zerkms
zerkms

Reputation: 255155

Java "Hello World" program running issue

I've trying to start learning Java and already in stuck with the easiest possible program (http://introcs.cs.princeton.edu/java/11hello/)

So I created HelloWorld.java with

public class HelloWorld { 
   public static void main(String[] args) { 
      System.out.println("Hello, World");
   }
}

Compiled it with D:\tmp\java>javac HelloWorld.java (all passed fine, without errors)

And tried to run compiled .class:

D:\tmp\java>java HelloWorld.class
Error: Could not find or load main class HelloWorld.class

I have

D:\tmp\java>javac -version
javac 1.7.0

and cannot get why such trivial example doesn't work :-S

Upvotes: 2

Views: 1215

Answers (3)

K.VENKATESAN
K.VENKATESAN

Reputation: 1

many instance we forgot to close and reopen the command prompt after editing the environement varriable . 1. In the environement varriable -create system variable called JAVA_HOME set the JAVA_HOME value upto bin folder of your JAVA directory 'C:\Program Files\Java\jdk1.7.0_04\bin'.3.Edit path in the system variable and add ';%JAVA_HOME%'. 4. close the control panel and close the command prompt and reopen and compile and run.donot bother about class path.

you can test the functioning by typing javac

For the first time create file helloworld.java the folder c:\users\documents\helloworld.java in note pad and type the following

class helloworld 
{

public static void main(String [] args )
 {
System.out.println("Welcome Helloworld");
 }
}

after saving click command prompt and type

for compiling c:\users\documents\ javac helloworld.java

for running c:\users\documents\ java helloworld

Upvotes: 0

Perception
Perception

Reputation: 80598

Remove the .class when running the program.

java HelloWorld

Good luck on your coding journey!

Upvotes: 3

Crozin
Crozin

Reputation: 44406

You should run it as java HelloWorld (without .class extension).

Upvotes: 7

Related Questions