2.
Rules for identifiers
2.1 What is an identifier:
in 1.Java languages, there are names for variables, constants, methods, all called Java identifiers.
2. Identifiers are used to name classes, objects, methods, variables, interfaces, and custom data types.
naming rules for 2.2 identifiers:
1. One region is unique, the same name can be used in different regions
2. must consist of letters, numbers, underscores, and $ symbols
3. cannot start with a number
4. cannot use illegal characters, such as:#,%.......& , etc.
5. cannot use System keywords
6. You cannot use spaces to separate
7. Unlimited Length
8. strictly case-sensitive
9. different identifiers have certain naming conventions
for the name of the constant, pay attention to the initial value .
naming conventions for 2.3 identifiers:
1. class and interface name: Capitalize the first letter of each word , such as MyClass,HelloWorld , and so on.
2. method name. The first letter is lowercase, the remaining initials are capitalized, and as few underscores as possible. For example,myName,settime and so on. This naming method is called Camel-named.
3. constant name. The constant name of the base data type uses all uppercase letters, and the words are separated by underscores. Object constants can be mixed in size. For example,size_name.
4. variable name. Can be mixed in case, first letter lowercase, inter-word separator with the first letter of the word capital. Don't underline, use the dollar sign less.
3.Java -expression
3.1 What is an expression:
a sequence consisting of a series of identifiers and operators. such as: comma expression , question mark expression , logical expression .
1. comma expression: used to delimit an expression. such as int = 1,b=2; .
2. question-Mark expression: such as ternary operator, (a>b? A++? b++).
3. logical expression: a meaningful expression that uses a logical operator to concatenate a relationship expression or a logical amount is called a logical representation. The value of a logical expression is a logical value, which is "true" or"false". if(a>b&&a>c)a++;
4. The concept and role of the package
4.1 What is a package:
1. Physically a folder
2. logically a collection of logically related classes
The role of the 4.2 package:
1. Avoid class names.
2. Control access rights.
3. packages can better manage logic-related classes and can control access between different packages.
naming conventions for 4.3 packages:
1. in the package name, you can use the . to differentiate the level of the package, and the package name is usually lowercase.
2. The first level refers to the type of the project, such as com,org,gov .
3. the second level refers to the name of the company developed or run by the project, such asChinasofti,icss,huawei .
4. The third level refers to the name of the project, such as:corejava,bcms,oa,erp .
5. The fourth level refers to the name of the project module, such as:bean,action,exception,chapter01 .
5. permission access modifiers
5.1 What is a permission access modifier
The Java language has four access modifiers, with permissions from large to small in turn:
1.public : Public permission to decorate classes, properties, methods. can be accessed by any class.
2.protected: Protected permissions decorated with properties, methods.
can be accessed by the same package class, if it is not the same package class, it must be a subclass of that class.
3.default: The same package permission modifies the class, property, method. can only be accessed by the same package class.
4.private: Private Permission Adornment property, method. can only be accessed in this class.
6.
encapsulation in the Java class
6.1 Package Nature
1. Encapsulation is a kind of information hiding technology.
2. Two meanings: (1) All attributes of an object are combined with all methods to form an indivisible independent unit
(2) Hide the internal structure of the object as much as possible
Rules for Java identifiers, etc.