-3

I got this error messaje while trying to copile a simple Java program. I know there is this question already here on Stack but the solution(that i forgot to include the .java suffixwhen compiling the program) still doesn't work for me. This is the program:

import java.io.Console;

    public class Introductions {

        public static void main(String[] args) {
            Console console = System.console();
            // Welcome to the Introductions program!  Your code goes below here
            String firstName = "Paul";
            console.printf("Hello, my name is %s\n", firstName);
            console.printf("%s this is learning how to write Java\n", firstName);
      }
    }
PaulP1
  • 125
  • 1
  • 7

1 Answers1

2

There are two different commands to compile Java programs and run Java programs. You're receiving an error that means that the command to compile the program (javac) has received arguments that don't include the .java suffix, as mentioned in other questions about this error.

It sounds, however, like you are compiling correctly, using javac Introductions.java. Your problem is actually in the second step, running the program. Running javac Introductions tells Java you want to compile again, and so it correctly points out that you forgot the extension.

But you're not wanting to compile a second time; you want to run it! That uses java instead of javac.

To compile: javac Introductions.java

To run: java Introductions

See also How do I run a Java program from the command line on Windows? (though this isn't really Windows-specific).

ojchase
  • 1,041
  • 1
  • 10
  • 22