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 Basics Using your New Tools Multiple Strings

User Input

What is the difference between getting user input with the Scanner object and Console.readLine ?

2 Answers

Did some quick researched and this was some helpful information I found

BufferedReader

Since Java 1.1
Throws checked exceptions
Can read chars, char arrays, and lines
Fast

Scanner

Since Java 1.5
Doesn't throw checked exceptions
Can read lines, whitespace-delimited tokens, regex-delimited tokens, and numbers
Difficult to read single characters

Console

Since Java 1.6
Doesn't throw checked exceptions
Can read lines
Underlying reader can read chars and char arrays (stops at line bounds)
Not always available (e.g. Eclipse)
Can read passwords (i.e. read without displaying the characters)
Recommendation: Scanner

The methods for reading numbers are very useful. The exceptions are unchecked, so you do not have to write boilerplate try/catch blocks.

A lot over my head as I just started with JAVA but helps. Thanks.

Well, for what I have seen they do pretty much the same thing, just with different synatx.

Short answer, but I hope that helps!

Thanks! :)