Java Reference
In-Depth Information
• The object
out
represents the standard output stream — the command line on your display screen
— and is a data member of the class
System
. The member,
out
, is a special kind of member of the
System
class. Like the method
main()
in our
OurFirstProgram
class, it is static. This means that
out
exists even though there are no objects of type
System
(more on this in forthcoming chapters).
Using the class name,
System
, separated from the member name
out
by a period —
System.out
— references the
out
member of the class.
• The bit at the rightmost end of the statement,
println("Krakatoa, EAST of Java??")
, calls the
println()
method that belongs to the object
out
. It outputs the text string that appears between
the parentheses to the command line. This demonstrates one way in which you can call a class
method — by using the object name followed by the method name, with a period separating them.
The stuff between the parentheses following the name of a method is information that is passed to
the method when it is executed. As I said, for
println()
it is the text you want to output to the
command line.
NOTE
For completeness, the keywords
public
,
static
, and
void
that appear in the method
definition are explained briefly in the annotations to the program code in
Figure 1-9
, but you
need not be concerned if these seem a bit obscure at this point. I come back to them in much
more detail in Chapter 5.
You can compile this program with the command
javac -source 1.7 OurFirstProgram.java
or with the
-classpath
option specified:
javac -classpath . OurFirstProgram.java
or you can just write the following:
javac OurFirstProgram.java
If it didn't compile, there's something wrong somewhere. Here's a checklist of possible sources of the
problem:
• The path to the
jdk1.7.0_n\bin
directory is not defined in the string for your
PATH
environment
variable. This results in your operating system not being able to find the
javac
compiler that is in
that directory.
• You made an error typing in the program code. Remember Java is case-sensitive, so
OurfirstProgram
is not the same as
OurFirstProgram
, and of course, there must be no spaces
in the class name. If the compiler discovers an error, it usually identifies the line number in the
code where the error is found. In general, watch out for confusing zero,
0
, with a small letter
o
, or
the digit one,
1
, with the small letter
l
. All characters such as periods, commas, and semicolons in
the code are essential and must be in the right place. Parentheses,
()
, curly braces,
{}
, and square
brackets,
[]
, always come in matching pairs and are not interchangeable.