Java language Fundamentals 1 Issues Summary

Source: Internet
Author: User

1. Is there really only one public class in a Java class file?

Program Experiment:

public class Test1 {
public static void Main (String args[]) {
}
public class innerclass{

}
}

The program operating system does not have an error stating that there can be more than one public class in a class file. Each compilation unit (file) can have only one public class. Each compilation unit can have only one exposed interface, and this interface is represented by its public class. If you can have more than one public class, the program will not be able to identify where to import the program from. Above this program appears the main class and the general public class, the second class is a general public class. It mainly distinguishes between public and main classes, main classes and main functions. There is not only one public class in the Ava class file, there can be more than one inner class, it can be common.

The return value of the 2.main method has void changed to int program can compile pass? Can you run it?

Compilation error

Add return 0 and compile right.

An error occurred at run time

3. Why is the Java rule static as the main () method of the entry point of the program?

The main function is actually a method of the same class, such as a class is Test, then the main of the class is actually Test.main (string[] args), it is well known that if a method is not static, you should first instantiate the class, such as to test t=new Test (); Before you can call Test.main (); This is impractical for running a program's main function, so for example, define the main function as static so that Test.main () can be called directly.

4. Problems with global variables and local variables

5. Trivia

6. Type Conversion Issues

.

The int short long byte represents an integer whose value is accurate, and the float double is floating point, which represents an approximation, so that when an integer is converted to a floating-point type, the approximate value will be lost in precision. While ascll are integers, there is no precision loss in converting Char to integral type

7. Accuracy Issues

Java in the decimal and binary conversion problems, double type of the value of 64bit, that is, 64 binary number, except the highest bit represents the positive and negative sign of the bit, in the lowest bit will be with the actual data error, simply is we give the value, in In most cases it takes more than 64bit of digits to be accurately represented (even in the case of an infinite number of bits), whereas a double type has a value of only 64bit, and the number of digits behind it will definitely bring an error, and the result of "mathematically accurate" cannot be obtained.

When using the BigDecimal (double) constructor, accurate errors occur when used improperly, and the limitations of binary floating-point numbers produce similar problems

8.

When "x+y=" is in front, the default is to convert int x, y to String, and "x+y=" causes the compiler to think that x, Y is a string type, System. the parameters of Out. println () itself are string by default, and in this case the conversion is defaulted, resulting in the result, and the second is a simple output that does not cause the calculator to "misunderstand".

Java language Fundamentals 1 Issues Summary

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.