Roman Roman - 1 year ago 74
Java Question

I have managed to compile java-program but I cannot execute it

I have just installed JDK on Windows Vista. After that I set proper values for the 4 environment variables: classpath, include, lib, path. After that I was able to compile my HelloWorld-program (I got a *.class file). But when I try to execute the compiled program (I type java HelloWorldApp) it does not work. The Java write a lot of stuff and in the end it is written that it "could not find the main class: HelloWorldApp". Can anybody, pleas, help me with this problem?

Answer Source
  1. create a file called;
  2. paste the code posted below inside
  3. compile it by executing the command: javac in the same folder as is in;
  4. execute the code by doing: java -cp . HelloWorld in the same folder as is in.

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("HelloWorld works!");

How the classpath works, can be read here:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download