Home > Java > javaTutorial > What are the eight basic data types of Java?

What are the eight basic data types of Java?

coldplay.xixi
Release: 2020-06-16 14:15:26
Original
3140 people have browsed it

What are the eight basic data types of Java?

What are the eight basic data types of Java?

The eight basic data types of java are:

Since the release of Java, the basic data types have been part of the Java language, namely byte, short, int, long, char, float, double, boolean.

Among them:

Integer type: byte, short, int, long

Character type: char

Floating point type: float, double

Boolean type: boolean

Before going into details, let’s do some popular science. The smallest calculation unit in Java is a byte, 1 byte = 8 bits (bit) .

1. Integer type

Integer data in Java are signed numbers, that is, the first bit is 0, which means a positive integer. A bit of 1 represents a negative integer. In computers, negative numbers are represented by complements, so how are complements calculated?

Complement code = source code negation 1;

For example:

22, represented in the computer as 00010110,

-22, negation: 11101001, plus 1: 11101010

byte

byte is an integer type in Java, with a length of 1 byte and 8 bits, and a value of 10000000 (-128) to 01111111 ( 127), the default value of variable initialization is 0, the packaging class Byte

short

short belongs to the integer type in Java, the length is 2 bytes 16bit, and the value is 10000000 00000000 (-32768) to 01111111 11111111 (32767), the default value of variable initialization is 0, the packaging class Short

int

int belongs to the integer type in Java, the length It is 4 bytes and 32bit, with values ​​ranging from -2^31 (-2,147,483,648) to 2^31-1 (2,147,483,647). The default value of variable initialization is 0. The packaging class Integer

long

long is an integer type in Java, with a length of 8 bytes and 64 bits, ranging from -2^63 (-9,223,372,036,854,775,808) to 2^63-1 (9,223,372,036,854,775,8087). The default value of variable initialization is 0 or 0L, packaging class Long

2. Floating point type

Floating point data in Java cannot be directly represented by binary, but is an approximate data representation of real numbers. Method, it follows the IEEE 754 standard

float

float belongs to the floating point type in Java, also called single-precision floating point type, with a length of 4 bytes and 32 bits. The default variable initialization value is 0.0f. The wrapper class Float

float structure contains three parts: sign bit, exponent bit, and mantissa bit

double

double belongs to the floating point type in Java, also called double precision floating point type, with a length of 8 bytes and 64 bits. The default variable initialization value is 0.0d. The packaging class Double

double structure contains three parts: sign bit , exponent bit, mantissa bit

3. Character type

char

char belongs to the characters in java type, occupies 2 bytes and 16 bits, can be assigned single characters and integer values, there is no default value for variable initialization, and the packaging class is Character.

For example:

char a = 'a';

char a = '中';

char a = 12; // The value range is 0~65536, because the char type has corresponding values ​​in the ASCII character encoding, and can be directly operated and output the corresponding characters in the character table

4. Boolean

boolean

The JVM does not provide boolean-specific bytecode instructions, and the boolean type After compilation, the data will be represented by the int type in the JVM. At this time, the boolean data is 4 bytes and 32 bits, and the boolean array will be encoded into a byte array of the Java virtual machine. At this time, each boolean data occupies 1 byte. 8bit.

There are only two values, true and false, and the default value of variable initialization is false

Recommended tutorial: "java video tutorial"

The above is the detailed content of What are the eight basic data types of Java?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template