Glossary of Java and Related Terms
Object-Oriented Programming with Java:
|
This glossary is taken from my book Object-Oriented Programming with Java: An Introduction, published by Prentice Hall. I would welcome corrections or requests for additional terms.
David Ashby has kindly provided both a PDF version and a a Word version of this glossary.
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z |
c:\Java\bin\javac.exeSee relative filename.
abstract
reserved word in its header.
Abstract classes are distinguished by the fact
that you may not directly construct objects from them using
the new
operator.
An abstract class may have zero or more abstract methods.
abstract
reserved word in its header.
An abstract method has no method body.
Methods defined in an interface are always abstract.
The body of an abstract method must be defined in a sub class
of an abstract class, or the body of
a class implementing an interface.
java.awt
packages.
Included are classes for windows, frames, buttons, menus, text areas, and so
on.
Related to the AWT classes are those for the Swing packages.
private
attribute of a class.
By convention, we name accessors with a get
prefix followed by the name
of the attribute being accessed.
For instance, the accessor for an attribute named speed
would be
getSpeed
.
By making an attribute private, we prevent objects of other classes from
altering its value other than through a mutator method.
Accessors are used both to grant safe access to the value of a private
attribute and to protect attributes from inspection by objects of other classes.
The latter goal is achieved by choosing an appropriate visibility for the
accessor.
// Create an anonymous array of integers. YearlyRainfall y2k = new YearlyRainfall( new int[]{ 10,10,8,8,6,4,4,0,4,4,7,10,});An anonymous array may also be returned as a method result.
quitButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.exit(0); } });
private Point[] vertices = { new Point(0,0), new Point(0,1), new Point(1,1), new Point(1,0), };See anonymous class, as these often result in the creation of anonymous objects.
Applet
or JApplet
classes.
They are most closely associated with the ability to provide
active content within Web pages.
They have several features which distinguish them from
ordinary Java graphical applications,
such as their lack of a
user-defined main method, and the security restrictions that limit
their abilities to perform some normal tasks.
+
, -
, *
, /
and %
take arithmetic expressions as their operands and produce
arithmetic values as their results.
+
, -
, *
, /
and %
, that produce a numerical result, as part of
an arithmetic expression.
int[] pair = { 4, 2, };is equivalent to the following four statements.
int[] pair; pair = new int[2]; pair[0] = 4; pair[1] = 2;
=
) used to store the value of an expression into
a variable, for instance
variable = expression;The right-hand-side is completely evaluated before the assignment is made. An assignment may, itself, be used as part of an expression. The following assignment statement stores zero into both variables.
x = y = 0;
int[] numbers;the base type of
numbers
is int
.
Where the base type is a class type, it indicates the lowest
super type of objects that may be stored in the array.
For instance, in
Ship[] berths;only instances of the
Ship
class may be
stored in berths
.
If the base type of an array
is Object
, instances of any class may be stored in it.
0
and 1
are used.
Digit positions represent successive powers of 2.
See bit.
+
,
-
, *
, /
and %
, and the boolean operators
&&
, ||
and ^
, amongst others.
0
and
1
.
Bits are the fundamental building block of both programs and data.
Computers regularly move data around in multiples of eight-bit units
(bytes for the sake of efficiency).
&
, |
and ^
, that are
used to examine an manipulate individual bits
within the bytes of a data item.
The shift operators, <<
, >>
and >>>
,
are also bit manipulation operators.
{
and }
).
For instance, a class body
is a block, as is a method body.
A block encloses a nested scope level.
boolean
type has only two values: true
and false
.
boolean
, i.e. gives a value of
either true
or false
.
Operators such as &&
and ||
take boolean operands and
produce a boolean result.
The relational operators take operands different types and produce boolean
results.
java.lang
, java.io
and java.io
packages.
IndexOutOfBoundsException
exception being thrown.
.class
files.
numbers
Arrays.sort(numbers);The
sort
method will change the order of the values stored in
the object referred to by numbers
.
However, it is impossible for the
sort
method to change which array numbers
refers to - a sorted
copy, for instance.
Some languages provide an argument passing semantics known as
call-by-reference, in which an actual argument's value
may be changed. Java does not provide this, however.
\r
character.
Also used as
a synonym for the `Return' or `Enter' key used to terminate a line of text.
The name derives from the carriage on a mechanical typewriter.
'A'
)
or lower-case (e.g., 'a'
).
ClassCastException
exception will be thrown for
illegal ones.
final
and static
.
extends
a super class
or implements
any interfaces.
private
access modifier.
public static void main(String[] args)The arguments are stored as individual strings.
~
, is used to invert the value of each
bit
in a binary pattern. For instance, the complement of 1010010
is 0101101
.
?:
) is used in the form
bexpr ? expr1 : expr2where
bexpr
is a boolean expression.
The the boolean expression has the value true
then the result of the
operation is the value of expr1
, otherwise it is the value of
expr2
.
public class Ship { public Ship(String name){ ... } ... }A class with no explicit constructor has an implicit no-arg constructor, which takes no arguments and has an empty body.
public class Point { // Use p's attributes to initialize this object. public Point(Point p){ ... } ... }The argument is used to define the initial values of the new object's attributes.
synchronized
methods or
statements.
--
) that adds one to its operand.
It has two forms: pre-decrement (--x
) and post-decrement
(x--
).
In its pre-decrement form, the result of the expression is the
value of its argument after the decrement.
In its post-decrement form, the result is the value of its argument
before the decrement is performed.
After the following,
int a = 5, b = 5; int y,z; y = --a; z = b--
y
has the value 4
and z
has the value 5
.
Both a
and b
have the value 4
.
double
, float
, int
, long
and short
.
The remaining three are used
to representing single-bit values
(boolean
), single byte values (byte
) and two-byte
characters from the ISO Unicode character set (char
).
0
to 9
are used.
Digit positions represent successive powers of 10.
int numStudents = 23; Ship argo = new Ship(); Student[] students = new Student[numStudents];Instance variables that are not explicitly initialized when they are declared have a default initial value that is appropriate to their type. Uninitialized local variables have an undefined initial value.
boolean
variables have the value false
, char
variables
have the value \u0000
and object references have the value
null
.
The initial values of local variables are undefined, unless explicitly
initialized.
false
.
The statements in the loop body will always be executed at least once.
// Downcast from Object to String String s = (String) o;See upcast.
private
and
channeling access to them through accessor and mutator methods.
public interface States { public static final int Stop = 0, Go = 1; }However, the compiler type checking usually available with enumerated types is not available with this form.
Throwable
class.
See checked exception and
unchecked exception.
^
) is both a
boolean operator and a
bit manipulation operator.
The boolean version gives the value true
if only one of its
operands is true
, otherwise it gives the value false
.
Similarly, the bit manipulation version produces a 1
bit wherever the
corresponding bits in its operands are different.
DataInputStream
and DataOutputStream
.
final
reserved word in its header.
A final class may not be extended by another class.
finalize
method is called.
This gives it the opportunity to free any resources it might be holding
on to.
final
reserved word in its header.
A final method may not be overridden by a method defined in
a sub class.
final
reserved word in its declaration.
A final may not assigned to once it has been initialized.
Initialization often takes place as part of its declaration.
However, the initialization of an uninitialized final field (known as
a blank final variable)
may be deferred to the class's constructor,
or an initializer.
true
.
The third expression is evaluated after each completion of the loop's
body.
The loop terminates when the termination test gives the value false
.
The statements in the loop body might be executed zero or more times.
package oddments; class Outer { public class Inner { ... } ... }The fully qualified name of
Inner
is
oddments.Outer.Inner
+
, are fully evaluating.
In contrast, some boolean operators,
such as &&
,
are short-circuit operators.
HashMap
.
hashValue
method,
inherited from the Object
class, to define
their own hash function.
0
to 9
and the letters
A
to F
are used. A
represents 10 (base 10), B
represents 11 (base 10), and so on.
Digit positions represent successive powers of 16.
if(boolean-expression){ // Statements performed if expression is true. ... } else{ // Statements performed if expression is false. ... }It is controlled by a boolean expression. See if statement.
if(boolean-expression){ // Statements performed if expression is true. ... }It is controlled by a boolean expression. See if-else statement.
String
class are immutable, for instance -
their length and contents are fixed once created.
++
) that adds one to its operand.
It has two forms: pre-increment (++x
) and post-increment
(x++
).
In its pre-increment form, the result of the expression is the
value of its argument after the increment.
In its post-increment form, the result is the value of its argument
before the increment is performed.
After the following,
int a = 5, b = 5; int y,z; y = ++a; z = b++
y
has the value 6
and z
has the value 5
.
Both a
and b
have the value 6
.
Y
calling method X
,
when an existing call from X
to Y
is still in progress.
false
.
Sometimes this is a deliberate act on the part of the programmer, using
a construct such as
while(true) ...or
for( ; ; ) ...but it can sometimes be the result of a logical error in the programming of a normal loop condition or the statements in the body of the loop.
private
, is one of the ways that we seek to promote information hiding.
Object
class is the ultimate ancestor of all classes - at the top of the hierarchy.
Two classes that have the same immediate
super class can be thought of as sibling
sub classes.
Multiple inheritance of interfaces gives
the hierarchy a more complex structure than that resulting from simple
class inheritance.
byte
, short
, int
and long
are used to hold integer values within narrower or wider
ranges.
InterruptedException
object being received
by the interrupted thread.
Waiting for an interrupt is an alternative to polling.
Iterator
and ListIterator
interfaces.
<<
) is a
bit manipulation operator.
It moves the bits in its left operand zero or more places
to the left, according to the value of its right operand.
Zero bits are added to the right of the result.
&&
, ||
, &
,
|
and ^
that take two boolean operands and produce a boolean result.
Used as part of
a boolean expression, often in
the condition of a control structure.
12
could mean many different things - the
number of hours you have worked today, the number of dollars you are owed by a
friend, and so on.
As far as possible, such values should be associated with an identifier
that clearly expresses their meaning.
final int maxSpeed = 50;If stored in a final variable, it is unlikely that any execution overhead will be incurred by doing so.
public static void main(String[] args)
void
.
private
attribute of a class.
By convention, we name mutators with a set
prefix followed by the name
of the attribute being modified.
For instance, the mutator for an attribute named speed
would be
setSpeed
.
By making an attribute private, we prevent objects of other classes from
altering its value other than through its mutator.
The mutator is able to check the value being used to modify the attribute and
reject the modification if necessary.
In addition, modification of one attribute might require others to be modified
in order to keep the object in a consistent state.
A mutator method can undertake this role.
Mutators are used both to grant safe access to the value of a private
attribute and to protect attributes from modification by objects of other classes.
The latter goal is achieved by choosing an appropriate visibility for the
mutator.
\n
character.
new
operatorpublic
access.
Its role is purely to invoke the no-arg constructor of the immediate
super class.
\u0000
character.
Care should be taken not to confuse this with the
null
reference.
null
referenceobject
, usually via the new
operator.
When an object is created, an appropriate constructor
from its class is invoked.
argo
Ship argo;is capable of holding an object reference, but is not, itself, an object. It can refer to only a single object at a time, but it is able to hold different object references from time to time.
0
to 7
are used.
Digit positions represent successive powers of 8.
\ddd
, where each d
is an octal digit.
This may be used for characters with a Unicode value in the range 0-255.
-
, ==
or ?:
taking one, two or
three operands and yielding a result.
Operators are used in both arithmetic expressions
and
boolean expressions.
read
method of InputStream
returns -1
to indicate
that the end of a stream has been reached, for instance, instead
of the normal positive byte-range value.
public
, protected
or private
access modifier
{access!modifier}
have package visibility.
Public classes and interfaces may be imported into other packages
via an import statement.
package java.lang;
Iterator
encapsulate a pattern of access
to the items in a collection, while freeing the client from the need
to know details of the way in which the collection is implemented.
PipedInputStream
and PipedOutputStream
.
wait
and
notify
mechanism associated with threads.
class Rectangle extends Polygon implements Comparablean object whose dynamic type is Rectangle can behave as all of the following types: Rectangle, Polygon, Comparable, Object.
x+y*z
, the multiplication is performed
before the addition because *
has a higher precedence than -
.
boolean
,
byte
,
char
,
double
, float
, int
, long
and short
.
protected
access modifier.
Such a member is accessible to all classes defined within the
enclosing package, and any sub classes extending the enclosing
class.
public
access modifier.
All such members are visible to every class within a program.
5/3
, 5
is the dividend and 3
is the divisor. This gives a quotient of 1
and a remainder of
2
.
Reader
abstract,
defined in the java.io
package.
Reader classes translate input from a host-dependent
character set encoding into Unicode.
See Writer class.
double
and float
are used to represent real numbers.
public static void countDown(int n){ if(n >= 0){ System.out.println(n); countDown(n-1); } // else - base case. End of recursion. }See direct recursion, indirect recursion and mutual recursion for the different forms this can take.
Class
class,
and other classes in the java.lang.reflect
package.
Reflection makes it possible, among other things, to create
dynamic programs.
<
, >
, <=
,
>=
, ==
and !=
, that produce a boolean result, as part of
a boolean expression.
../bin/javac.exeA relative filename could refer to different files at different times, depending upon the context in which it is being used. See absolute filename.
class
,
int
, public
, etc.
Such words may not be used as ordinary identifiers.
void
return type may only have return statements
of the following form
return;A method with any other return type must have at least one return statement of the form
return expression;where the type of
expression
must match the return type of the method.
void
in
public static void main(String[] args)or
Point[]
in
public Point[] getPoints()
>>
) is a
bit manipulation operator.
It moves the bits in its left operand zero or more places
to the right, according to the value of its right operand.
The most significant bit from before the shift is
replicated in the leftmost position - this is called
sign extension. An alternative right shift operator (>>>
)
replaces the lost bits with zeros at the left.
ivar
is an int
variable,
the following statement is syntactically correct
ivar = true;However, it is semantically incorrect, because it is illegal to assign a
boolean
value to an integer variable.
&&
) and logical-or (||
) operators are the most
common example, although the
conditional operator (?:
) also
only ever evaluates two of its three operands.
See fully evaluating operator.
1
bit indicates a negative number, and a
0
bit indicates a positive number.
byte
variable contains the bit pattern,
10000000
.
If this is stored in a short
variable, the resulting bit pattern
will be 1111111110000000
.
If the original value is 01000000
, the resulting bit pattern
will be 0000000001000000
.
// This line will be ignored by the compiler.
;
) is used to indicate the end of a statement.
static
reserved word.
A static initializer is defined outside the methods of its enclosing class,
and may only access the static fields and methods
of its enclosing class.
static
reserved word in its header.
Static methods differ from all other methods
in that they are not associated with any particular instance of the class to
which they belong.
They are usually accessed directly via the name of the
class in which they are defined.
static
reserved word in its header.
Unlike inner classes, objects of static nested classes
have no enclosing object.
They are also known as nested top-level classes.
static
variable defined inside a class body.
Such a variable
belongs to the class as a whole, and is, therefore,
shared by all objects of the class.
A class variable might be used to define the default value of an
instance variable,
for example, and would probably also be defined as
final
, too.
They are also used to contain dynamic information that is shared between
all instances of a class. For instance the next account number to be allocated
in a bank account class.
Care must be taken to ensure that access to shared information, such as this,
is synchronized
where multiple threads could be involved.
Class variables are also used to give names to application-wide values or
objects since they may be accessed directly via their containing class name
rather than an instance of the class.
String
class.
Strings consist of zero or more Unicode characters, and they are
immutable, once created.
A literal string is written between a pair of string delimiters ("
),
as in
"hello, world"
extends
its super class.
A sub class inherits all of the members of its
super class.
All Java classes are sub classes of the Object
class, which
is at the root of the inheritance hierarchy.
See sub type
Object
class as a super class.
See super type.
javax.swing
packages.
They provide a further set of components that
extend the capabilities of the Abstract Windowing Toolkit (AWT).
Of particular significance is the greater control they provide over
an application's look-and-feel.
switch(choice){ case 'q': quit(); break; case 'h': help(); break; ... default: System.out.println("Unknown command: "+choice); break; }
// Initialise with default values. public Heater() { // Use the other constructor. this(15, 20); } // Initialise with the given values. public Heater(int min,int max) { ... }
public Heater(int min,int max) { this.min = min; this.max = max; ... }
talker.talkToMe(this);
Thread
class in the
java.lang
package.
public int find(String s) throws NotFoundException
throw new IndexOutOfBoundsException(i+" is too large.");
true
and false
,
on
and off
, or 1
and 0
.
try{ statement; ... } catch(Exception e){ statement; ... } finally{ statement; ... }Either of the catch clause and finally clause may be omitted, but not both.
1
bit indicates a negative number, and a
0
bit indicates a positive number.
A positive number can be converted to its negative value by
complementing
the bit pattern and adding 1
.
The same operation is used to convert a negative value to its
positive equivalent.
-
, +
, !
, !
,
++
and --
.
www.javasoft.com
)
a name (e.g. index.html
) and a scheme (e.g. http
).
// Upcast from VariableController to HeaterController VariableController v; ... HeaterController c = v;See downcast. Java's rules of polymorphism mean that an explicit upcast is not usually required.
null
.
A variable of a class type acts as a holder for a reference to an object
that is compatible with the variable's class type.
Java's rules of polymorphism allow a variable of a class type to hold a
reference to any object of its declared type or any of its sub types.
A variable with a declared type of Object
, therefore, may hold a
reference to an object of any class, therefore.
80
is the well-known port number for
servers using the
HyperText Transfer Protocol (HTTP).
false
.
The statements in the loop body might be executed zero or more times.
java.lang
package.
They consist of a class for each primitive type:
Boolean
, Byte
, Character
, Double
,
Float
, Integer
, Long
and Short
.
These classes provide methods to parse strings containing primitive values,
and turn primitive values into strings.
The Double
and Float
classes also provide methods to detect
special bit patterns for floating point numbers, representing values such
as NaN
, +infinity and -infinity.
Writer
abstract,
defined in the java.io
package.
Writer classes translate output from Unicode
to a host-dependent character set encoding .
See Reader class.