Java Reference
In-Depth Information
Although the Java language doesn't require it, using a consistent
case format for each kind of identifier makes your identifiers easier
to understand. There are various Java conventions regarding identi-
fiers that should be followed, though technically they don't have to
be. For example, we use
KEY CONCEPT
Java is case sensitive. The uppercase
and lowercase versions of a letter
are distinct.
title case (uppercase for the first letter of
each word) for class names. Throughout the text, we describe the preferred case
style for each type of identifier when it is first encountered.
While an identifier can be of any length, you should choose your names care-
fully. They should be descriptive but not verbose. You should avoid meaningless
names such as a or x . An exception to this rule can be made if the short name
is actually descriptive, such as using x and y to represent ( x , y ) coordinates on a
two-dimensional grid. Likewise, you should not use unnecessarily long names,
such as the identifier theCurrentItemBeingProcessed . The name currentItem
would serve just as well. As you might imagine, the use of identifiers that are
verbose is a much less prevalent problem than the use of names that are not
descriptive.
You should always strive to make your programs as readable as possible.
Therefore, you should always be careful when abbreviating words. You might
think curStVal is a good name to represent the current stock value,
but another person trying to understand the code may have trouble
figuring out what you meant. It might not even be clear to you two
months after writing it.
KEY CONCEPT
Identifier names should be descrip-
tive and readable.
White Space
All Java programs use white space to separate the words and symbols used in a
program. White space consists of blanks, tabs, and newline characters. The phrase
“white space” refers to the fact that, on a white sheet of paper with black print-
ing, the space between the words and symbols is white. The way a programmer
uses white space is important because it can be used to emphasize parts of the
code and can make a program easier to read.
Except when it's used to separate words, the computer ignores
white space. It does not affect the execution of a program. This fact
gives programmers a great deal of flexibility in how they format a
program. The lines of a program should be divided in logical places,
and certain lines should be indented and aligned so that the pro-
gram's underlying structure is clear.
Because white space is ignored, we can write a program in many different
ways. For example, taking white space to one extreme, we could put as many
words as possible on each line. The code in Listing 1.2, the Lincoln2 program, is
formatted quite differently from Lincoln but prints the same message.
KEY CONCEPT
Appropriate use of white space
makes a program easier to read and
understand.
 
Search WWH ::




Custom Search