Glossary¶
- alias¶
Another way to access the same object through a copy of a reference value. For example, after
int[] b = a;, ifarefers to an array, thenaandbrefer to the same array, so changes made through either variable are visible through the other. The two are still separate variables: assigningnulltobdoes not change the value ofa.- argument¶
An expression supplied in a method or constructor call. In
Math.max(age, 18),ageand18are arguments. Their values, after any required conversions, initialize the corresponding parameters of the method or constructor. An argument is not the parameter itself; see pass by value.- call stack¶
The frames of the method calls that have started but not yet completed, with the most recent call's frame on top. When a method call completes, its frame is removed, and control transfers back to the caller. Each thread has its own call stack.
- command-line arguments¶
When you run a program by entering its associated command at a shell prompt, the text that you include after the program name is called the program's command-line arguments. This text is interpreted by the shell as an array of strings that it passes into the program when it runs it. The program can use the values of these command-line arguments to adjust its behavior. For several general examples of command-line arguments adjusting program behavior, refer to the Unix Commands chapter. In Java, this array containing the command-line arguments can be referred to using the
mainmethod'sString[] argsparameter. For more information on how to work with command-line arguments in Java, refer to the Command-Line Arguments chapter.- command-line interface¶
- CLI¶
The term command-line interface (CLI) refers to programming approaches for accepting user input that require the user to enter lines of text to supply values that impact the behavior of the program. On a Unix system, the shell prompt is an example of a CLI. In Java, a CLI for a program might involve displaying text to the user, reading in user input (e.g., using a Scanner object for standard input), then using that input to change what the program does.
- copy constructor¶
A copy constructor for a class called
Ais the constructorA(A other); if a class has a copy constructor, then calling it with a reference to some existing object of the class as its argument should result in the newly constructed object being a copy. The result is not always guaranteed to be a deep copy, so you should always check the constructor documentation and class documentation for more information before you make any assumptions.- default value¶
The value that Java initially gives an instance variable, a static variable, or an array component: zero for numeric types,
falseforboolean, andnullfor reference types. The defaultcharvalue is the character with code zero, not the character'0'. A local variable does not get a default value; it must be assigned a value before that value is used.- frame¶
- stack frame¶
The storage for one method call's parameters and local variables. Every method call gets a new frame, even when the same method is called again, and the frame is removed when the call completes.
- heap¶
The area of memory where objects, including arrays, are created. An object's instance variables and an array's components are part of the object, so they are on the heap even when their types are primitive.
- instance method¶
In Java, an instance method is a non-static method of a class. Such methods are called "instance" methods for two reasons: i) they are called on a specific object, or instance, of the class, through a reference value that refers to it; and ii) they have access to the instance variables associated with that particular instance. To call one instance method from another instance method in the same class, the
thiskeyword can be used as a reference that refers to the current object. If you do not use thethiskeyword to qualify a call to an instance method (e.g.,getFoo()instead ofthis.getFoo()), then Java will automatically qualify it for you, assuming the instance method exists.- instance variable¶
In Java, an instance variable is a non-static variable of a class that is not local to a method. Such variables are called "instance" variables for two reasons: i) they are accessed through a reference value that refers to a specific object, or instance, of the class; and ii) each instance of the class gets its own copy of the variable. Adjusting the value of an instance variable for one object does not impact its value in another object, unless additional code is written to explicitly make that happen. To access an instance variable inside an instance method in the same class, the
thiskeyword can be used as a reference that refers to the current object. If you do not use thethiskeyword to qualify the access (e.g.,xinstead ofthis.x), then Java will automatically qualify it for you, assuming the instance variable exists and is not shadowed by a local variable.- lifetime¶
How long a variable or object exists while a program runs. Lifetime is different from scope, which concerns where a name can be used in source code. Leaving a local variable's scope does not by itself destroy the object it referred to: another reachable reference may still refer to that object.
- local variable¶
In Java, a local variable is a variable declared inside a block, such as a method body or a loop body. Its scope runs from its declaration to the end of that block. Each method call gets its own local variables in that call's frame. Java's language specification distinguishes parameters from local variables, although both appear in a call's frame in our memory map diagrams and are typically counted together.
- manual page¶
A page from the Unix reference manual describing a command, utility, or system interface. Any command on a Unix system can be looked up in the manual by using the man command.
- memory map¶
A diagram of a program's state at one point in its execution: the frames on the call stack, the variables in each frame and their values, and the objects on the heap. An arrow shows that a reference value refers to an object; it does not mean that the variable contains the object. The box for a variable whose value is
nullholdsnulland has no arrow.- null¶
The literal
nulldenotes the null reference, which refers to no object. If the value ofnameisnull, thennamedoes not refer to an object. Calling an instance method or accessing an instance variable through a null reference throws aNullPointerException.- object¶
A class instance or an array, created while a program runs and stored on the heap. Variables of a reference type store reference values; they never contain objects. A variable, its reference value, and the object that value refers to are three distinct things.
- parameter¶
- formal parameter¶
A variable declared in a method's or constructor's parameter list. In
setAge(int age),ageis a parameter. Each call initializes its parameters with the values of the call's arguments, after any required conversions. A parameter is separate from every variable in the caller, even one with the same name. Java's language specification distinguishes parameters from local variables. Both appear in a call's frame in our memory map diagrams and are typically counted together.- pass by value¶
How Java passes arguments: each parameter receives a copy of its argument's value, after any required conversion. When that value is a reference value, the copy refers to the same object, so changes the method makes to that object are visible to the caller. Assigning a new value to the parameter, however, changes only the parameter, not any variable in the caller.
- path¶
A string of characters used to identify the unique location of a file or directory within a file system's hierarchical directory tree (either an absolute path or a relative path).
- primitive type¶
One of the eight types that Java predefines and names with keywords:
boolean,byte,short,int,long,char,float, anddouble. A variable of a primitive type stores a primitive value, not a reference value. Every other type, includingStringand every array type, is a reference type.- primitive variable¶
In Java, a primitive variable is a variable that stores a primitive value directly (rather than a reference to an object). Java defines eight primitive types:
byte,short,int,long,float,double,boolean, andchar.- reference equality¶
Comparing reference values with
==or!=. Two non-null references are equal under==when they refer to the same object, and twonullvalues are also equal. To compare the text of two strings, useequalsinstead, because two differentStringobjects can contain the same text.- reference type¶
A type whose variables store reference values. Class types such as
String, interface types, and array types such asint[]are reference types. The components of anint[]array are primitive variables, butint[]itself is a reference type.- reference value¶
- reference¶
A value that refers to an object, or the null reference. Assignment, argument passing, and a method returning with a reference value each copy the reference value, never the object. In a memory map, an arrow shows which object a reference value refers to. The book's visualizer also shows a number in the variable's box and after the
@in the object's label, as inStopwatch@622. The number identifies the object, so you can see which references refer to the same object. It is not a memory address.- reference variable¶
In Java, a reference variable is a variable of a reference type. Its value is either a reference value that refers to an object or
null.- scope¶
The region of source code in which a declared name can be used. For example, the scope of a local variable runs from its declaration to the end of the block that declares it. Scope is about names, not lifetime. A parameter and an instance variable can share a name; in
this.age = age,this.agenames the instance variable andagenames the parameter.- shell¶
A program that serves as the primary end-user interface to the services provided by an operating system. On a Unix system, the term shell often refers to a CLI program like Bash or Zsh that manages user–system interactions using a prompt.
- shell prompt¶
A command-line shell manages user–system interactions by prompting users for input, interpreting the input, asking the operating system to perform interpreted actions (e.g., running another program), and displaying related output. While the exact text that is used when a prompt is displayed is often customized, it is common for that text to end with either
$or%. On a Unix system, this is where users enter commands.- standard error¶
A file or stream to which a program writes or prints its error-related output data. Unless redirected, data written to standard error is sent to the same place as standard output. In Java, System.err refers to a PrintStream for standard error. On most Unix systems, a file or symbolic link that represents standard error exists in the file system, typically at
/dev/stderr.- standard input¶
A file or stream from which a program reads its input data. Unless redirected, data read from standard input is taken from a user's terminal keyboard. In Java, System.in refers to an InputStream for standard input. On most Unix systems, a file or symbolic link that represents standard input exists in the file system, typically at
/dev/stdin.- standard output¶
A file or stream to which a program writes or prints its output data. Unless redirected, data written to standard output is sent to a user's terminal display. In Java, System.out refers to a PrintStream for standard output. On most Unix systems, a file or symbolic link that represents standard output exists in the file system, typically at
/dev/stdout.- static method¶
In Java, a static method is a method associated with a class rather than with individual instances of that class. Static methods are declared with the
staticmodifier and can be invoked directly on the class name without creating an object of that class.- static variable¶
- class variable¶
In Java, a static variable (or class variable) is a variable declared with the
staticmodifier that is associated with a class rather than with individual instances. All instances of the class share a single copy of a static variable.- symbolic link¶
- symlink¶
A symbolic link or symlink refers to a kind of file that links to (i.e., serves as a shortcut to) another file or directory called the link target. On most Unix systems, the ln -s command can be used to create a symbolic link; refer to the manual page for ln for information. For an example that shows how to use ln to create a symbolic link, refer to the "Hosting the API Documentation Website" section in the Javadoc and API Documentation chapter.
- terminal emulator¶
- terminal¶
A graphical program (such as Terminal and iTerm2 on macOS, or MobaXterm on Windows) that provides a windowed, text-based interface for interacting with a shell.
- Unix¶
A family of computer operating systems that derive from work performed in the 1970s at the Bell Labs research center by Ken Thompson, Dennis Ritchie, and others. For more information, refer to the Unix Environment chapter.
- variable¶
A storage location with a type that holds one value at a time. Local variables, parameters, instance variables, static variables, and array components are all variables. A variable of a reference type holds a reference value, never an object.