Im using fedora 19. Content of HelloWorld.java :
    class HelloWorld {
        public static void main( String args[] ) {
            System.out.println( "Hello World!!" );
        }
    }
I can successfully compile it using
javac HelloWorld.java
But i cannot run it using
java HelloWorld
It gives the following error
Error: Could not find or load main class HelloWorld
But i can run it using
sudo java HelloWorld
What am I missing here???
You are not setting a classpath that includes your compiled class! java can't find any classes if you don't tell it where to look.
Try java -cp . HelloWorld
Source here
Not sure why it works with sudo though. My* guess would be, that the CLASSPATH is set for the root user and not for the current user.
Dear Pranav Chugh,
1- cmd - go the directory of located java file
run the following on cmd
2- javac HelloWorld.java 
3- java HelloWorld             ---- not not add .class
here you will get the result
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With