Java Reference
In-Depth Information
as
int
, are not allowed. Although it is legal to do so, you should not reuse
identifier names that are already visibly used (for example, do not use
main
as
the name of an entity).
Java is
case-sensitive
, meaning that
Age
and
age
are different identifiers.
This text uses the following convention for naming variables: All variables
start with a lowercase letter and new words start with an uppercase letter. An
example is the identifier
minimumWage
.
Here are some examples of declarations:
Java is case-
sensitive.
int num3; // Default initialization
double minimumWage = 4.50; // Standard initialization
int x = 0, num1 = 0; // Two entities are declared
int num2 = num1;
A variable should be declared near its first use. As will be shown, the
placement of a declaration determines its scope and meaning.
1.3.4
terminal input and output
Basic formatted terminal I/O is accomplished by
nextLine
and
println
. The
standard input stream is
System.in
, and the standard output stream is
System.out
.
The basic mechanism for formatted I/O uses the
String
type, which is
discussed in Section 2.3. For output,
+
combines two
String
s. If the second
argument is not a
String
, a temporary
String
is created for it if it is a prim-
itive type. These conversions to
String
can also be defined for objects
(Section 3.4.3). For input, we associate a
Scanner
object with
System.in
.
Then a
String
or a primitive type can be read. A more detailed discussion
of I/O, including a treatment of formatted files, is in Section 2.6.
basic operators
1.4
This section describes some of the operators available in Java. These opera-
tors are used to form
expressions
. A constant or entity by itself is an expres-
sion, as are combinations of constants and variables with operators. An
expression followed by a semicolon is a simple statement. In Section 1.5, we
examine other types of statements, which introduce additional operators.
Search WWH ::
Custom Search