Reputation: 391
I have created a HelloWorld.java file in Git Bash by
$vi HelloWorld.java
Then inserted the following:
class Hello {
public static void main (String[] arguments) {
System.out.println ("Hello, world!");
}
}
push esc and write :wq!
Then I tried to call the program.
$ls
HelloWorld.java
$javac HelloWorld.java
$ls
Hello.class HelloWorld.Java
$ java HelloWorld
Error: Could not find or load main class HelloWorld
Caused by: java.lang.ClassNotFoundException: HelloWorld
Can you help me?
Upvotes: 1
Views: 3831
Reputation: 1390
You need to fix few things:
Your main class should have public access modifier
public class Hello {}
Also file name and class name should match. So if your class name is Hello, your file should be named Hello.java
Upvotes: 5