Java Reference
In-Depth Information
a6
equals(String)
charAt(
int
) ...
String
"xyz"
s1 a6
Variable
s1
contains the name of a folder of class
String
, and the folder con-
tains not only the string of characters but also many methods that are useful in
manipulating those characters. These methods are discussed in detail in Sec. 5.2.
Here is an important point: testing two
String
variables
s1
and
s2
using
s1 == s2
does not test whether they represent the same string of characters. Instead, it tests
whether
s1
and
s2
contain the same folder name, just like when two variables of
class
JFrame
are compared. To test whether the strings of characters in the fold-
ers named by
s1
and
s2
are the same, use the test
s1.equals(s2)
.
Equality is discussed in detail in Sec. 3.2.4.
1.3.5
Key concepts
•
Class
. A
class
is a file drawer of folders. Each folder in a drawer has the same
components.
•
Instances and objects.
The terms
folder
,
instance
, and
object
are used inter-
changeably.
•
Components: fields and methods
. The possible components of an
object
are
fields
, which are variables and, thus, contain values, and
methods
, which are
called to perform tasks.
•
Procedures, functions, constructors
. There are three kinds of method. A call
to a
function
produces a value. A call to a
procedure
performs some task but does
not produce a value. A call to a
constructor
initializes some or all fields of a
newly created object. A method call can have
arguments
, which are expressions.
The values of the arguments are used in some fashion when the method is called;
the specification of the method explains how they are used.
•
New-expression
. Evaluation of a new-expression
new
class-name
(
arguments
)
creates a new object of the class, initializes its fields by calling constructor
class-
name
, and yields as its value the name of the newly created object.
•
Class as a type
. A class name may be used as a type, and a variable declared
with that type can contain the name of a folder of that type. For example, vari-
able
w
of type
JFrame
can contain the name of a folder that goes in
JFrame
's file
drawer.
•
Null
. The value
null
represents the absence of the name of an instance. If a
Search WWH ::
Custom Search