1
public class Main {
    public static void main(String[] args) {
        //Set your print into the console
        System.out.println("Hello World");
    }
}

I have tried executing the program through command prompt(cmd.exe), yet it keeps on bringing errors as its output.

I expected to get hello World, but I get:

Error: could not find or load main class MyClass.java
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Donfortune
  • 11
  • 2

1 Answers1

0

Since you gave little to no information it's hard to tell where the error is.

Here's the code which would print 'Hello World'

public class Main {
    //Class name is irrelevent, but it must be the same as the filename

    //Define a main method, it HAS to be public, static and called 'main' and should     
    //receive a String array and return void (just copy the next row)
    public static void main(String[] args) {
        //Set your print into the console
        System.out.println("Hello World");
    }

}

Now compile your file by typing in the terminal:

javac <the path to your .java file>

And then:

java <classname (here Main)>

Jakob Herk
  • 157
  • 11
VoroX
  • 237
  • 1
  • 11