Hands on the brain

Source: Internet
Author: User

Java hands-on brain

1. Enumtest.java Example

The results of the Enumtest.java operation are as follows

Run result analysis: Enum type is a reference type and is not part of the original data type.

Conclusion: An enumeration type is a reference type and is not part of the original data type, and each of its specific values refers to a specific object. The same value refers to the same object.

You can use the "= =" and the Equals () methods to directly compare the values of the enumeration variables, in other words, the result of the "= =" and the Equals () methods are equivalent for variables of enum types.

2. Testdouble.java Example

Testdouble.java Running Results

Results analysis: The conversion between some types, the accuracy will be missing. So the same data needs to be converted to multiple types, and this data needs to be used for a longer period of time, and in most cases it is recommended to use coercion type conversions directly.

Conclusion: The result of the calculation using a double type of numerical value is imprecise.

3. What is the output of the following code?

int x=100;

int y=200;

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

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

Why is there such an output result?

Operation Result:

Results analysis: System.out.println ("x+y=" +x+y); this line of code output 100200 is because the computer reads the code is in order, to output is "x+y=", the back of the +x is 100, and then a +y is 200, so the last output X +y=100200, while System.out.println (x+y+ "=x+y"); x+y=100+200=300, the final output results.

Conclusion: In addition to the assignment operator =, all the binding is left to right.

4. Hands-on brain:

Look at this figure, and look at the number of bits in Java for each data type, and the range of values that you can draw.

Conclusion: The loss of information may be caused by coercion of type conversions.

Hands on the brain

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.