Java Reference
In-Depth Information
Coding Output
Displaying output in console applications involves sending a message to
the standard output device, which in most cases is the monitor of the computer
system. In the Welcome to My Day application, the output is displayed as
white characters on the black background of the command prompt window.
Figure 2-23 shows the code you use to display output.
14
System .out.println () ;
15
System .out.println ( "Welcome to my day!" ) ;
16
System .out.println ( "Daily planner for Linda Nunez" ) ;
17
System .out.println ( "October 4, 2007" ) ;
18
System .out.println () ;
19
FIGURE 2-23
In line 14, the word, System, refers to a specific Java class definition supplied
with the SDK. A class definition defines the instance and class variables and
methods available for use in the class, as well as other information, such as the
immediate superclass. The System class contains several useful class variables
and methods, such as those involving standard input, standard output, and other
utility methods. The System class extends , or inherits, methods from its super-
class, which in this case is Java's Object class. You will learn more about the
System and Object classes in later chapters.
Class Definitions
A class definition defines the instance and class variables and
methods available for use in the class, as well as other information,
such as the immediate superclass. You can use the Java API to
view the hierarchy of individual classes and to look up specific
methods used by each class.
The word, out , refers to the object representing the default display. Perhaps
the most often used object from the System class, out represents the device used
to display a standard output of text characters. A period (.) separates or delimits
the class, System, and the object, out.
Following another period delimiter, the word, println, identifies the println()
method from the System class. The println() method returns its value to the
System.out device. The println() method is called from the Java Object package
in this case — the programmer is not writing all of the code to make it work. Call-
ing methods such as println() differs from writing methods such as main(). When
coding the main() method, which begins with a method header, the programmer
must include the code statements for operations that the main() method must
perform. Methods such as println() already have been written, so programmers
can use the methods without having to write all of the code that each method
must perform . Programmers simply call such methods by the method's name
and send data along with it, in the form of arguments enclosed in parentheses.
You do not need to specify the argument's data type when calling a method.
Search WWH ::




Custom Search