Java Reference
In-Depth Information
Self-Test Exercises
4. What is a compiler?
5. What is a source program?
6. What is an object program?
7. What do you call a program that runs Java byte-code instructions?
8. Suppose you defi ne a class named NiceClass in a fi le. What name should the
fi le have?
9. Suppose you compile the class NiceClass . What will be the name of the fi le
with the resulting byte-code?
1.2
Expressions and Assignment Statements
Once a person has understood the way variables are used in programming, he
has understood the quintessence of programming.
E. W. DIJKSTRA , Notes on Structured Programming
Variables, expressions, and assignments in Java are similar to their counterparts in most
other general purpose languages. In this section, we describe the details.
Identifiers
The name of a variable (or other item you might define in a program) is called an
identifier . A Java identifier must not start with a digit and all the characters must
be letters, digits, or the underscore (_) symbol. (The symbol $ is also allowed, but it
is reserved for special purposes only, so you should not typically use $ in your Java
identifiers.) For example, the following are all valid identifiers:
identifier
x x1 x_1 _abc ABC123z7 sum RATE count data2 bigBonus
All of the preceding names are legal and would be accepted by the compiler, but the
first five are poor choices for identifiers, since they are not descriptive of the identifier's
use. None of the following are legal identifiers and all would be rejected by the
compiler:
12 3X %change data-1 myfirst.java PROG.CLASS
The first two are not allowed because they start with a digit. The remaining four
are not identifiers because they contain symbols other than letters, digits, and the
underscore symbol.
 
 
Search WWH ::




Custom Search