Initialization and default values in JAVA, wrapper classes and basic types

When a variable is used as a class member, java ensures that its initial value is given , preventing program runtime errors

type of data initial value
byte 0
short 0
int 0
long 0L
char 'u0000'
float 0.0f
double 0
boolean false
All reference types null

The wrapper classes of primitive data types are all reference types

basic type

size (bytes)

Defaults

Package class

byte

1

(byte)0

Byte

short

2

(short)0

Short

int

4

0

Integer

long

8

0L

Long

float

4

0.0f

Float

double

8

0.0d

Double

boolean

-

false

Boolean

char

2

\ u0000 (null)

Character

If one side is a wrapper class and the other side is a basic type; or if the comparators such as <, >, <= are used, value comparison will be performed; if it finds that both sides of == are objects, it will directly compare references instead of values.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325191095&siteId=291194637