Hi every one .. this is my first topic in fourms ...
My Question is how can I give an arguments for a code before it been executed ..
public static void main( String args[]) .. I mean here o give main args to use it in program like args[0] , args[1] ... etc
This could be executed in old Java when execute program , ex for class xyz:
c:\java\bin>java xyz "Hi" "localhost"
Thanks for your time
Using Args In Jcreator
Started by
WaNaBeWiThYoU
, Apr 29 2005 09:32 PM
8 replies to this topic
#1
Posted 29 April 2005 - 09:32 PM
#2
Posted 30 April 2005 - 04:04 AM
Here is how to do it:
1) Go to Configure >> Options.
2) In the option dialog, go to JDK Tools in the left panel.
3) For tool type, choose "Run Application" from the drop-down list, and then select <Default>.
4) Click Edit.
5) Go to the Parameters tab and select the check box "Prompt for main method arguments."
And now when you run your program, it will ask for parameters.
1) Go to Configure >> Options.
2) In the option dialog, go to JDK Tools in the left panel.
3) For tool type, choose "Run Application" from the drop-down list, and then select <Default>.
4) Click Edit.
5) Go to the Parameters tab and select the check box "Prompt for main method arguments."
And now when you run your program, it will ask for parameters.
#3
Posted 30 April 2005 - 04:02 PM
Will i want to make my question more specified ..
is this operation can happen only for one class .. without see the dialog of args in any other class
is this operation can happen only for one class .. without see the dialog of args in any other class
#4
Posted 01 May 2005 - 02:30 AM
It is for the main method only. What you specify here is the values in args[]. The rest of the program runs normally, no additional input is required.
#5
Posted 05 May 2005 - 10:46 AM
I have done this (it was clearly described in the help system too), but it has not worked.
I have re-compiled and then run the program, and it does not prompt for any arguments. I am using the LE (free) version, if this makes any difference.
I am running through an introductory course, and the prog I am currently writing is called NewRoot (a standard calculate the square root beginner app). I have tried setting the 'Run Application, Prompt for main method arguments' check box with a Name of NewRoot, and also NewRoot.class - neither worked for me.
Any ideas where I may be going wrong ?
Win XP and JCreator 3.50 LE (version 3.50.012)
The prog is :
class NewRoot {
public static void main (String[] arguments) {
int number = 0;
if (arguments.length > 0)
number = Integer.parseInt( arguments[0] );
System.out.println("The square root of " + number
+ " is " + Math.sqrt(number));
}
}
There is not something I'm missing here is there ?
Matt
I have re-compiled and then run the program, and it does not prompt for any arguments. I am using the LE (free) version, if this makes any difference.
I am running through an introductory course, and the prog I am currently writing is called NewRoot (a standard calculate the square root beginner app). I have tried setting the 'Run Application, Prompt for main method arguments' check box with a Name of NewRoot, and also NewRoot.class - neither worked for me.
Any ideas where I may be going wrong ?
Win XP and JCreator 3.50 LE (version 3.50.012)
The prog is :
class NewRoot {
public static void main (String[] arguments) {
int number = 0;
if (arguments.length > 0)
number = Integer.parseInt( arguments[0] );
System.out.println("The square root of " + number
+ " is " + Math.sqrt(number));
}
}
There is not something I'm missing here is there ?
Matt
#6
Posted 07 May 2005 - 05:03 PM
CODE
class NewRoot {
public static void main (String[] arguments) {
int number = 0;
if (arguments.length > 0)
number = Integer.parseInt( arguments[0] );
System.out.println("The square root of " + number
+ " is " + Math.sqrt(number));
}
}
the code is working with no problems but u seem that u don't send args b4 begining the execution of the program . does u ?
#7
Posted 11 May 2005 - 10:47 AM
Thanks for replying, but I couldn't understand the answer.
I believe that I should be able to bring up a prompt for arguments to pass to the program by setting the 'prompt for main method arguments' flag, but I am not getting any prompt. Are you saying that the code needs to be changed to look for an argument ? As I mentioned, I am working through course examples, and according to the course this should work. If this were in RPG I would have no problems, but this modern stuff is still a little bit of a mystery to me - hence the call for help.
Do I need to change the code, or should this work ?
Thanks for any help you can provide.
I believe that I should be able to bring up a prompt for arguments to pass to the program by setting the 'prompt for main method arguments' flag, but I am not getting any prompt. Are you saying that the code needs to be changed to look for an argument ? As I mentioned, I am working through course examples, and according to the course this should work. If this were in RPG I would have no problems, but this modern stuff is still a little bit of a mystery to me - hence the call for help.
Do I need to change the code, or should this work ?
Thanks for any help you can provide.
#9
Posted 11 May 2005 - 01:35 PM
Thanks for your help. I think I have found what I was doing wrong. I had not set up a project, and was working with 'external files'. I copied the source into a project. Initially it still would not work as expected, but did so once I had set the checkbox under the Toolbar's 'Execute' drop-down menu's configure section ! (Whew ... sorry about that sentence
)












