Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Basics Perfecting the Prototype Parsing Integers

Mayank Sapra
Mayank Sapra
4,555 Points

Why aren't we using the traditional way of printing the data on console using System.out.println(); functions ?

I self taught core java to myself and observed that the data or whatever we want to print on to console we do it using output stream System.out.println(); why aren't we displaying the output using output stream ?

2 Answers

I assume you are referring to the teachers use of the printf() method instead of println(). The reason is simple readability. Let's say I wanted to display text and include 3 variables which looked something like this:

System.out.println("My first variable is " + firstVar + " and then you get " + secondVar + " all while maintaining that " + third var +
" is also true.");
System.out.printf("My first variable is %s and then you get %s all while maintaining that %s is also true\n", firstVar, secondVar, 
thirdVar);

The printf command makes it look a lot nicer and simpler to read. There is nothing wrong with either one as they both work to do the same job. I myself only knew about the println until I began this course. If using variables, I now use the printf for simplicity.

Mayank Sapra
Mayank Sapra
4,555 Points

@Jeremiah Montano Thanks !! Since you have traversed a lot of java content here on teamtreehouse , what is your observation is the courseware sufficient enough to prepare for oracle certified professional Java exam ?

Leen Leenaerts
Leen Leenaerts
1,096 Points

You can do that too and you'll have to use it when you follow the Java course for a few minutes more than you did now ;)