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 trialHan Wu
927 PointsConsole console = System.console
What is it?
2 Answers
Talmage Shill
Courses Plus Student 7,593 PointsBasically, that line of code gives you access to the console(command line interface). System.console() is a function that returns a console object. By saving it in a variable, you have access to the console throughout your code and only create one instance of the object (which saves memory).
The console is used to get information from the user and display information to the user. For example, you could make a simple calculator program that asks the user for a list of numbers and then display their average. Console is primarily used in applications without a Graphical user interface.
Console come from an external package provided by Java, but is not included by default. In order to get access to the Console you have to use
import java.io.Console;
This tells java you would like to use the console.
Let me know if there is anything else I can clarify
Talmage Shill
Courses Plus Student 7,593 PointsIm not totally sure what your looking for; however, It looks like you forgot your parenthesis at the end of System.console. Try this:
Console console = System.console();
Kevin Faust
15,353 Pointsthe question is what is "Console console = System.console();" like what is the use of this, where did this come from, why are we using it, etc.