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

2

4

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

Stonyhearted answered 24/5, 2017 at 6:54 Comment(1)
1st link suggested by a google search: docs.oracle.com/javase/tutorial/java/nutsandbolts/…Meadowsweet
Q
17
byte        0
short       0
int         0
long        0
float       0.0f
double      0.0d
char        '\u0000'
boolean     false
Quire answered 24/5, 2017 at 7:1 Comment(0)
E
9

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.

Entangle answered 24/5, 2017 at 6:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.