no java programs are running although programs geting complied

im new to java just intalled JDK 1.6

following thing

rightclick my comp->advanced->envoirnment variables

CLASSPATH-> edit C:\Program Files\Java\jdk1.6.0_01\jre\lib\rt.jar

new

JAVA_HOME->C:\Program Files\Java\jdk1.6.0_01

then i saved my file in C:\Program Files\Java\jdk1.6.0_01\bin

so file got compiled and a class file hello.class was created

but on running it using java hello it was giving error that main

exception in thread "main" java.lang.noclassdefinationfounderror:hello

wat to do?

[569 byte] By [amit_garga] at [2007-11-27 8:40:04]
# 1

that means you dont have a main method.

class HelloWorld {

public static void main(String[] args) {

System.out.println("Hello Java");

}

}

try compiling it now

schumachera at 2007-7-12 20:38:21 > top of Java-index,Java Essentials,New To Java...
# 2
class hello{// Your program begins with a call to main(). public static void main(String args[]) {System.out.println("This is a simple Java program."); }}this is my program
amit_garga at 2007-7-12 20:38:21 > top of Java-index,Java Essentials,New To Java...
# 3
its gettin complied properly and class file is getting created also
amit_garga at 2007-7-12 20:38:21 > top of Java-index,Java Essentials,New To Java...
# 4
rt.jar should NOT be on your classpath. You shouldn't even have a CLASSPATH environment variable.You should NOT put anything in that bin directory--or anywhere under your java installation.Say you have C:\projects\hello\Hello.class.java -cp C:\projects\hello Hello
jverda at 2007-7-12 20:38:21 > top of Java-index,Java Essentials,New To Java...
# 5
> that means you dont have a main method.No. The error he's getting means it's not even finding the class.> try compiling it nowIt's compiling fine. It's running it that he's having trouble with.
jverda at 2007-7-12 20:38:21 > top of Java-index,Java Essentials,New To Java...
# 6
prob solvedi had to delete the classpath and java_home system variables and then set the "path" variable in user variables toC:\Program Files\Java\jre1.6.0_01\bin;C:\Program Files\Java\jdk1.6.0_01\bin
amit_garga at 2007-7-12 20:38:21 > top of Java-index,Java Essentials,New To Java...
# 7

> i had to delete the classpath and java_home system

> variables and then set the "path" variable in user

> variables to

>

> C:\Program Files\Java\jre1.6.0_01\bin;C:\Program

> Files\Java\jdk1.6.0_01\bin

Glad to see that the problem is solved. Just for future reference, you do not need both of these on you're path. You only need "C:\Program Files\Java\jdk1.6.0_01\bin". The problem you were having before is that the java compiler (javac) by default searches the current directory (".") for classes as if it were on the classpath, but the java interpreter (java) only searches the current directory for classes if it is on the classpath. If your classpath is not set, however, the default is the current directory. The reason it is working now is because you unset the classpath, so its value defaulted to the current directory, and the java interpreter was able to locate the class you were trying to execute.

As a side note, you also don't need have "C:\Program Files\Java\jdk1.6.0_01\jre\lib\rt.jar" on the classpath because the .jar files in the JRE\lib and JRE\lib\ext are automatically searched for classes by javac and java. (I think JRE\lib\ext contains non-standard libraries which, if used, may produce java programs that will only run on other platforms which also have the libraries. I believe this directory is most commonly used for optional or extension packages to the JDK (such as the Java Cryptography Extension) or in conjunction with the Servlet and JSP API or commercial Database APIs as a place to put libraries with no home or as a predefined place to put libraries to prevent the classpath from becoming cluttered.)

@modia at 2007-7-12 20:38:21 > top of Java-index,Java Essentials,New To Java...