Java programmers must read-some common problems in programming

Source: Internet
Author: User
Tags case statement

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, some programmers use different names for the class from the. Java file. Make sure that you use the class name instead of the file name. In fact, this error will not occur if the class name and file name are the same.

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 following code block looks right, because it adopts indent writing, 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.