|
|
|
|
|
How to Pass arguments from Command Prompt To Javapublic static void main (Sring[] args)AP Computer Science Class | AB AP computer Science Class | Mastering the Class Path|How to run a class from the command prompt | how to create a runnable Jar file
This example assumes that you are comfortable using the windows command prompt as well as how compiling and running basic java files.
First, use javac to compile the java class below.
public class Arg{
public static void main(String[] args){
System.out.println(args[0]);
}
}
Example 2. Changing the Class and Parameters
So, what if you don't want to print out the first argument in the command prompt?
First, let's recompile Hi.java so that it prints the second argument that is passed,ie args[1].
public static void main(String[] args){
System.out.println(args[1]);
}
Top |