If you are making a console based program, you may need to have some arguments passed to it. Below is a simple example of how to do this!
Any values passed to your Java class/program get put into an array specified in your 'main' class, in the example below it is the 'args' array. Unlike some languages such as Go, the first element in the array is the first item passed to the program. Click following to find out more about Java Arrays and how to access them!
With the Java JDK installed, from a command line:
If you do not have Java JDK installed, click the following link to find out how to install Java on your computer!
class Hello{
public static void main(String[] args){
// Check if we have passed any arguments
if (args.length>0){
for(var name:args){
System.out.println("Hello "+name+"!");
}
}else{
System.out.println("Where is everyone?");
}
}
}
Updated (26/08/2026)