|
|
|
1000 Java Tips ebook
|
|
 

Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java
programming articles and tips. Please take your copy here.
Take your copy of free "Java Technology Screensaver"!. |
|
Easy Learn Java: Programming Articles, Examples and Tips - Page 167
Previous
1060 Stories (530 Pages, 2 Per Page)
Next
The Java Lesson 3: Identifiers and primitive data types
|
1. Identifiers in Java | 2. Primitive data types in Java
Identifiers and primitive data types
Uses of identifiers
-
To name a variable (a data area
that takes on different values during processing)
-
To name a method (a module of
code)
-
To name a class (a definition
from which objects can be constructed)
-
To label a statement (for later
referencing)
Rules for identifiers
-
It must not be a
Java keyword
-
It must begin with a letter,
dollar sign ( $ ), or
underscore ( _ )
-
Subsequent characters may be
letters, dollar signs, underscores, or digits
-
Case matters. For example, the
three identifiers MAIN,
Main, and main are different.
Examples of valid
identifiers
yearlyGrossPay
_2002_Budget
JuneActual
$totalAmtDue
Programming
conventions
-
Are not enforced by the
compiler but make it easier to read and maintain Java code
-
Most programmers use "camel
caps" (such as firstQuarterSalesTotal) to handle long identifiers that appear
to contain multiple words. Some use undercores (like first_Quarter_Sales_Totals).
-
Begin variable names, method
names, and labels with a lower case letter. For example, totalAmount, hoursWorked, employeeName, calcBonus, and main.
-
Begin class names with a
capital letter. For example, Person, Customer, SalesRep, and Part.
-
Names of constants should be
all capitals. For example, TAX_RATE, COMMISSION, and DEPOSIT_CODE.
16 comments | | Score: 4
|
Posted by jalex on Wednesday, February 11, 2004 (00:00:00) (23053 reads)
|
|
|