Foreword
After learning the first java program, I will learn java systematically. Let’s start with basic grammar. You can also understand this grammar as the grammar in English or Chinese, but each has its own characteristics and differences. Learning programming is actually a learning process of programming language. When we are learning English, we all say that if you want to learn English well, you must speak it, so when you learn programming, you must write it. Programming is nothing more than a process of writing code. The first thing is that you must have a foundation in your mind. How can you write without a foundation? Just like a good article, it cannot be written without good writing. Good writing depends not only on accumulation, but also on creation, and the same is true for programming. Java is an object-oriented language. In the process of writing code, what you come into contact with the most are classes and interfaces as well as the following properties and methods. Then in the process of learning, we must continue to accumulate important classes and methods, so that writing programs will be convenient and fast. Let’s start learning the basic syntax of Java:
The key points of learning are as follows:
•Master the definition rules of identifiers
•Understand commonly used reserved words and delimiters
•Master the use of various simple data types
•Master operators and expressions Use of formulas
• Master the simple input and output methods of Java programs
1. Java identifiers
are used to represent the names of variables, methods or classes. The rules defined are as follows:
•Only letters, numbers, underscores and dollar signs can be used.
•Can only start with a letter, underscore and dollar sign. That is, it cannot start with a number.
•Strictly case-sensitive, no length limit. But it’s best not to be too long, and it’s not necessary.
•Should have a specific meaning. It is best to express it with a related word, such as an addition method, then it is best to write: add (inta, intb).
2. Java reserved words
These reserved words are often used during programming.
3. Java delimiters
•Have: spaces, parentheses, curly braces, semicolons, etc.
•Each statement, whether one line or multiple lines, ends with a semicolon. Block (Block) is multiple statements contained in {}, and blocks can be nested. Whitespace is inserted between elements of the code: it consists of one or more spaces, or it can also consist of one or more tab spaces to form multiple empty lines.
4. Java comments
Comments are used to give a standardized explanation of the written code. This is not only organized, but also understandable by others, and will also bring convenience to future development.
(1) Single line: //... used to comment one line of code
(2) Multiple lines: /* used to comment multiple lines of code
...
*/
(3) Documentation comments: Use the javadoc tool to read from the source Extract the information from the code and document comments, and then convert it into an HTML file
/**
*…
*/
5. Java data type
The data type is the previous type when defining an attribute or method, for example, inta;int is a Data type, representing an integer variable. The data types in java are divided as follows
6. Java operators and expressions
1. Arithmetic operators: addition + subtraction - multiplication * division / remainder % addition + + subtraction - take Anti-
2. Assignment operator: =
3. Relational operator: >=4. Logical operator: true, false
5. Conditional operator: ? :
7. Java input and output
System.in represents the input stream; System.out represents the output.
The above is the content of java study notes (introduction)_java’s basic syntax. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!