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 Syntax

In Console ob=System.console(); what is the use of that console with capital C (Console)

2 Answers

All of what Raaji said is correct, but here's a more basic explanation of the line of code in question in case it's helpful:

This line of code creates a new object reference - like giving it a name. Console is the type of object. "ob" is the name/reference. And System. console() is a method that returns a Console object - the object to which the new name will refer.

Here are some "real life" analogies...

If a boy just got a new puppy and named it Spot, the naming would look like this in code:

Puppy spot = new Puppy();

However, getting a dog from a neighbor who is moving away and renaming it would look more like this:

Dog sandy = Neighbor.giveDog();

Kinda looks like the Console line, right?

The Capital C Console is a predefined class in the java.io.Console library. So we need to import the java.io.Console library to use the Console objects and the methods of the Console class. Please check https://docs.oracle.com/javase/7/docs/api/java/io/Console.html