I'm trying to execute a simple java program ("HelloWorld") in command prompt without using the set path option or setting the system variable. Suppose the java program is in D:\My_Programs and the java executable files are in C:\Program Files\Java\jdk1.6.0_24\bin. Here's what I did to compile: C:\Program Files\Java\jdk1.6.0_24\bin>javac D:\My_Programs\HelloWorld.java It is creating a .class file but the same strategy for execution creates an exception: C:\Program Files\Java\jdk1.6.0_24\bin>java D:\My_Programs\HelloWorld
Exception in thread "main" java.lang.NoClassDefFoundError: D:\My_Programs\HelloW
orld
Caused by: java.lang.ClassNotFoundException: D:\My_Programs\HelloWorld
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: D:\My_Programs\HelloWorld. Program will exit.
Can someone suggest on how to execute this file. Thanks in advance for your help.
The code:
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
javaandjavacbinaries is irrelevant once they're on your PATH. Show us the Java code inHelloWorld.java.