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 trialPhilip Schultz
11,437 PointsWhy do we use "console".
Why are we using console.printf("");. and not system.out.printf("");. What is the difference between the two and what will I be using the most?
1 Answer
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 PointsHey there Phillip, the console does have some benefits, you can read input from users that is pretty difficult to do in the System class without some rigging, (most people just import another class like Scanner for this) Console is good because for interactive console environments, like the repl, it combines all the features of a scanner or BufferedReader. Essentially a console is more beginner friendly, but you'll notice that you outgrow it the more you work on your own projects, in fact they're a pain to set up in IDE environments.
Console will slowly become that cool awkward friend that you used to know when you dive into your own thing with java, we miss him.
There's no real big different between console.printf() and System.out.printf()
Thanks, hope this helps. Shout if it doesn't.
Philip Schultz
11,437 PointsPhilip Schultz
11,437 PointsThank you for the response Rob. Could you please explain how and why they work. when I say console or system am i calling a method from a library or something. I tried to use the console demand on NetBeans but it would not work. Thanks Rob.
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 PointsRob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 PointsHey Phillip both Console and System are classes in java. Which means that they're already built in the background, it's the same thing with Strings, they're pre built into the JDK source code that we download.
With that being said when you call one of these like System.out.println() that method is already built into java to know to print whatever is passed in as the argument to the internal console inside the IDE or whichever development environment you might be using.
As far as being able to use console in IDE's they take a lot of time to set up, as the IDE's usually have their own internal console, it's easier to use a class like Scanner to import one if you need to get user information.
I've included some impromptu code below to show how to import a scanner into your environment, and how to use like a console object.
This would catch whatever input the user put for "name" and pass that value into name, you'll notice that we have to use both System.out.println to set up the variables, in IDE environments you unfortunately have to use both, as consoles really don't work in an IDE environment.
For the next step, let's way you wanted to get an int
Thanks, sorry if I threw too much information than what was asked for.