File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes PrintWriter write() and println() method query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "PrintWriter write() and println() method query" Watch "PrintWriter write() and println() method query" New topic
Author

PrintWriter write() and println() method query

Abhay Agarwal
Ranch Hand

Joined: Feb 29, 2008
Posts: 1220
    
    1

Just realized that PrintWriter has both write() and println() method.
Any idea what is the difference between them and which function to use when ?



Oracle Java Web Service Developer (1z0-897), Oracle certified Java 7 Programmer, SCJA 1.0, SCJP 5.0, SCWCD 5.0, Oracle SQL Fundamentals I, CIW Certified Ecommerce specialist
Shwetha Sharma
Ranch Hand

Joined: Jun 01, 2008
Posts: 34

PrintWriter.println(String)
This method prints null if the argument passed to it is null.

PrintWriter.write(String)
This method throws a null pointer exception if the argument is null.

Apart from this it works the same as the write method except that it appends "\n" to the string argument.

Also the println method throws IOException while the PrintWriter.write doesn't throw IOException

SCJP6:80%, OCWCD 88 %
Abhay Agarwal
Ranch Hand

Joined: Feb 29, 2008
Posts: 1220
    
    1

Thanks for the reply
Understood
praneeth ram
Ranch Hand

Joined: Sep 21, 2009
Posts: 60
why we can use write() method in the case of AJAX why not println() method.
could you please explain it.

Thanks,
Praneeth.
SCJP,SCWCD.OCP.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: PrintWriter write() and println() method query