Home >Java >javaTutorial >The key to opening the door to JAVA--Grammar

The key to opening the door to JAVA--Grammar

坏嘻嘻
坏嘻嘻Original
2018-09-14 16:12:301612browse

This article introduces most of the syntax of Java to you, and I hope you can learn it patiently.

After studying C/C for several years, I started to officially transfer to JAVA today. I hope to go deeper and deeper on this road and get better and better~ Let’s start with grammar~ Let’s learn the core technology of JAVA.

1. Every method in Java is included in the class, including the main method. The main method is generally defined as public static void main, which is a static function, indicating that the main method does not It will depend on the object of the class and can be called without creating an object. The main method is the entry point for executing your own code.

2. The length of all data types in Java is fixed and will not change randomly. This is different from C and is also a reflection of its good portability.

3. All char types in java are in Unicode encoding format.

4. Constants defined in java use final instead of const. const is a reserved word of java, but it is not used yet.

5. The >> operator means shifting the binary bits to the right and filling the high bits with the sign bit. There is the >>> operator in Java, which means to shift the binary to the right and fill the high bits with 0.

When performing a shift operation, the shift amount needs to be modulo 32/64 (for int, the values ​​​​of 1 << 35 and 1<<3 are the same)

6. The substring function of string in java has the same meaning as the substring function of c but the meaning of the parameters is different. s.substring(a,b) in java means intercepting s from a to b- The string of 1, but c means to intercept the string from a to a b-1 in s.

7. Input and output,

Console: System.out.println() with newline                         System.out.print() without newline               System.out.printf () Formatted output

Create the Scanner object scn and bind it to System.in, you can use scn.nextLine() scn.next() scn.nextDouble(), etc. for input

File: Create the Scanner object scn and bind it to the File object. Use scn to read the file. When writing the file, create the PrintWriter object pwt and bind it to the file name. You can use pwt to read the file. write operation.

8. The execution control of Java is basically the same as that of C. Java has a new break Label function, which can directly break to the back of the Label block for execution.

Continue Label is to jump to the head of the loop in the Label block to continue execution.

Related recommendations:

Java, java official website_PHP tutorial

##Connecting PHP and Java -- PHP/Java Bridge [1]

The above is the detailed content of The key to opening the door to JAVA--Grammar. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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