Content received from: http://JavaFAQ.nu/java-article386.html


The Java Lesson 3: Identifiers and primitive data types
Wednesday, February 11, 2004 (00:00:00)

Posted by jalex

All Java Lessons contents page | Java Lesson 1 | Java Lesson 2 | Java Lesson 3 | Java Lesson 4 | Java Lesson 5 | Java Lesson 6 | Java Lesson 7 | Java Lesson 8 | Java Lesson 9 | Java Lesson 10 | Java Lesson 11 | Java Lesson 12 | Java Lesson 13 | Java Lesson 14 | Java Lesson 15 | Java Lesson 16 | Java Lesson 17 | Java Lesson 18 | Java Lesson 19 | Java Lesson 20 | Java Lesson 21 | Java Lesson 22 | Java Lesson 23 | Java Lesson 24 | Java Lesson 25 | Java Lesson 26 | Java Lesson 27 | Java Lesson 28 | Java Lesson 29 | Java Lesson 30 | Java Lesson 31 | Java Lesson 32 | Java Lesson 33 | Java Lesson 34 | Java Lesson 35 | Java Lesson 36 | Java Lesson 37 | Java Lesson 38 | Java Lesson 39 | Java Lesson 40 | Java Lesson 41 | Java Lesson 42 | Java Lesson 43 | Java Lesson 44 | Java Lesson 45 | Java Lesson 46

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.