views:

227

answers:

7

Hello everyone, I'm new to JAVA and I'm currently trying out both Netbeans and Eclipse.

I'm confused about inputting values to my JAVA application.I see the output getting displayed on the output window in Eclipse ...but,I don't know how to input values ...??

In a normal console application in .Net,we can input values through the console window (Command Prompt Window) ,but I don't see any command prompt window coming up when I run my JAVA program to Input values or Type Anything.How do I do this?

Thanks.

+1  A: 

Using eclipse, you need to update the Run Configuration for a given Class. Provide any arguments you want to pass into the main method.

yankee2905
+2  A: 

In netbeans there is an output window that behaves like a console. That is, if your program requests keyboard input you can type directly in the output window.

Vincent Ramdhanie
+3  A: 

If I remember correctly, you can actually type in Eclipse's Java console and that will be sent through the standard input stream, System.in (probably depending on the application's run configuration).

However the standard way of doing this is to pass a number of strings on the command line, which will appear as the elements of the String[] parameter to your application's main method.

Alternatively you can get input in via flat files, from a database, through sockets etc. though this is, as you might expect, a lot more complex and should certainly not be considered for a "Hello World" type application. Java web services, for example, do take their input via network sockets rather than via the command line as this latter would restrict them somewhat. ;-)

Andrzej Doyle
+2  A: 

You can use two ways.

1) The first is from the console.

System.out.println("Please give number");
Scanner s = new Scanner(System.in);
int number = s.nextInt(); // Or s.nextString() to get the string.
System.out.println("You typed " + number);

2) The second is to show a dialog

String input = JOptionPane.showInputDialog("Please give number");

Hope this helps.

Martijn Courteaux
A: 

You can type in the same space where you see output (it's lake windows console but withe and embedded into IDE).

Also You can run your APP form console: java ClassName

Maciek Sawicki
+1  A: 

In Eclipse, you just type in the console where you get the results (e.g. System.out.println(...)). Your text will be colored in green.

True Soft
A: 

Use System.console() in Java 6.

snowstalker