Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a java program in cmd with arguments [duplicate]

Tags:

java

cmd

javac

This is a beginner question. I am trying to run a java program from cmd with arguments. This is my class:

public class Test{
    public static void main(String[] args){
        System.out.println("This is a test");
        System.out.println(args.length);
    }
}

I can run it without arguments successfully. How can I put for example 5 and 6 as arguments in my program?

All the other answers I found where just to run the program. I already know how to do that. I was not able to find how to run the program using arguments.

like image 427
Ioanna Katsanou Avatar asked Oct 28 '25 08:10

Ioanna Katsanou


1 Answers

java Test arg1 arg2 arg3 ...

or

java Test "arg1 arg2 arg3" ...

More details here Command-Line Arguments

like image 103
Berserk Avatar answered Oct 30 '25 14:10

Berserk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!