Java Reference
In-Depth Information
Using Prefixes in Variable Names
Sun Microsystems has no suggested naming convention for Java
variables. It is customary to begin variable names with lowercase
letters. Some programmers use single character prefixes in front of
their variable names to denote the data type. For example, a
double value for sales tax might be named dSalesTax. For non-
primitive data types, programmers sometimes use a three-letter
prefix, similar to the standard Visual Basic notation for objects.
For example, a Label component might be named lblFirstName.
Regardless of the convention you follow, it is important to use
mnemonic, user-friendly variable names. Naming and coding
conventions will be covered in more detail later in the chapter.
The following step enters code to declare variables.
To Enter Code to Declare Variables
1. With the insertion point on line 16 in the coding window, type the line
comment and declaration statements, as shown in Figure 3-9 on the
previous page.
A line comment in line 16 explains that the following code declares and con-
structs variables (Figure 3-10). Three declaration statements are displayed in
lines 17 through 19. No assignment of values is made.
line
comment
declaration
statements
FIGURE 3-10
It may be helpful to remember that the integer data type, as declared in line
18, represents whole numbers, whereas the double data type represents a double-
precision, floating-point value. Table 3-2 on page 140 describes a double as a
number that is precise up to 14 or 15 decimal places. The word, floating, comes
 
Search WWH ::




Custom Search