Home > Java > javaTutorial > What does java syntax mean?

What does java syntax mean?

coldplay.xixi
Release: 2020-08-19 10:50:25
Original
2774 people have browsed it

The grammar of java refers to the rules in java, that is, the naming rules of java: 1. The naming of the package, all lowercase, is defined by the domain name; 2. The naming of the class, the first letter of the word is capitalized; 3. When naming methods, the first letter should be lowercase and the beginning of the letter should be uppercase; 4. When naming constants, use all uppercase letters and often be underlined.

What does java syntax mean?

[Related learning recommendations: java basic tutorial]

The syntax in java refers to the syntax in java The rules, that is, the naming rules of java:

1. Package naming (all lowercase, defined by the domain name)

The names of Java packages are all composed of Made up of lowercase words. However, due to the characteristics of Java object-oriented programming, every Java programmer can write his own Java package. In order to ensure the uniqueness of each Java package naming, in the latest Java programming specifications, programmers are required to define their own Java package. The name of the package is preceded by a unique prefix. Since domain names on the Internet are not repeated, programmers generally use their own domain name on the Internet as the unique prefix of their own program packages. For example: net.frontfree.javagroup

2. Class naming (the first letter of the word is capitalized)

According to convention, Java class names usually start with capital letters. If the name consists of multiple words, the first letter of each word should be capitalized, such as TestPage; if the class name contains an abbreviation, each letter of the written word should be capitalized, such as: XMLExample, and a little naming The trick is that since classes are designed to represent objects, try to choose nouns when naming classes.

For example: Graphics

3. Name the method (the first letter is lowercase, the first letter is uppercase)

The first word of the method name should be Start with a lowercase letter, and subsequent words start with an uppercase letter.

For example: drawImage

4. Naming of constants (all capital letters, often underlined)

The names of constants should all use capital letters, and Indicate the complete meaning of the constant. If a constant name consists of multiple words, the words should be separated by underscores.

For example: MAX_VALUE

5. Naming of parameters

The naming convention of parameters is the same as that of methods, and in order to avoid causing errors when reading the program Confused, please make the parameter naming as clear as possible while ensuring that the parameter name is one word.

Knowledge expansion:

Pay attention to the following points when naming variables:

1. Choose meaningful names , note that the first letter of each word must be capitalized.

2. Do not use the same variable in a function to represent two values ​​with different meanings.

3.i, j, k, etc. are only used as loop index variables for small loops.

4. Avoid using Flag to name state variables.

5. Use Is to name logical variables, such as: blnFileIsFound. By naming Boolean variables in a positive manner, other developers can more clearly understand the meaning of Boolean variables.

6. If necessary, append a calculation qualifier at the end of the variable, such as: curSalesSum.

7. The names are not inclusive, curSales and curSalesSum.

8.static final variable (constant) names should be in capital letters and indicate the full meaning.

9. If you need to abbreviate variable names, you must pay attention to the consistency of the abbreviation rules throughout the code. For example, using intCnt in some areas of your code and intCount in other areas adds unnecessary complexity to your code. It is recommended that abbreviations should be avoided in variable names.

10. By placing a quantifier at the end, you create more unified variables that are easier to understand and search for. For example, use strCustomerFirst and strCustomerLast instead of strFirstCustomer and strLastCustomer. Commonly used quantifier suffixes are: First (the first in a group of variables), Last (the last in a group of variables), Next (the next variable in a group of variables), Prev (the previous variable in a group of variables) ), Cur (the current variable in a set of variables).

11. Choose the best data type for each variable, which will not only reduce the memory requirements, speed up the execution of the code, but also reduce the possibility of errors. The data type used for a variable may affect the results of calculations performed on that variable. In this case, the compiler does not generate a runtime error, it simply forces the value to conform to the data type requirements. These types of issues are extremely difficult to find.

12. Try to narrow the scope of variables as much as possible. If a variable's scope is larger than it should be, the variable can continue to exist and occupy resources long after the variable is no longer needed. The main problem with them is that they can be modified by any method in any class, and it is difficult to track exactly where the modification was made. Occupying resources is an important issue involved in scope. For variables, keeping the scope as small as possible will have a huge impact on the reliability of the application.

Regarding the naming method of constants, in JAVA code, it is recommended to use constants to replace numbers and fixed strings at any time. In other words, except for 0 and 1, other numbers should not appear in the program as much as possible. Constants can be defined at the beginning of the program or in a wider scope. The names should be in uppercase letters and indicate the full meaning of the constant. If a constant name consists of multiple words, the words should be separated by underscore "_" such as: NUM_DAYS_IN_WEEK, MAX_VALUE.

Related learning recommendations: Programming video

The above is the detailed content of What does java syntax mean?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template