Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes package statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "package statement" Watch "package statement" New topic
Author

package statement

chailin fong
Greenhorn

Joined: Oct 15, 2007
Posts: 10
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

Joined: Sep 11, 2006
Posts: 959

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.


SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
chailin fong
Greenhorn

Joined: Oct 15, 2007
Posts: 10
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

Joined: Aug 29, 2007
Posts: 212

go one directory up, and execute the same command.

it should be

C:>java BookPack.BookDemo


[Servlet tutorial] [Servlet 3.0 Cook Book]
bharathibattu kandikuppa
Greenhorn

Joined: Mar 16, 2011
Posts: 1
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

Joined: Aug 16, 2005
Posts: 14074
    
  16

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: package statement
 
Similar Threads
Exercise of he book Head First Java
Java Arrays to display String
Beginner package help please
package problem
Creating classes