It's not a secret anymore!
The moose likes Beginning Java and the fly likes Input in Java, Simplest way Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Input in Java, Simplest way" Watch "Input in Java, Simplest way" New topic

Input in Java, Simplest way

Shashank Mittal

Joined: Nov 30, 2009
Posts: 9
Its surprising that after reading almost the whole book, . . . Guys Is there any simplest way to get the input in java, such that I can add 2 strings, numbers by taking command line input from user.
There is only one way I know,
BufferedReader br = new BufferedReader(new InputStreamReader(;

This clicks me as somewhat odd way of taking input. Guys I have recently moved from C/C++ to Java, and I was expecting the input taking mechanism to be butterly simple, but the above statement horrified me badly. We learn in 2-3rd chapter in C/C++ "How to take input" and in Java why is it such lately introduced in almost all the books?


Lord don't move that mountain, Give me the strength to climb it.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

There are millions of ways of getting input. For input from the command line you could use the commandline arguments (main(String[] args), your approach but I would recommend you to look at the Console class which was introduced in java 6.
1 trapdoor: not all environments can supply a Console, for instance the Netbeans IDE.

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1789

I'm a Scanner addict myself.... I find it's pretty easy. Here's the API.


When you do things right, people won't be sure you've done anything at all.
Shashank Mittal

Joined: Nov 30, 2009
Posts: 9
Thanks for replies man, but in general Java books, why they are covered way after traversal of key concepts, thats still unknown to my limited intelligence.
thanks again, scanner one is really a cool one!
I agree. Here's the link:
subject: Input in Java, Simplest way
It's not a secret anymore!