Common problems you may encounter in learning the Java language

Source: Internet
Author: User
Tags case statement reset

This tutorial will discuss some of the common problems you might encounter in learning the Java language.

Problem one: The compiler could not find the class.

Workaround:

Make sure you have imported the class or its package.

If the CLASSPATH environment variable is set, reset it.

Make sure that the spelling of the class name is the same as defined, so be careful with the case.

If the classes are in the package, make sure they are in the correct subdirectory.

At the same time, some programmers use different names from the. java file name for the class. Make sure you use the class name instead of the filename. In fact, this error does not occur if the class name and file name are the same.

Question two: The annotation cannot find one of the classes

Workaround:

Make sure you specify the name of the class rather than the file name of the class.

If the CLASSPATH environment variable is set, reset it.

If the classes are in the package, make sure they are in the correct subdirectory.

Make sure that you call this annotation from the directory in which the. class file resides.

Question three: Does the procedure not work? What was wrong?

The following are the common mistakes of novice Java, note the following:

Do you forget to use the break in every case statement in a switch statement?

Do you use the assignment operator when you should use the comparison notation = =?

is the termination condition in the loop statement correct? Make sure you don't end the cycle prematurely or too late. That is, make sure the < or <= or > or >= a operator is used correctly.

Remember that the index of an array starts at 0, so the loop of the array should be:

for (int i = 0; i < array.length; i++)

. . .

Are you comparing floating-point numbers with = =? The greater-than and less-than sign (> and <) operators are more appropriate in the conditional logic of floating-point numbers.

Do you have questions about encapsulation, inheritance, or other object-oriented programming and design concepts?

Make sure the statement block is circled between the braces {and}. The following code block looks as if it is right because it is written in indentation, but you look carefully at the missing {}:

for (int i = 0; i < arrayofints.length; i++)

Arrayofints[i] = i;

System.out.println ("[I] =" + arrayofints[i]);

Do you use the conditional operation symbol correctly? Be sure to understand && | | and use them correctly.

Do you use the negation operator (!)? Try not to use it. This will reduce the occurrence of errors.

Do you use the Do-while statement. If so, do you know that the Do-while statement is executed at least once? It is not the same as a while loop statement, and it can not be executed even once.

Do you want to change the value of the parameter from the method? Parameters in Java are passed by parameters and cannot be changed in the method.

Do you inadvertently add a semicolon (;) to prematurely terminate the statement? Like what:

for (int i = 0; i < arrayofints.length; i++);

Arrayofints[i] = i

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.