Java Reference
In-Depth Information
21
Figure 12
Calling a Method
A sequence of characters enclosed in quotation marks
ÑHello, World!Ñ
is called a string. You must enclose the contents of the string inside quotation marks so
that the compiler knows you literally mean ÑHello, World!Ñ . There is a reason
for this requirement. Suppose you need to print the word main. By enclosing it in
quotation marks, ÑmainÑ , the compiler knows you mean the sequence of characters
main , not the method named main . The rule is simply that you must enclose all text
strings in quotation marks, so that the compiler considers them plain text and does not
try to interpret them as program instructions.
A string is a sequence of characters enclosed in quotation marks.
You can also print numerical values. For example, the statement
System.out.println(3 + 4);
displays the number 7.
The println method prints a string or a number and then starts a new line. For
example, the sequence of statements
System.out.println("Hello");
System.out.println("World!");
prints two lines of text:
Hello
World!
Search WWH ::




Custom Search