Java Reference
In-Depth Information
Note that the single quote can also be printed without using the escape sequence.
Therefore, the preceding statement is equivalent to the following output statement:
System.out.println("The tab character is represented as '\\t'");
The output of the statement:
2
System.out.println("The string \"Sunny\" contains five characters");
is:
The string "Sunny" contains five characters
To access a Java program that shows the effect of the statements in Example 2-23,
download Additional Student Files from www.cengagebrain.com. (The program is named
Example2_23.java
.)
Statement
Only a small number of operations, such as arithmetic and assignment operations, are
explicitly defined in Java. Many of the methods and identifiers needed to run a Java
program are provided as a collection of libraries, called packages. A package is a
collection of related classes. Moreover, every package has a name.
In Java, class is a broadly used term. The term class is used to create Java programs, either
application or applet; it is used to group a set of related operations; and it is used to allow
users to create their own data types. For example, there are various mathematical
operations, such as determining the absolute value of a number, determining one number
raised to the power of another number, and determining the logarithm of a number. Each
of these operations is implemented using the Java mechanism of methods. Think of a
method as a set of instructions designed to accomplish a specific task. For example, the
name of the method implementing the operation of one number raised to the power of
another number is
pow
. This and other mathematical methods are contained in the
class
Math
. The name of the package containing the
class
Math
is
java.lang
.
The package
java.util
contains the
class
Scanner
. This class contains the methods
nextInt
,
nextDouble
,
next
, and
nextLine
for inputting data into a program. In the
next section, you will learn how class(es) are used to create a Java application program.
To see the complete definitions of the (predefined) Java classes, such as
String
,
Math
,
and
Scanner
, as well as the class hierarchy, you can visit the Web site http://
java.sun.com/javase/7/docs/api/.
Search WWH ::
Custom Search