javacmd

Compiling Java in Cmd and Running it


When I try to run compiled .class java program with this command

java main.class

I get this error

Error: Could not find or load main class main.class

When I compile the program with

javac main.java

It compiles nicely with no errors and gives me a .class file

What am I doing wrong?

I tried editing system variables to no avail.


Solution

  • You may simply write this to run the program:-

    java main
    

    Remove the .class