IntelliJ Java IDE
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
Register / Login
JavaRanch » Java Forums » Professional Certification » Web Component Certification (SCWCD/OCPJWCD)
Reply 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: 655
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 certified Java 7 Programmer, SCJA 1.0, SCJP 5.0, SCWCD 5.0, Oracle SQL Fundamentals I
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: 655
Thanks for the reply
Understood
praneeth ram
Ranch Hand

Joined: Sep 21, 2009
Posts: 56
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.
 
 
subject: PrintWriter write() and println() method query
 
Threads others viewed
QuizCard txt file - newline missing
PrintWriter And ServletOutputStream API Doubt
println() to a PrintWriter and write() to a ServletOutputStream()
PrintWriter and OutputStream
difference between PrintWriter.println and PrintWriter.write
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture