• Register
3,890 points
11 5 1
Welcome to Kodlogs, programming questions and answer website.

Java is a language that forces the programmers to create variables referencing null. Any variable that is declared but left uninitialized will automatically be referenced as null.  The other Java language constructs like try/catch force the variables to be declared in the outer scope where null is the only valid choice.

Types of Null:

Null is not an object neither it is a type. It is a special value that can be assigned to any reference type and The user can case null to any other type.

// null can be assigned to String

    String str = null;   

    // you can assign null to Integer also

    Integer itr = null;   

    // null can also be assigned to Double

    Double dbl = null;

    // null can be typecast to String

    String myStr = (String) null;

    // it can also be type cast to Integer

    Integer myItr = (Integer) null;

   // yes it's possible, no error

    Double myDbl = (Double) null;

Java check for null:

An int is not null. It can be zero if left uninitialized. If you want an integer to be able to null, then you have to use Integer instead of int.

Integer id;

String name;

public Integer getId() {

return id;



3,890 points
11 5 1