8 basic types in Java

Java is a strongly typed language, which means that every variable must declare a type.

Before we talk about variables, we must first talk about the types of variables.

In Java, variable types are divided into two categories: basic types and reference types.

Type classification of variables in Java
Variable type
basic type Reference type
8 types Except for the 8 basic types, all other variable types are reference types

Java supports the basic variable types in 8.

Basic type information table of variables in Java
type name

size of space

(Unit: byte or bytes)

Representation range
byte (byte type) 1 -2^{7}\sim 2^{7}-1
short (short integer) 2 -2^{15} \sim 2^{15}-1
int (integer) 4 -2^{31} \sim 2^{31}-1
long (long integer) 8 -2^{63} \sim 2^{63}-1
float (single precision floating point type) 4

                  about\large \pm 3.40282347E+38F

      (The effective number of digits is 6~7)

double (double-precision floating-point type) 8

                   about\large \pm 1.79769313486231570E+308

        (The effective number of digits is 15)

char (character type) 2 0 \sim 2^{16}-1
boolean (Boolean)   true,false

Among them, byte, short, int, long are the basic types that represent integers;

Float, double are the basic types that represent real numbers with decimals;

Char is the type that represents a character. Characters in Java are encoded in Unicode and are two bytes (2 bytes, 16 bits) long;

boolean is a type that indicates that the truth value is correct or incorrect.

 

tips: These 8 types can be selected reasonably according to the form of the data in the program.


 

Guess you like

Origin blog.csdn.net/PursueLuo/article/details/81952845