File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes A println() peculiarity... Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "A println() peculiarity..." Watch "A println() peculiarity..." New topic
Author

A println() peculiarity...

Matthew Alesi
Ranch Hand

Joined: Sep 13, 2006
Posts: 38
Came across this problem writing a program for my Computer Science class. Reproduced here with simpler code:



All but the last call in main() work fine; the last throws a null pointer exception. What is the explanation for this seeming inconsistency?


-Matt
Current CS undergrad
SCJP 5.0
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 2912
You are effectively passing 'null' in the first 3 calls. In the last call you are passing an object, whose toString() is returning a null.
The println method checks if the passed object is null (not whether the passed object's toString() returns null), in which case it prints "null" without trying to call any method on it.


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: A println() peculiarity...
 
Similar Threads
inner class????
Reflection Problem
How to pass value from one file to anaother
calling another GUI class
Understanding Wait and Notify