computerprogram
computerprogram

Reputation: 31

How to compile and run a Java program with arguments

I'm trying to write a java program which takes in input from the command line but for some reason I keep getting this message;

public class Class {
  public static void main(String[] args) {
    String s = args[0];
  }
}

Literally trying to just run the above program for now, and once I can get the input working I can build upon the program to complete my h/w assignment.

I keep getting this message when trying to compile in terminal:

error: Class names, 'test', are only accepted if annotation processing is explicitly requested

Also, this is what I'm writing in terminal javac Filename.java test

sometimes I also use "" so I write javac Filename.java "test"

However, I get the same error. I've found other questions who get the same error but the answer seems to be to add a .java when compiling - but I'm already doing this?

Upvotes: 0

Views: 1851

Answers (1)

Dmitrii B
Dmitrii B

Reputation: 2860

You add the word "test" in the compilation command javac. Try to put javac Filename.java without args and with them when you run your programmjava Filename command.

Upvotes: 2

Related Questions