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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "NULL" Watch "NULL" New topic
Author

NULL

Karu Raj
Ranch Hand

Joined: Aug 31, 2005
Posts: 479
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;
a.concat("abc");/////1
a.concat("def");/////2
System.out.println(a);
}
}
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: http://aspose.com/file-tools
 
subject: NULL