Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / June 2005

Tip: Looking for answers? Try searching our database.

question about package

Thread view: 
thanh toan - 11 Jun 2005 21:25 GMT
would you please explain how to put classes in package and to use them.
I make a directory name One. And two classes: Class1 and Class2 in the
directory, One.

Class1.java:7: cannot find symbol
symbol  : class Class2
location: class One.Class1
               Class2 test = new Class2();
               ^
Class1.java:7: cannot find symbol
symbol  : class Class2
location: class One.Class1
               Class2 test = new Class2();
                                 ^
2 errors
Class2 compiled ok, but not Class1. The following is error while compiling
Class 1.

Class1.java:7: cannot find symbol
symbol  : class Class2
location: class One.Class1
               Class2 test = new Class2();
               ^
Class1.java:7: cannot find symbol
symbol  : class Class2
location: class One.Class1
               Class2 test = new Class2();
                                 ^
2 errors
================

==============
/ * filename Class1.java */
package One;

public class Class1

{

   public static void main(String args[])

   {

       Class2  test = new Class2();

   }

}

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

/* filename: Class2.java */

package One;

public class Class2

{

   public static void main(String args[])

   {

   }

}
Knute Johnson - 11 Jun 2005 22:52 GMT
> would you please explain how to put classes in package and to use them.
> I make a directory name One. And two classes: Class1 and Class2 in the
> directory, One.

thanh:

You need to think of packages as directories.  The package one.two.three
would be in directory one/two/three.  So to compile files in any of the
packages you need to be in a directory above one (eg. root).

This and how jar files work is one of the most complicated parts of
Java.  Why it isn't simpler or better documented I don't know.

Signature

Knute Johnson
email s/nospam/knute/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.