Home Java javaTutorial What does java syntax mean?

What does java syntax mean?

Aug 19, 2020 am 10:50 AM
java grammar

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Perfect Number in Java Perfect Number in Java Aug 30, 2024 pm 04:28 PM

Guide to Perfect Number in Java. Here we discuss the Definition, How to check Perfect number in Java?, examples with code implementation.

Random Number Generator in Java Random Number Generator in Java Aug 30, 2024 pm 04:27 PM

Guide to Random Number Generator in Java. Here we discuss Functions in Java with examples and two different Generators with ther examples.

Weka in Java Weka in Java Aug 30, 2024 pm 04:28 PM

Guide to Weka in Java. Here we discuss the Introduction, how to use weka java, the type of platform, and advantages with examples.

Smith Number in Java Smith Number in Java Aug 30, 2024 pm 04:28 PM

Guide to Smith Number in Java. Here we discuss the Definition, How to check smith number in Java? example with code implementation.

Java Spring Interview Questions Java Spring Interview Questions Aug 30, 2024 pm 04:29 PM

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Break or return from Java 8 stream forEach? Break or return from Java 8 stream forEach? Feb 07, 2025 pm 12:09 PM

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

TimeStamp to Date in Java TimeStamp to Date in Java Aug 30, 2024 pm 04:28 PM

Guide to TimeStamp to Date in Java. Here we also discuss the introduction and how to convert timestamp to date in java along with examples.

Java Program to Find the Volume of Capsule Java Program to Find the Volume of Capsule Feb 07, 2025 am 11:37 AM

Capsules are three-dimensional geometric figures, composed of a cylinder and a hemisphere at both ends. The volume of the capsule can be calculated by adding the volume of the cylinder and the volume of the hemisphere at both ends. This tutorial will discuss how to calculate the volume of a given capsule in Java using different methods. Capsule volume formula The formula for capsule volume is as follows: Capsule volume = Cylindrical volume Volume Two hemisphere volume in, r: The radius of the hemisphere. h: The height of the cylinder (excluding the hemisphere). Example 1 enter Radius = 5 units Height = 10 units Output Volume = 1570.8 cubic units explain Calculate volume using formula: Volume = π × r2 × h (4

See all articles