When writing the program, according to certain specifications from the name to better let's take a quick read is not easy to confuse the class name or variable name. So, there is the following specifications:
Class Name: For all classes, the name of the class must support the "big hump" principle, namely: the first letter of the word must be capitalized, if a class name with multiple words, each word is capitalized.
Such as: TestDemo;
Method names and variable names: must support the "small hump" principle, namely: in addition to the first word that the remaining capitalized words, if a method or variable name only a word, then all lowercase.
Such as: testDemo ();
Constant name: When you define a constant name must be all uppercase, between words can also use "_" to separate the open.
Such as: the PI; SUM_ADD;
Source File name: source file name must be the same as the class name, and the case to be exactly the same.
Such as: source file TestDemo class named TestDemo.java
The main method (main method): that a Java program all Java programs are executed by the main method starts in one and only one main method.
如:public static void main(String[] args){}
Keywords: We know that there are more than fifty Java keywords, so when to classes, methods, variables, constants, etc., or any identifier named, can not use Java keywords as a name.
Such as: int keyword, class name can not be called other identifiers int, method, also can not be int, of course, can be written as: test_int, such wording is supported.
Specifications: We know that Java stressed that "see-known name meaning", so when writing an identifier, we should follow this principle.
Such as: the preparation of a student category, then the name of the class can be written as: Student
Written in Java specifications reflect the following code:
. 1 Package com.lxj.cnblogs; 2 . 3 / ** . 4 * @author Liu will . 5 * . 6 * / . 7 public class TestDemo { // TestDemo as the class name, following the "big hump principle", and this is just a test class , so named: TestDemo (test case) . 8 . 9 Final Double the PI = 3.14; // the PI as a constant, follows the writing specifications in all caps 10 . 11 public void TestVariable () { // TestVariable as the method name, followed " small hump "principle 12 is int Age = 20 is ; 13 is int studentAge = 18 is; //age and studentAge as a variable name, followed the "little hump" in principle 14 } 15 16 public static void main (String [] args) { // I am the main method, all the procedures are performed by me begin 17 System.out .println ( "the HelloWorld"); // console output a string, called: HelloWorld, greetings from Java's 18 } 19 }