Java Reference
In-Depth Information
instance 296
instance method
property 296
public class 299
reference type 304
reference variable
305
instance variable
305
instantiation 296
no-arg constructor
304
303
setter (or mutator)
320
null
value
305
state 296
static method 312
static variable 312
Unified Modeling Language
(UML)
object 296
object-oriented programming (OOP)
package-private (or package-
access) 317
private constructor
297
319
C
HAPTER
S
UMMARY
1.
A
class
is a template for
objects
. It defines the
properties
of objects and provides
constructors
for creating objects and methods for manipulating them.
2.
A class is also a data type. You can use it to declare object
reference variables
. An
object reference variable that appears to hold an object actually contains a reference
to that object. Strictly speaking, an object reference variable and an object are differ-
ent, but most of the time the distinction can be ignored.
3.
An object is an
instance
of a class. You use the
new
operator to create an object, and
the
dot operator
(
.
) to access members of that object through its reference variable.
4.
An
instance variable
or
method
belongs to an instance of a class. Its use is associated
with individual instances. A
static variable
is a variable shared by all instances of the
same class. A
static method
is a method that can be invoked without using instances.
5.
Every instance of a class can access the class's static variables and methods. For clar-
ity, however, it is better to invoke static variables and methods using
ClassName.variable
and
ClassName.method
.
6.
Modifiers specify how the class, method, and data are accessed. A
public
class,
method, or data is accessible to all clients. A
private
method or data is accessible
only inside the class.
7.
You can provide a
get
method or a
set
method to enable clients to see or modify the
data. Colloquially, a
get
method is referred to as a
getter
(or
accessor
), and a
set
method as a
setter
(or
mutator
).
8.
A
get
method has the signature
public returnType getPropertyName()
. If
the
returnType
is
boolean
, the
get
method should be defined as
public
boolean isPropertyName()
. A
set
method has the signature
public void
setPropertyName(dataType propertyValue)
.
9.
All parameters are passed to methods using pass-by-value. For a parameter of a prim-
itive type, the actual value is passed; for a parameter of a
reference type
, the reference
for the object is passed.
10.
A Java array is an object that can contain primitive type values or object type values.
When an array of objects is created, its elements are assigned the default value of
null
.