There can be more than one public class in a Java class file
public class Test1 {public static void main(String[] args) { // TODO 自动生成的方法存根}public class InnerClass{} }
This is the right way to write.
Java specifies that main () is a static cause
In the case of static, it is not necessary to create an object to be used.
A non-static member function must first construct and instantiate the class that contains the function before executing it.
If the non-static main is allowed, then the class where the main function resides must be instantiated first,
Then you need to write a function to instantiate the class where main is, and then call Main, where is this instantiation code written? If it is also non-static, would it not be to write a function to instantiate the class it is in?
Therefore, the Java language specifies that main must be static.
That is: The program must have a portal, if main is not static, you need something else to instantiate the main, and the instantiation of the main thing if it is not static, you need to instantiate the other, so loop down the program is impossible to start execution. Therefore, the main method is static.
Type conversions in Java
First look at a picture.
Let's write a piece of code to see how many bits of data are in Java.
public class Test1 {public static void main(String[] args) { // TODO 自动生成的方法存根 System.out.println(Byte.SIZE); System.out.println(Byte.SIZE/8); System.out.println(Short.SIZE); System.out.println(Short.SIZE/8); System.out.println(Character.SIZE); System.out.println(Character.SIZE/8); System.out.println(Integer.SIZE); System.out.println(Integer.SIZE/8); System.out.println(Float.SIZE); System.out.println(Float.SIZE/8); System.out.println(Long.SIZE); System.out.println(Long.SIZE/8); System.out.println(Double.SIZE); System.out.println(Double.SIZE/8);}}
The operation results are as follows
It can be seen from the conclusion that, in addition to the int to double conversion, the conversion between the different data types of the same number will lose precision.
The role of operator + in Java
First look at a piece of code
public class Test2 {public static void main(String[] args) { // TODO 自动生成的方法存根int X=100;int Y=200;System.out.println("X+Y="+X+Y);System.out.println(X+Y+"=X+Y");}}
The results of the operation are as follows:
The reason for this is that + can be used as a mathematical operation symbol, and can concatenate two strings, as well as the precedence of operators in Java.
The plus sign in the first line is the two parts that are connected to the output.
The plus sign in the second row is the function of the arithmetic operation.
Java Learning Notes