Java Reference
In-Depth Information
Examples of valid identifiers include
i
,
counter
,
loop10
,
border$color
and
_char
. Examples of invalid identifiers include
50y
(starts with a digit) and
first#name
(
#
is not a valid identifier symbol).
Note
Javaisa
case-sensitive language
,whichmeansthatidentifiersdifferingonly
incaseareconsideredseparateidentifiers.Forexample,
salary
and
Salary
aresep-
arate identifiers.
Almost any valid identifier can be chosen to name a class, method, or other source
code entity. However, some identifiers are reserved for special purposes; they are
known as
reserved words
. Java reserves the following identifiers:
abstract
,
as-
sert
,
boolean
,
break
,
byte
,
case
,
catch
,
char
,
class
,
const
,
continue
,
default
,
do
,
double
,
enum
,
else
,
extends
,
false
,
final
,
finally
,
float
,
for
,
goto
,
if
,
implements
,
import
,
instanceof
,
int
,
inter-
face
,
long
,
native
,
new
,
null
,
package
,
private
,
protected
,
public
,
return
,
short
,
static
,
strictfp
,
super
,
switch
,
synchronized
,
this
,
throw
,
throws
,
transient
,
true
,
try
,
void
,
volatile
, and
while
. The
compiler outputs an error message if you attempt to use any of these reserved words
outside of their usage contexts.
Note
MostofJava'sreservedwordsarealsoknownas
keywords
.Thethreeexcep-
tions are
false
,
null
, and
true
, which are examples of
literals
(values specified
verbatim).
Types
Programsprocessdifferenttypesofvaluessuchasintegers,floating-pointvalues,char-
acters,andstrings.A
type
identifiesasetofvalues(andtheirrepresentationinmemory)
andasetofoperationsthattransformthesevaluesintoothervaluesofthatset.Forex-
ample, the integer type identifies numeric values with no fractional parts and integer-
oriented math operations, such as adding two integers to yield another integer.
Note
Javaisastronglytypedlanguage,whichmeansthateveryexpression,variable,
andsoonhasatypeknowntothecompiler.Thiscapabilityhelpsthecompilerdetect
type-relatederrorsatcompiletimeratherthanhavingtheseerrorsmanifestthemselves
at runtime. Expressions and variables are discussed later in this chapter.
Java classifies types as primitive types, user-defined types, and array types.