Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the default values for data types in Java? [duplicate]

Tags:

java

primitive

I am very new to Java having always issue with data types. So what are the default values for all data types in Java?

like image 422
Dhiraj Kumar Avatar asked Nov 29 '22 09:11

Dhiraj Kumar


2 Answers

byte        0
short       0
int         0
long        0
float       0.0f
double      0.0d
char        '\u0000'
boolean     false
like image 175
chamina Avatar answered Dec 04 '22 13:12

chamina


http://javaignite.com/post/66/default-values-for-primitives-in-java

primitives dont have null value. default have for an int is 0.

if(person.getId()==0){}

Default values for primitives in java:

Data Type Default Value (for fields)

byte                0
short               0
int                 0
long                0L
float               0.0f
double              0.0d
char               '\u0000'
boolean             false

Objects have null as default value.

like image 37
Dhiraj Thakur Avatar answered Dec 04 '22 13:12

Dhiraj Thakur