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 For Each

yvesramos
yvesramos
12,816 Points

Console console = example

Hi, it might be the wrong place to ask but here in Feeling Loopy is where I notice. Here is my question, what's the reason of using Console console = example, or why we use it and how and when do we use it? I am new at JAVA and I would like to be an expert in the future so it might be a simple code but I would like to learn not matter how simple or hard it's the code. Thanks in advanced.

1 Answer

It's the same concept as creating a new object from a class.

Example example = new Example();

The capitalized first word is the object being created/modified (In your question it's the Console, in the above class example it'd be the project class Example()). The camelCase second word is variable that object belongs to and can be anything you choose, and after the equals sign is the action taking place (creating a new Example() or casting System.console() to console). The point is you select the Console by writing console(or whatever word you choose) followed by a dot and the method you wish to use. Another example of doing the same thing as what's being done in the video

Console terminal = System.console();
terminal.printf("Jack's son is %s", jacksSon);