Problem statement: what do you mean by null & NullPointerException?
System.out.println(s); // valid
System.out.println((String)null); // valid
8. For any object reference r,
r == null is always false
but null == null is always true
9. for any object reference r,
r.equals(null) is always false
10. null vs NULL vs String s ="";
null & empty both are not same.
there is no concept like NULL in java
11. If an object is no longer required then we can make that object eligible for Garbage Collector by assigning null to all its reference variables.
Student s1 = new Student();
s1 = null;
Now object is eligible for GC
12. In java there are total 53 reserved word out of them 50's are keyword and 3's are reserved literal[true, false, null]
[a]-if reserved words are associated with functionality then it will keyword. e.g. if()...
[b]-if reserved words are just to represent the value then such reserved words are called reserved literals like true, false, null
- null:
- null is reserved literal but not keyword in java [literal mean any constant value that can be assigned to a variable]
- we can use null for any object reference variable
- if the value of reference variable null means it is not pointing to any object
- null is applicable to only for Object types but not for Primitive Type if we are trying to use for the primitive data types then we will get Compile Time Error
- null is default value for reference variable [note: make sure you should remember default values concept is applicable only for Instance & Static Variables but not for Local Variable]
- System.out.println(null); Compile error - reference to println is ambiguous
System.out.println(s); // valid
System.out.println((String)null); // valid
- NullPointerException:
8. For any object reference r,
r == null is always false
but null == null is always true
9. for any object reference r,
r.equals(null) is always false
10. null vs NULL vs String s ="";
null & empty both are not same.
there is no concept like NULL in java
11. If an object is no longer required then we can make that object eligible for Garbage Collector by assigning null to all its reference variables.
Student s1 = new Student();
s1 = null;
Now object is eligible for GC
12. In java there are total 53 reserved word out of them 50's are keyword and 3's are reserved literal[true, false, null]
[a]-if reserved words are associated with functionality then it will keyword. e.g. if()...
[b]-if reserved words are just to represent the value then such reserved words are called reserved literals like true, false, null
No comments:
Post a Comment