In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "what are the four rules to be followed by java identifiers". In daily operation, I believe many people have doubts about what the four rules of java identifiers are. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the questions of "what are the four rules to be followed by java identifiers?" Next, please follow the editor to study!
There are four rules for identifiers.
1. The identifier must start with a letter, the next loop _, and the dollar sign $.
2. The rest of the identifier can be any combination of letters, underscores _, $, and numbers. (note: identifiers cannot start with a number)
3. Java identifiers are case-sensitive and unlimited in length.
4. Identifiers cannot be keywords of Java.
I would also like to talk about the specification for the use of identifiers.
1. The identifier that represents the class name: the first letter of each word is capitalized. Such as Welcome, HellWorld
2. Identifiers for methods and variables: the first word is lowercase, starting with the second word with the first letter capitalized, also known as the "hump principle". Such as: play (), playGame ()
Next, to demonstrate, open the development artifact IDEA
As you can see from the above, the identifier can start with a letter, an underscore, a dollar sign, and an alphanumeric combination, so let's show you how to start with a number.
As you can see here, identifiers cannot start with a number, so the compilation will report an error, and of course, you can't use special symbols, such as the # sign, but only letters, lower _, dollar sign $and numbers.
To make it clear here, men can be used as representers, because the Java language uses the unicode character set, while the unicode character set contains Chinese, which can be demonstrated here.
Of course, it is not recommended to use Chinese when programming with Java.
Also, as shown in the following figure, the Java keyword cannot be used as an identifier, such as class, and the keyword is also called a reserved word, and they have the same meaning. Keywords have a special meaning, so we can't use keywords as identifiers
So what are the Java keywords? Here to tell you, Java keyword we do not need to remember, because when you enter the Java keyword as an identifier, IDEA will report an error, there will be a corresponding prompt.
Of course, I've also compiled a picture of the Java keyword here, which you can take a look at, but you don't need to remember that there are 50 keywords in the Java language.
After talking about identifiers and keywords, let's talk about variables. The essence of variables is operable storage space. For example, it is a bit like a parking space in a parking lot, and a variable is equivalent to a parking space. we can find the corresponding location by the name of the parking space and then determine what car is parked on it. The car here is similar to the data and is variable.
The essence of a variable is to represent an "operable storage space". The location of the space is determined, but what is in it is uncertain. We can access the "corresponding storage space" through the variable name to manipulate the value stored in this "storage space".
Here use Excel to give an example, such as the table in Excel, each table is equivalent to a "storage space", here you can write "2, 3, 33" and other different values, we can give the table a name, use the name to find its corresponding value.
It can be seen that if we give this table the name "monthly salary", then we can use "monthly salary" to find the corresponding value of 33.
It can be seen that the use of "monthly salary * 12" here actually refers to the value of "monthly salary" of 25000 and calculates the result of 300000, so how is it written in the Java program?
At this point, we are almost done with the knowledge of variables.
Let me ask you one more question. Do you know what programmers hate most?
Lose your hair? Is it difficult to find a man / girlfriend? Total output bug?
In fact, it is not, but pick up the code written by others, and there are no comments in the code.
In the Java language, in order to facilitate and read, you can write some illustrative text in the program to improve the readability of the program, which is called comments. Comments do not appear in bytecode files. Java compilers skip comment statements when compiling Java code, so you can write whatever you think in comment statements.
According to the function of comments, we can divide comments into three types: single-line comments, multi-line comments, and document comments.
The following are descriptions of the three comments
In the example written above, we use single-line comments, and the comment statement Java compiler automatically skips comments, and the shortcut key in IDEA is ctrl+/
Multi-line comment is / * multi-line comment content * /. Note that there can be no more nesting of multi-line comments in multi-line comments, otherwise an error will be reported.
Document comments, written on the class, you can write some class description, author, version and other information. Write on the method, you can write some method description, parameter description and other information.
At this point, the study of "what are the four rules to be followed by java identifiers" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.