-2

The file name is BookDemo.java and I compiled it like this: javac bookpack\BookDemo.java

This is my block of code:

package bookpack;  

class Book {  
private String title;  
private String author;  
private int pubDate;  

Book(String t, String a, int d) {  
title = t;  
author = a;  
pubDate = d;  
}  

void show() {  
System.out.println(title);  
System.out.println(author);  
System.out.println(pubDate); 
System.out.println(); 
  }  
}  

class BookDemo {  
public static void main(String args[]) {  
Book books[] = new Book[5];  

books[0] = new Book("Java: A Beginner's Guide", 
                    "Schildt", 2011);  
books[1] = new Book("Java: The Complete Reference", 
                    "Schildt", 2011); 
books[2] = new Book("The Art of Java", 
                    "Schildt and Holmes", 2003); 
books[3] = new Book("Red Storm Rising", 
                     "Clancy", 1986);  
books[4] = new Book("On the Road", 
                    "Kerouac", 1955);  

for(int i=0; i < books.length; i++) books[i].show();  
   } 
}

The output is this:
javac: file not found:bookpack\BookDemo.java Usage: javac <options> <source files> use -help for a list of possible options

How can you fix this so that the code will execute? Thank you for your help!!!

James Bond
  • 5
  • 1
  • 1
  • 8
  • so how are you trying to run java? What is the command ? – Scary Wombat Nov 21 '14 at 04:44
  • Can you include the entire input and output? This sounds like it might be an issue with your PATH. – Pokechu22 Nov 21 '14 at 04:44
  • possible duplicate of [How to execute a java .class from the command line](http://stackoverflow.com/questions/1279542/how-to-execute-a-java-class-from-the-command-line) – Scary Wombat Nov 21 '14 at 04:45
  • Post the command to run it. It might be that the name isn't fully qualified since it's in a package. Run it with java bookpack.BookDemo from the bookpack folder. – AtlasMeh-ed Nov 21 '14 at 04:46

3 Answers3

0

To run program you must try this command:

java bookpack.BookDemo

While running program, you need to specify the class containing main().

Make sure that cmd/termincal location is like e.g.

D:\
|
`+-your-folder(cmd here)
    |
    `+-bookpack
0

The compile never completed because javac could not successfully find your .java file. Try putting in the entire path to the file. For example, if the file is in C:\Users\James\bookpack\BookDemo.java, try running javac "C:\Users\James\bookpack\BookDemo.java".

After the compilation is complete, you would run it with java "C:\Users\James\bookpack\BookDemo".

RogueBaneling
  • 4,331
  • 4
  • 22
  • 33
0

I placed your code in file BookDemo.java inside directory C:\Java\new

And run commands below:

C:\Java\new>javac -version javac 1.7.0_40

C:\Java\new>javac -d . BookDemo.java

C:\Java\new>java bookpack.BookDemo Java: A Beginner's Guide Schildt 2011

Java: The Complete Reference Schildt 2011

The Art of Java Schildt and Holmes 2003

Red Storm Rising Clancy 1986

On the Road Kerouac 1955

C:\Java\new>

The command :

javac -version

for checking the javac already on your PATH .If it failure check the post here

Community
  • 1
  • 1
vanduc1102
  • 5,769
  • 1
  • 46
  • 43