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 Getting Started with Java IO

Tanveer Singh
Tanveer Singh
213 Points

What about System.out.println(""); for printing a statement. Why are we using console instead??

Why aren't we using System.out.println(""); for printing a statement. And scanner to take inputs??

1 Answer

andren
andren
28,558 Points

While I can't speak for Treehouse in any official capacity I imagine it was due to the fact that they wanted to keep the basics course as simple as possible. Having one object that can be used for both input and output and that also supports writing a message to the console when it prompts for input (which Scanner does not) makes things simpler.

As with most languages Java is pretty flexible and there are a ton of ways to do most stuff. Using System.out.* for printing and the Scanner class for input is certainly a valid approach, but so is using the console object.

The main disadvantage of the Console class which causes it to often not be used during teaching is that for various somewhat complex reasons it doesn't work if you run your code in a Java IDE like IntelliJ, Eclipse or something else along those lines. Due to the way that they run your code.

That is not an issue for Treehouse though since they do not use any IDE during the basic courses.

If you are used to using System.out.* and the Scanner class then you are certainly free to continue using them. Just be aware that for challenges within the Treehouse courses they will often expect you to use the console object. So your solution will likely be marked as wrong if you don't use that for those challenges.

Tanveer Singh
Tanveer Singh
213 Points

Thanks a lot.......!!!!!!!