Java Reference
In-Depth Information
If you have never seen a program written in a programming language, the Java program,
ASimpleJavaProgram , given in the previous section, may seem to be written in a
foreign language. To make meaningful sentences in any foreign language, you must learn
its alphabet, words, and grammar. The same is true of a programming language. To write
meaningful programs, you must learn the programming language's special symbols,
words, and syntax rules. The syntax rules tell you which statements (instructions) are
legal, or accepted by the programming language, and which are not. You must also learn
the semantic rules, which determine the meaning of the instructions. The programming
language's rules, symbols, special words, and their meanings enable you to write programs
to solve problems.
Programming language: A set of rules, symbols, and special words used to construct
programs.
In the remainder of this section, you will learn about some of the special symbols used in
a Java program. Additional symbols are introduced as other concepts are encountered in
later chapters. Similarly, syntax and semantic rules are introduced and discussed through-
out the topic.
2
Comments
The program that you write should be clear not only to you, but also to the reader of
your program. Part of good programming is the inclusion of comments in the program.
Typically, comments can be used to identify the authors of the program, give the date
when the program is written or modified, give a brief explanation of the program, and
explain the meaning of key statements in a program. In the programming examples, for
the programs that we write, we will not include the date when the program is written,
consistent with the standard convention for writing such topics.
Comments are for the reader, not for the compiler. So when a compiler compiles a
program to check for the syntax errors, it completely ignores comments. Throughout this
book, comments are shown in green.
ASimpleJavaProgram , given in the previous section, contains the following comments:
//********************************************************
// This is a simple Java program. It displays three lines
// of text, including the sum of two numbers.
//********************************************************
A Java program has two common types of comments—single-line comments and
multiple-line comments.
Single-line comments begin with // and can be placed anywhere in the line. Every-
thing encountered in that line after // is ignored by the compiler. For example, consider
the following statement:
System.out.println("7 + 8 = " + (7 + 8));
 
 
Search WWH ::




Custom Search