The basic syntax of _java

  • 2020-04-01 01:23:14
  • OfStack

preface
After learning the first Java program, after the system to learn Java. Start with the basic grammar, which you can also understand as English or Chinese grammar, but each has its own characteristics and differences. Learning programming is also a learning process of programming language. When we are learning English, we all say that you must speak English well if you want to learn English well, so you must write when you are learning programming. Programming is nothing more than a process of writing code, the first is to have a foundation in your mind, no basis to write, like a good article, no good writing is not written. Good writing depends not only on accumulation, but also on creation, and so does programming. Java is an object-oriented language, in the process of writing code, the most contact is the class and interface and the following properties and methods. So in the process of learning we have to continue to accumulate important classes and methods, so that writing programs will be convenient and fast. Here's the basic syntax of Java:

The key points are as follows :
The & # 8226; Master the rules for defining identifiers
The & # 8226; Understand the common reserved words and separators
The & # 8226; Master the use of various simple data types
The & # 8226; Master the use of operators and expressions
The & # 8226; Master the simple I/o methods of Java programs

1. Java identifiers
A name used to represent a variable, method, or class, etc. The rules are defined as follows:
The & # 8226; Use only letters, Numbers, underscores, and dollar signs.
The & # 8226; You can only begin with letters, underscores, and dollar signs. You can't start with a number.
The & # 8226; Case sensitive, no length limit. But it's better not to be too long. It's not necessary.
The & # 8226; It should have a specific meaning. Best expressed as a related word, such as an addition method, it is best to write: add (inta,intb).

2. Java reserved words
These reserved words are often used in programming.

3. Java delimiters
The & # 8226; Has: Spaces, parentheses, curly braces, semicolons, and so on.
The & # 8226; Every statement ends with a semicolon, whether one or more lines. Blocks are statements contained within {} and blocks can be nested. Whitespace is inserted in the middle of the elements of the code: it is composed of one or more Spaces. It can also be composed of one or more TAB Spaces to form blank lines.

4. Java annotations
Comments are used to make a formal statement of the code you write, so that it is not only logical, but also understandable to others and convenient for future development.
(1) single line: //... Used to comment against a line of code
(2) multi-line:
(3) document comments: use the javadoc tool to take the information out of the source code and document comments and convert it into an HTML file

5. Java data types
A data type is the type in front of an attribute or method, such as inta; Int is a data type that represents an integer variable. The data types in Java are divided as follows:
< img border = 0 height = 365 SRC = "/ / files.jb51.net/file_images/article/201301/201313100810748.jpg" width = 623 >  

6. Java operators and expressions
1. Arithmetic operator: plus + minus - times * over/remainder % plus plus ++ minus minus -
2. Assignment operator: =
3. Relational operator: > < > = < = = =! =
Logical operators: true, false
5. Conditional operator:? :

7. Java input and output
System. In represents the input stream; System.out stands for output.

Related articles: