running java programs on linux
Java Note
=========
did a simple hello world program (my first in java), compiled it and then tried to run it but this happens (note bin is /java/bin);
[root@localhost bin]# ./java [PATH TO PROGRAM]/hello
Exception in thread "main" java.lang.NoClassDefFoundError: [PATH TO PROGRAM]/hello
is this because i haven't linked java to it's standard classes or I haven't set classpath or what.
please give answer in plain english as i'm new to both java and linux (i'm using fedora core 1).
OK, assuming you have paths set up correctly, and you do not have an environment variable CLASSPATH, do the following
1. cd into the directory where your java file is
2. Type the following (assuming your program is Hello.java) javac Hello.java
3. Assuming this compiled, you should now have a file called Hello.class
4. To run it, type the following java Hello
If that does not work, make sure you have a main method which looks something likepublic static void main (String [] args) {
System.out.println("Hello World");
}
Get back if you have more problems.