Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

package statement

 
chailin fong
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I placed BookDemo.java in c:\BookPack,
then I compile this file, it created two .class file

Next, I want to create the package. I go to the directory above BookPack, and issue this command:

C:\> package BookPack

The message shown as:

'package' is not recognized as an internal or external command, operable program or batch file.



Thanks

====================================================================

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 Beginners Guide", "Schildt", 2001);
books[1] = new Book("Java 2 Programmer Reference", "Schildt", 2002);
books[2] = new Book("HTML Programmer Reference", "Powell and Whitworth", 1998);
books[3] = new Book("Red Storm Rising", "Clancy", 1986);
books[4] = new Book("On the Road", "Kerouac", 1995);
}
}
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no command package. If you want to create a package, you need to create a directory called BookPack in your case and then put your source code there. Then compile it using the normal javac.
 
chailin fong
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created directory BookPack and place BookDemo.java in it.

Now, if I did this:

C:\BookPack> java BookPack.BookDemo

I will get:

Exception in thread :"main" java.lang.NoClassDefFoundError:BookPack/BookDemo
 
sudhir nim
Ranch Hand
Posts: 212
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
go one directory up, and execute the same command.

it should be

C:>java BookPack.BookDemo
 
bharathibattu kandikuppa
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i typed the program like this but it is giving the error 'class' or 'interface' expected what i have to correct the program please reply it i created BookPack directory when i compiled it gives error.

 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15281
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Please UseCodeTags when you post source code, so that your code is formatted nicely with line numbers. I added the code tags in your post above for you.

In which line do you get the error message? Please copy and paste the exact error message here.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic