Java Language Foundation Jobs

Source: Internet
Author: User

1. Hands-on brain

Read the example carefully: Enumtest.java, run it, analyze the running results?

Program Run Result:

Experimental conclusion: Enum type is a reference type!
An enumeration 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. After-school contact

Read the corresponding textbook, or use the Internet search engine, find out the anti-code, complement and the original code of the concepts, and then write a sample program, the positive numbers, negative numbers of various bit operations, observe the output, and the results of the manual calculation, to see the number in Java is the above-mentioned code representation.

The original code: is the binary fixed-point notation, that is, the highest bit is the sign bit, "0" is positive, "1" is negative, the remaining bits represent the size of the value.

Anti-code: Anti-code notation: the inverse code of a positive number is the same as its original code; the inverse of a negative number is a bitwise negation of its original code, except for the sign bit.

Complement: The complement notation stipulates that the complement of a positive number is the same as its original code; the complement of a negative number is added to the minus 1 of its inverse code.

3. Hands-on brain

Why is the numeric value of a double type not "mathematically accurate" result?

This involves the conversion of binary and decimal. n binary can be understood as: the power of the numerical x cardinality, for example, we are familiar with the decimal number 123.4=1x10²+2x10+3x (10 of the power of 0) +4x (10-1 power) The other binary is the same, such as the binary number 11.01=1x2+1x (2 of the power of 0) +0+1x (2-2 power) = decimal 3.25.   double The value of a type takes up 64bit, or 64 binary numbers, except that the highest bit represents the positive and negative sign, and the lowest bit is bound to have an error with the actual data (unless the actual data is exactly 2 of the N-squared).   for example, for example, to use 4bit to represent decimal 3.26, from high to low in turn corresponds to 2 1,0,-1,-2 power, according to the top analysis, Should be selected between binary number 11.01 (corresponding to decimal 3.25) and 11.10 (corresponding to decimal 3.5).   is simply the value we give, in most cases it takes more digits than 64bit to accurately represent it (even if it requires an infinite number of bits), and double The value of the type is only 64bit, and the number of bits in the back is bound to bring an error, and the result of "mathematically accurate" cannot be obtained.

4. Hands-on brain

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");

Output Result:

x+y=100200

300=x+y

Why is there such an output result?

The first sentence outputs the "+" connection literal, and the result is that x and Y will connect the two data.

The "+" in the two outputs of the statement is the operator, and the result is the sum of x and Y.

After-school assignments:

Write a program, the user input two number, to find out its subtraction, and the message box to display the calculation results.

Run results

Java Language Foundation Jobs

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.