Summary of Java Basic data types

Source: Internet
Author: User

In this article, we discuss some of the most basic things about Java, these things we generally just learn Java when we learned, but not necessarily really understand. Exactly, I'm doing a read memory value that involves reading and writing the value of bit bit. Then you can discuss the details of a Java basic data type value in the machine:

There are eight kinds of Java basic data types: Character type char, Boolean type Boolean, and numeric type Byte, short, int, long, float, double. Numeric types can also be divided into integer types, byte, short, int, long, and floating-point number type float, double.

Java determines the size of each of the simple types. These sizes do not change as the machine structure changes. This immutable size is one of the reasons why Java programs have a strong ability to migrate.

Below, we are going to analyze the value range of the Java base data type and how many bytes (1 bytes = 8 bit) are taken.

The code is as follows:

public class basedatainfo{public static void Main (string[] args) {System.out.println ("Boolean.false:" +boolean.false);  System.out.println ("Boolean.true:" +boolean.true); int maxbyte = Byte.max_value;int Minbyte = byte.min_value;int sizebyte = byte.size; System.out.println ("Byte.max_value:" +maxbyte); System.out.println ("Byte.min_value:" +minbyte); System.out.println ("byte.size:" +sizebyte); int Maxchar = Character.max_value;int Minchar = Character.min_value;int Sizechar = character.size; System.out.println ("Character.max_value:" +maxchar); System.out.println ("Character.min_value:" +minchar); System.out.println ("character.size:" +sizechar); int maxshort = Short.max_value;int Minshort = Short.min_value;int Sizeshort = short.size; System.out.println ("Short.max_value:" +maxshort); System.out.println ("Short.min_value:" +minshort); System.out.println ("short.size:" +sizeshort); int maxInt = Integer.max_value;int Minint = Integer.min_value;int sizeint = Integer.size;int Bitcount = Integer.bitcount (10); System.out.println ("Integer.max_value:" +maxint); System.out.println ("Integer.min_value:" +minint); System.out.println ("integer.size:" +sizeint); System.out.println ("Integer.bitcount (1):" +bitcount); long Maxlong = Long.max_value;long Minlong = Long.min_value;int Sizelong = long.size; System.out.println ("Long.max_value:" +maxlong); System.out.println ("Long.min_value:" +minlong); System.out.println ("long.size:" +sizelong); float maxfloat = float.max_value;float minfloat = Float.min_value;int Sizefloat = float.size; System.out.println ("Float.max_value:" +maxfloat); System.out.println ("Float.min_value:" +minfloat); System.out.println ("float.size:" +sizefloat);D ouble maxdouble = double.max_value;double mindouble = double.min_value; int sizedouble = double.size; System.out.println ("Double.max_value:" +maxdouble); System.out.println ("Double.min_value:" +mindouble);  System.out.println ("double.size:" +sizedouble); }}

Output Result:Boolean.FALSE:false
Boolean.TRUE:true
byte.max_value:127
byte.min_value:-128
Byte.size:8
character.max_value:65535
character.min_value:0
Character.size:16
short.max_value:32767
short.min_value:-32768
Short.size:16
integer.max_value:2147483647
integer.min_value:-2147483648
Integer.size:32
Integer.bitcount (1): 2
long.max_value:9223372036854775807
long.min_value:-9223372036854775808
Long.size:64
Float.max_value:3.4028235e38
Float.min_value:1.4e-45
Float.size:32
double.max_value:1.7976931348623157e308
double.min_value:4.9e-324
Double.size:64

As you can see from the output:

Boolean

Only true and false two values

Byte

8 bits, the maximum amount of storage data is 255, the data range stored is between -128~127

Short

16 bits, maximum data storage is 65536, data range is -32768~32767

Int

32 bits, the maximum data storage capacity is 2 of 32 times minus 1, the data range is negative 2 of 31 to positive 2 square minus 31 (that is, -2147483648~2147483647). from the int range, int is suitable for shaping data at level 2 billion.

Long

64-bit, the maximum data storage capacity is 2 of 64 times minus 1, the data range is negative 2 of 63 to positive 2 square minus 63 (that is, -9223372036854775808~9223372036854775807). From the range of long, it can be seen that long is suitable for large-scale (billion-billion) of shaping data.

Float

32-bit, data range in 3.4e-45~1.4e38, direct assignment must be preceded by a number F or F. As can be seen from the value range of float, float is suitable for E38-level float data.

Double

64 bits, the data range is 4.9e-324~1.8e308, can be added D or D can not be added when the value is assigned. From the value range of double, it can be seen that double is suitable for e308 double data.

Char

16-bit, storing Unicode code, assigning values in single quotes



Basic data types

Boolean

Byte

Char

Short

Int

Long

Float

Double

Bit number of bits

1

8

16

16

32

64

32

64

Number of byte bits

0.125

1

2

2

4

8

4

8

Encapsulation class

Boolean

Byte

Character

Short

Integer

Long

Float

Double

Reference: Java basic Data Type summary
Http://www.cnblogs.com/doit8791/archive/2012/05/25/2517448.html

Summary of Java Basic data types

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.