aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes NULL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "NULL" Watch "NULL" New topic


Karu Raj
Ranch Hand

Joined: Aug 31, 2005
Posts: 481
Here why it is throwing null point exception.
as we know that strings are immutable so there is no change in string a .
so why it is not printing null.

but if i remove /////1 and //////2 then it prints null.

How ?/

public class NULL

public static void main (String[] args)
String a = null;
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
In lines 1 and 2, you are trying to call a method on an object reference which is null.

If you take out those lines, you get the String representation of null.
It is sorta covered in the JavaRanch Style Guide.
subject: NULL