All things are difficult at the beginning, and beginners to Java programming often encounter a variety of problems. For self-taught readers, it takes more time and energy to solve these problems, and once the problem can not be solved for several days, it often brings great frustration.
\
So this section introduces some beginners often appear mistakes, in order to reduce the obstacles in learning readers.
1) Case
As we mentioned earlier, Java is a case-sensitive language. But since most readers are Windows loyalists, they tend not to pay enough attention to size (the Linux platform is case-sensitive).
For example, a reader may write a Java program whose class is HelloJava, but when he runs the Java program, he runs javaHelloJava in the form of javaHelloJava. This incorrect form is not written strictly according to the Java program, which may cause the system to prompt the error shown in the figure.
\
Therefore, it is important to remind you that HelloJava and HelloJava are completely different in Java programs, and you must pay strict attention to case issues in Java programs.
In addition, when you write Java programs following the examples in this tutorial, you must pay strict attention to the case of each word in the Java program and not write arbitrarily. For example, class and class are two different words. Class is correct, but if you write class, the program will not compile.
In fact, keywords in Java programs are all lowercase and do not need to be capitalized.
2) The path contains Spaces
This is a more error-prone question. Since many Windows directories contain Spaces, a typical example is the ProgramFiles folder, which is the default JDK installation path.
If the CLASSPATH environment variable contains a path with Spaces, an error may be raised. Therefore, you are advised not to install JDK and Java-related programs and tools in a path containing Spaces. Otherwise, errors may occur.
3) Problems with the main method
If you want to run a Java class directly with a Java command, the Java class must contain the main method, which must be public and static, which must declare the return value of the method using void, and which can only be an array of strings. It can’t be any other kind of argument. For the main method, the preceding public and static modifiers are interchangeable, but the rest are fixed.
When defining the main method, do not write it as main. If you accidentally write the first letter of the method name in uppercase, you will compile without any problems, but you will get an error message like this when you run the program:
\
This error indicates that the main method cannot be found because the Java virtual machine will only choose to execute from the main method. With the Main method, the Java virtual machine treats the method as a normal method, not as an entry point to the program.
The main method can place executable statements that the programmer needs to execute, such as System.out.println(“HelloJava! ), this line is an output statement in Java, used to type a “HelloJava!” to the console The content of the string is output with a newline character.
Print (what needs to be printed) and System.out.println(what needs to be printed), where the former does not wrap after output and the latter does line wrap after output. These two methods will be explained in more detail later, so the reader can only write them down here.