Java Reference
In-Depth Information
Comments exist to make code easier for humans to read. These humans
include other programmers who may have to modify or use your code, as well
as yourself. A well-commented program is a sign of a good programmer.
1.2.2 main
A Java program consists of a collection of interacting classes, which contain
methods. The Java equivalent of the function or procedure is the static
method , which is described in Section 1.6. When any program is run, the spe-
cial static method main is invoked. Line 6 of Figure 1.1 shows that the static
method main is invoked, possibly with command-line arguments. The parame-
ter types of main and the void return type shown are required.
When the program
is run, the special
method main is
invoked.
1.2.3 terminal output
The program in Figure 1.1 consists of a single statement, shown on line 8.
println is the primary output mechanism in Java. Here, a constant string is
placed on the standard output stream System.out by applying a println
method. Input and output is discussed in more detail in Section 2.6. For now
we mention only that the same syntax is used to perform output for any entity,
whether that entity is an integer, floating point, string, or some other type.
println is used to
perform output.
primitive types
1.3
Java defines eight primitive types . It also allows the programmer great flexi-
bility to define new types of objects, called classes . However, primitive types
and user-defined types have important differences in Java. In this section, we
examine the primitive types and the basic operations that can be performed on
them.
1.3.1 the primitive types
Java has eight primitive types, shown in Figure 1.2. The most common is the
integer, which is specified by the keyword int . Unlike with many other lan-
guages, the range of integers is not machine-dependent. Rather, it is the same
in any Java implementation, regardless of the underlying computer architec-
ture. Java also allows entities of types byte , short , and long . These are known
as integral types . Floating-point numbers are represented by the types float
and double . double has more significant digits, so use of it is recommended
over use of float . The char type is used to represent single characters. A char
occupies 16 bits to represent the Unicode standard. The Unicode standard
contains over 30,000 distinct coded characters covering the principal written
Java's primitive
types are integer,
floating-point, Bool-
ean, and character.
The Unicode stan-
dard contains over
30,000 distinct
coded characters
covering the princi-
pal written
languages.
 
 
Search WWH ::




Custom Search