Java Reference
In-Depth Information
Did You Know?
Hello, World!
The “hello world” tradition was started by Brian Kernighan and Dennis Ritchie.
Ritchie invented a programming language known as C in the 1970s and, together
with Kernighan, coauthored the first book describing C, published in 1978. The
first complete program in their book was a “hello world” program. Kernighan
and Ritchie, as well as their book The C Programming Language, have been
affectionately referred to as “K & R” ever since.
Many major programming languages have borrowed the basic C syntax as a
way to leverage the popularity of C and to encourage programmers to switch to it.
The languages C
and Java both borrow a great deal of their core syntax from C.
Kernighan and Ritchie also had a distinctive style for the placement of curly
braces and the indentation of programs that has become known as “K & R style.”
This is the style that Sun recommends and that we use in this topic.
String Literals (Strings)
When you are writing Java programs (such as the preceding “hello world” program),
you'll often want to include some literal text to send to the console window as output.
Programmers have traditionally referred to such text as a string because it is com-
posed of a sequence of characters that we string together. The Java language specifi-
cation uses the term string literals.
In Java you specify a string literal by surrounding the literal text in quotation
marks, as in
"This is a bunch of text surrounded by quotation marks."
You must use double quotation marks, not single quotation marks. The following
is not a valid string literal:
'Bad stuff here.'
The following is a valid string literal:
"This is a string even with 'these' quotes inside."
String literals must not span more than one line of a program. The following is not
a valid string literal:
"This is really
bad stuff
right here."
 
Search WWH ::




Custom Search