Java Reference
In-Depth Information
• Java provides the
if
,
switch
,
while
,
for
, and other reserved words as
found in the C and C++ languages. Java also provides the
try
,
catch
,
class
,
private
,andotherreservedwordsthatarefoundinC++butnotin
C.
• AswithCandC++,Javasupportscharacter,integer,andotherprimitivetypes.
Furthermore, Javasharesthesame reserved wordsfornaming these types; for
example,
char
(for character) and
int
(for integer).
• Java supports many of the same operators as C/C++: the arithmetic operators
(
+
,
-
,
*
,
/
, and
%
) and conditional operator (
?:
) are examples.
• Javaalsosupportstheuseofbracecharacters
{
and
}
todelimitblocksofstate-
ments.
AlthoughJavaissimilartoCandC++,italsodiffersinmanyrespects.Thefollowing
list itemizes some of these differences:
• Java supports an additional comment style known as Javadoc.
• Javaprovides
transient
,
synchronized
,
strictfp
,andotherreserved
words not found in C or C++.
• Java's character type has a larger size than the version of this type found in C
and C++, Java's integer types do not include unsigned variants of these types
(JavahasnoequivalentoftheC/C++unsignedlongintegertype,forexample),
and Java's primitive types have guaranteed sizes, whereas no guarantees are
made for the equivalent C/C++ types.
• Java doesn't support all of the C/C++ operators. For example, there is no
sizeof
operator.Also,JavaprovidessomeoperatorsnotfoundinC/C++.For
example,
>>>
(unsigned right shift) and
instanceof
are exclusive to Java.
• Java provides labeled break and continue statements. These variants of the
C/C++ break and continue statements provide a safer alternative to C/C++'s
goto statement, which Java doesn't support.
Note
Comments,reservedwords,types,operators,andstatementsareexamplesof
fundamental language features, which are discussed later in this chapter.
AJavaprogramstartsoutassourcecodethatconformstoJava
syntax
,rulesforcom-
bining symbols into meaningful entities. The Java compiler translates the source code
stored in files that have the “
.java
” file extension into equivalent executable code,
known as
bytecode
, which it stores in files that have the “
.class
” file extension.