Java basic type

Source: Internet
Author: User

I have been studying Java for some years, but I am deeply impressed by the basic knowledge of Java, Java Oo, and Java APIs, which are also called core Java, never dare to relax their repeated learning and refining. In addition, it turns out that more programming methods have been realized through the gradual accumulation and deep learning of them, and the programming capability is also growing step by step. Even when you switch to other languages, applying the corresponding routines will get twice the result with half the effort (however, it is also crucial to catch the difference between different languages and avoid a lot of detours ).

Recently, I decided to repeat core Java and hope to find the missing parts and give a clearer picture. First read the book from thin to thick, and then read the book from thick to thin! (In other words, there is no thin book on the computer, and there is no sweat.) I don't plan to post all the content in a large space, I just want to use my blog to record some important points that need to be paid attention to at any time for myself to share with you.

Let's get down to the truth and give a brick to introduce a piece of jade. Let's first introduce a basic Java type. Maybe you think this is the simplest concept in Java. In fact, it may not be clear to everyone, and can be used very well.

Java integer

Int 4 bytes -2147483648 ~ 2147483647 (more than 2 billion)
Short 2 bytes -32768 ~ 32767
Long 8 bytes -9223372036854775808 ~ 9223372036854774807
Byte 1 byte -128 ~ 127

Floating Point Type

Float 4 bytes About ± 3. 40282425e + 38f (6-7 digits)
Double 8 bytes About ± 1. 79769313486231570e + 308 (the valid digits are 15 digits)


1if (x
= Double. Nan)
// Is never true

1if (double. isnan (x ))
// Check whether is "not a number"

Floating point values are not suitable for financial calculation that prevents rounding errors. For example, system. Out. println (2.0-1.1); will print 0.899999999999999 instead of 0.9. Because floating point values are represented by binary systems, while binary systems cannot accurately represent the score of 1/10, just as decimal systems cannot accurately represent 1/3. If there is no rounding error in numerical calculation, use the bigdecimal class.

Char type

In Java, the char type describes a unit of code with UTF-16 encoding. We strongly recommend that you do not use char in the program.

Boolean Type

In C or C ++, a value or pointer can replace the Boolean value. 0 is equivalent to flase, not 0 is equivalent to true, but not in Java, and an error is reported during compilation.

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