This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
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

Win a copy of Elasticsearch in Action this week in the Big Data forum!
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.
I agree. Here's the link:
subject: NULL