aspose file tools*
The moose likes Beginning Java and the fly likes How to run and print this code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to run and print this code" Watch "How to run and print this code" New topic
Author

How to run and print this code

Lao Kinsuyi
Ranch Hand

Joined: Mar 22, 2007
Posts: 30
Hi Ladies and Gentlemen

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");
}
}
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags.

I doubt that code compiled.
Lao Kinsuyi
Ranch Hand

Joined: Mar 22, 2007
Posts: 30
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.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

In addition to using code tags it's helpful to PostRealCode.

Is the code in the default package? (In other words, no package keyword?)
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Wait--you have SCJP 5.0?
Tekchand Prasad
Ranch Hand

Joined: Oct 20, 2005
Posts: 32
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: 39409
    
  28
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to run and print this code