Java base data type scavenging

Source: Internet
Author: User

The main thing is something that suddenly jumps out of the sense of importance, or something that you're forgetting, or what you think is important in the book ...

First, the underlying data type:

Integer type (4): Byte (1 bytes) short (2 bytes) int (4 bytes) long (8 bytes)

Character type (1): char (2 bytes)

Floating-point type (2): Float (4 bytes) double (8 bytes)

Boolean type (1): Boolean (1 bytes)

Because the integer type defaults to the int type, and the floating-point type defaults to double, if you want to use a long or float type, you need to keep the value of L (or L, preferably the upper case) or F (or F) after the number when the variable is assigned to it.

Three or two integer: 0b or 0B beginning; octal: 0 beginning; 16 in: 0x or 0X begin.

0 of these are numeric zeros.

The integral type is signed bit.

Four, Java uses 2 bytes of Unicode encoding, so char a = ' a '; and char Characterchinese = ' Medium '; it's all 2 bytes, which is different from the C language.

The char type, if treated as an integer, is a 16-bit unsigned integer.

If an int in a 0-2^16-1 range is directly assigned to a char, then the system treats it as a character.

Seven, ' \ ' used to represent the escape character. This point requires special attention when using a Windows path, such as a path: D:\JavaSpace\IO\from.txt, which needs to be opened in IO, such as the direct path is an error, there are two processing methods, as follows: d:\\javaspace/io/ From.txt

Java floating-point numbers follow the IEEE 754 standard, using the scientific notation of binary data to represent floating-point numbers. For float: The 1th digit is the sign bit, the next 8 digits represent the exponent, and then the 23 digits represent the mantissa, and the double is 1+11+52.

The imprecision of floating point numbers is widely existed. In the Java math package, there is a Bigdecmal class specifically designed to handle large precision data.

The BigDecimal class provides operations for arithmetic, scale manipulation, rounding, comparison, hashing, and format con Version. The ToString () method provides a canonical representation of a BigDecimal.

But by my own use, it seems not too much power ... It may be that I have not mastered the essence of it, a moment to turn an article to introduce a special introduction to this. Put on my test results:

Double A = 5.899989871234567890987654321;
System.out.println (a); Output Result: 5.899989871234568

BigDecimal bd = new BigDecimal (5.899989871234567890987654321);
SYSTEM.OUT.PRINTLN (BD);//output Result: 5.89998987123456775094609838561154901981353759765625

Mathcontext mc = new Mathcontext (28);
BigDecimal bd = new BigDecimal (5.899989871234567890987654321, MC);
SYSTEM.OUT.PRINTLN (BD);//output Result: 5.899989871234567750946098392

Look at the API a little try, or in vain, so Baidu looked under the other people's blog to understand that the original to use string as a parameter structure, in order to get the most accurate results, a moment alone.

十、三个 comparison of commonly used double constants:

Static double NaN
A constant holding a not-a-number (NaN) value of type Double.
Static double Negative_infinity
A constant holding the negative infinity of type double.
Static double Positive_infinity
A constant holding the positive infinity of type Double.

All positive infinity values are equal, and all negative infinity is equal, and Nan is not equal to any numeric value, even to Nan.

Only floating-point operations divided by 0 will get positive or negative infinity, and an integer type divided by 0 throws an exception.

0.0 divided by 0.0 or the sum of a negative number will get a non count.

Xi. after Java 7, new values are used to separate the underscore, eg:

int binval = 0b1000_0001;

Double d = 3.09_87_93;

Double height = 9_8_4_8.78;

12, Boolean type only true or False value, other basic data types cannot be converted to a Boolean type. The string "true" "false" is not converted directly to a Boolean type, but if you use a Boolean value and a string concatenation operation, the Boolean value is automatically translated to a string.



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.