Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use System.out.println() or something else?

I've been casually programming in Java for a while, but I still have a few burning questions on the fundamentals. I've heard that I should use System.out.println() to display data from some people, and others have given me different ideas (like PrintStream or something else). What's the best way to print to console in Java?

like image 207
Rafe Kettler Avatar asked Jul 23 '10 16:07

Rafe Kettler


2 Answers

If you are just starting and wanting to print some strings to the console then System.out.println() will be fine. Get your fundamentals down and then you can dive into the finer points of Java I/O.

like image 195
wshato Avatar answered Sep 27 '22 22:09

wshato


System.out is a PrintStream.

If your main goal is to interact with a console, look at java.io.Console. If your main goal is to have some kind of logging, use a logging framework like the Java Logging API or log4j.

like image 40
Mark Peters Avatar answered Sep 27 '22 23:09

Mark Peters