This tutorial will discuss some common problems that may occur when learning the Java language.
Problem 1: the compiler cannot find the class.
Solution:
Make sure that you have imported the class or its package.
If you have set the classpath environment variable, You need to reset it.
Make sure that the spelling of the class name is the same as the definition. Pay attention to the Case sensitivity issue.
If the classes are in the package, make sure they are in the correct subdirectory.
At the same time, someProgramThe member uses different names for the class from the. Java file name. Make sure that you use the class name instead of the file name. In fact, make the class name
This error will not occur if it is the same as the file name.
Problem 2: The annotator cannot find one of the classes.
Solution:
Make sure that you specify the class name rather than the class file name.
If you have set the classpath environment variable, You need to reset it.
If the classes are in the package, make sure they are in the correct subdirectory.
Make sure that you call this annotator from the directory where the. Class file is located.
Question 3: cannot a program work? What's wrong?
The following are public errors made by beginners of Java. Note the following:
Do you forget to use break for every case statement in the switch statement?
Do you use the value assignment operator = when the comparison operator number is =?
Are the termination conditions in the loop statements correct? Make sure that you do not terminate the cycle too early or too late. That is to say, make sure that the <, <= or> = A operator is used correctly.
Remember that the index of the array starts from 0, so the loop of the array should be:
For (INT I = 0; I <array. length; I ++)
...
Are you using = in the floating point type? Greater than or less than (> and <) operators are more suitable for the conditional logic of floating point numbers.
Do you have any questions about encapsulation, inheritance, or other object-oriented programming and design concepts?
Make sure that the statement block is enclosed in braces {And. The followingCodeThe block seems to be correct, because it uses indentation, but you should carefully check that {} is missing here {}:
For (INT I = 0; I <arrayofints. length; I ++)
Arrayofints [I] = I;
System. Out. println ("[I] =" + arrayofints [I]);
Are you sure you want to use the conditional operator number correctly? Make sure that you understand & | and use them correctly.
Do you use the negative operator (!)? Try not to use it. This will reduce the occurrence of errors.
Whether you have used the do-while statement. If yes, do you know that the do-while statement must be executed at least once? It is different from the while loop statement. It can be skipped once.
Do you want to change the value of the parameter from the method? Parameters in Java are transmitted by parameters, which cannot be changed in methods.
Do you have no intention of adding a semicolon (;) to terminate the statement too early? For example:
For (INT I = 0; I <arrayofints. length; I ++ );
Arrayofints [I] = I