Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects (Retired) Delivering the MVP Validation

Trudy Lee
Trudy Lee
2,812 Points

No need to import Character? Importing isn't better than just using?

1) The some previous class, I learned about import, import java.io.Console on the top in Prompter.java. But what I couldn't catch is... why do we need to import Console? I thinks there is some different point that I can't catch. "import java.io.Console" VS "import java.lang.Character"

2) <Prompter.java> : the practice code import java.io.Console; Console console = System.console();

With the practice code, I imagined like below.

<Game.java> import java.lang.Character; Character character = new Character();

or (just) Character character = new Character();

which one is correct?

3) if we import Character on the top in Game.java, we don't need to use "Character".isLetter We can just use isLetter.

Just want to know why he didn't import? Does it has any convention to import?

1 Answer

Seth Kroger
Seth Kroger
56,405 Points

java.lang is a special package that contains classes that are core to the Java language and all classes in it are automatically imported. Importing them yourself is redundant.