0

How to do a null check? Like if its in a 'if' statement. Plus what data types do support null

is default constraint available in Java?

2nd Nov 2016, 12:25 PM
RaJat Thakur
RaJat Thakur - avatar
6 Réponses
0
if(myVar == null) { // Throw exception? set default value? etc. } // Your code _ All type that derives from the class object do. Primitives do not. here is the list with so background to them: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
3rd Nov 2016, 2:31 AM
Nicolas Dussault-Pilon
Nicolas Dussault-Pilon - avatar
0
does this work on a double?
3rd Nov 2016, 2:33 AM
RaJat Thakur
RaJat Thakur - avatar
0
doubles can't be null, their default value is 0 except that Double type allows nulls.
3rd Nov 2016, 2:35 AM
Nicolas Dussault-Pilon
Nicolas Dussault-Pilon - avatar
0
I'm making a simple interest calc. what to do if I want that if no value is entered in time field the default is 1?
3rd Nov 2016, 2:37 AM
RaJat Thakur
RaJat Thakur - avatar
0
Double myVar = get value from user if myVar equals null set myVar to 1
3rd Nov 2016, 2:47 AM
Nicolas Dussault-Pilon
Nicolas Dussault-Pilon - avatar
0
thanks dude!
3rd Nov 2016, 2:49 AM
RaJat Thakur
RaJat Thakur - avatar