Question:
How do I run my Java program from the command prompt with a parameter?
hanesjw
2007-05-21 14:53:07 UTC
Lets say my java program is called "Yay.java", I know if I type in "java Yay.java" it runs correctly. But I want a parameter added to it such as "java yay.java p1". How do I set this up in my java program? The program should take a string as a parameter from the command prompt. (I'm using windows).
Three answers:
2007-05-21 14:59:20 UTC
public static void main(string[] args)



and args is a string array of the command line arguements, idk if java or the program name are in there, i beleive no
?
2016-11-26 03:56:43 UTC
definite, do no longer hear to those that says to apply the cmd. that's the twenty first century, there are lots of IDE compiler for Java obtainable and that's loose. If that's loose, than why worry utilizing cmd? An IDE will keep you somewhat some time and frustration in the long-term.
Brian P
2007-05-21 22:06:06 UTC
Compile the java source using:



javac Yay.java



Run the program using:



java Yay arg1 arg2 arg3


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...