This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

How to run and print this code

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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");
}
}
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseCodeTags.

I doubt that code compiled.
 
Lao Kinsuyi
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wait--you have SCJP 5.0?
 
Ranch Hand
Posts: 32
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 74687
335
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic