Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to run and print this code

 
Lao Kinsuyi
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags.

I doubt that code compiled.
 
Lao Kinsuyi
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wait--you have SCJP 5.0?
 
Tekchand Prasad
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48402
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic