File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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: 2398
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.
I agree. Here's the link:
subject: NULL
It's not a secret anymore!