I have a problem to run this code. After typing javac Book.java It compiled without error. But, when i typed java Book and press enter to run the program, it shows Exception in thread "main" java.lang. Noclass Def Found error:Book I don't know what to press after writting java Book.
Here is the code
public class Book{
Book b = new Book();
public static void main (String[] args) {
System.out.prinln ("Your Book");
}
}
Sure it compiled without error. Or why do you think not? Well, I'm new to java. Ok. I wrote prinln in this forum instead of System.out.println("Your Book") ; But, it was correct on my computer and compiled.
Follow this procedure.
1. Create a dir in C drive as javaexample
2.set CLASSPATH as C:\javaexample in Environment Variable
3.run from command prompt C:\javaexample>javac Book.java
4. run from command prompt C:\javaexample>java Book
it will work
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32599
4
posted
0
Tekchand Prasad wrote:Follow this procedure.
. . . set CLASSPATH as C:\javaexample in Environment Variable . . .
No, don't set up a classpath. It will do more harm than good. When you open the command prompt create a directory there and navigate thither with these or similar commands:
mkdir java
cd java
. . .
Put your Book.java file in that directory
. . .
javac Book.java
java Book
Now you have a "java" directory for your Java work.