title: Java Program execution in cmd without using set path or system variables
body: <p>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 <strong>D:\My_Programs</strong>  and the java executable files are in <strong>C:\Program Files\Java\jdk1.6.0_24\bin</strong>. Here's what I did to compile:
  <strong>C:\Program Files\Java\jdk1.6.0_24\bin>javac D:\My_Programs\HelloWorld.java</strong> It is creating a .class file but the same strategy for execution creates an exception: 
  <strong>C:\Program Files\Java\jdk1.6.0_24\bin>java D:\My_Programs\HelloWorld</strong></p>
  
  <pre><code>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.
  </code></pre>
  
  <p>Can someone suggest on how to <em>execute this file</em>.
  Thanks in advance for your help.</p>
  
  <p>The code:</p>
  
  <pre><code>class HelloWorld {
      public static void main(String[] args) {
          System.out.println("Hello World!");
      }
  }
  </code></pre>