Enter your E-mail Address below for Free E-mail Alerts right Into your Inbox: -

Tuesday

NullPointerException in java and What is null in java java.lang.NullPointerException

NullPointerException(java.lang.NullPointerException) is the one that each and every java programmer got trouble while coding. The reason is if null is not handled correctly in java, it will leads to serious trouble.
        So every java developer must aware of NullPointerException in java and how to avoid the nasty issues.Many of the java applications spend much effort to handle NullPointerException. Clients, team and firm every one likes robust programming.So first you should understand what is NULL in java.

Facts about NULL in Java:

  1. null is the keyword used and it's case-sensitive. you can't use Null or NULL. eg: String[] str = null;
  2. without initializing variables and other are default as null. eg:- String[] str; System.out.println(str); output:- null.
  3. null is not a type or Object. It can be TypeCasted.
  4. null can't be applied to primitive type,used along with wrapper type.eg:- int a = null//wrong. Integer b = null//correct
  5. instanceof operator will return false if used against any reference variable with null value or null eg:- Integer a = null; if(a instanceof Integer) System.out.println("true");else System.out.println("false"); output:- false.
  6. static method can be called by null object refernce.non-static cannot be called.
  7. You can use "==" or "!=" for comparing null but can't use other operators.

No comments:

Post a Comment