01.JAVA Language Basics Related Solutions

Source: Internet
Author: User
Tags float double

1. First, the first question is, is there really only one public class in a Java class file? And the following code is given. You can see that there are two public classes in this program:

I have made different debugs:

It can be seen that if an entity is defined only in the first public class, or if two are undefined and no error is found, the program can run. Indeed, each compilation unit (file) can have only one public class. What this means is that each
A unit can have only one open 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.

There can be only one public representing the main class, and the rest can represent the common class, but be aware of the syntax.

2. .

Compilation cannot be passed. So I made the following compilation:

Answer.

3.

The static keyword tells the compiler that the main function is a static function. That is, the code in the main function is stored in a static storage area, that is, when the class is defined, the code already exists. If the main () method does not use the static modifier, then the compilation will be error-free, but if you attempt to execute the program you will get an error indicating that the main () method does not exist. Because the class that contains main () is not instantiated (that is, an object without this class), its main () method does not exist. Using the static modifier means that the method is static and does not need to be instantiated for use.

4.

                   .

 

5.

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 penalty for converting char into an integral type.

6 .

.

Because there is a problem in the decimal and binary conversion in Java, double type of the value of 64bit, that is, 64 binary number, minus the highest bit to indicate the positive and negative signs of the bit, in the lowest bit will be with the actual data error, in simple terms, 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.

7.

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

8.

Code involved:

Public class Test {

Public Static void Main (string[] args) {

int x=100;

int y=200;

System. out. println ("x+y=" +x+y);

System. out. println (x+y+ "=x+y");

The result of the operation:

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".

01.JAVA Language Basics Related Solutions

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.