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 / General / January 2006

Tip: Looking for answers? Try searching our database.

package problem

Thread view: 
gk - 11 Jan 2006 07:03 GMT
package com.pack1;

import com.pack1.packe2.pack3.*; // is this correct ? its more deeper

import com.*;// is this correct ? its above the package directory

// java class here
Roedy Green - 11 Jan 2006 07:30 GMT
>import com.pack1.packe2.pack3.*; // is this correct ? its more deeper
>
>import com.*;// is this correct ? its above the package directory

It is not a hierarchy even though it looks like one.

You must spell it out longhand.

import com.pack1;
import com.pack2;
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

gk - 11 Jan 2006 08:50 GMT
>It is not a hierarchy even though it looks like one.

what ? which one is not hierarchy ?

i can save files here "com/pack1/packe2/pack3"  folder  with a package
statement "package com.pack1.packe2.pack3; " in all my  java files.

i can save files here "com"  folder  with a package statement "package
com; " in all my  java files.

but if i have a file   with package statement "package com.pack1"
which of the following import work ?

import com.pack1.packe2.pack3.*;
import com.*;

i did not understand what do you mean  by hierrarchy
gk - 11 Jan 2006 08:50 GMT
>It is not a hierarchy even though it looks like one.

what ? which one is not hierarchy ?

i can save files here "com/pack1/packe2/pack3"  folder  with a package
statement "package com.pack1.packe2.pack3; " in all my  java files.

i can save files here "com"  folder  with a package statement "package
com; " in all my  java files.

but if i have a file   with package statement "package com.pack1"
which of the following import work ?

import com.pack1.packe2.pack3.*;
import com.*;

i did not understand what do you mean  by hierrarchy
Robert Klemme - 11 Jan 2006 11:22 GMT
>> It is not a hierarchy even though it looks like one.
>
> what ? which one is not hierarchy ?

Packages in general.

> i can save files here "com/pack1/packe2/pack3"  folder  with a package
> statement "package com.pack1.packe2.pack3; " in all my  java files.

This is just a convention used by most Java IDE's and standard class
loaders.  But you should remember that packages != directories.  You can
place your class files everywhere you like as long as you make sure they
are accessible via some class loader.  Of course, there are some drawbacks
in putting all class files in a single directories (size and nameclashes
to name some).

What Roedy tried to convey is that there is no hiearchy of packages
although the dotted notation makes it look like there was.  Packages are
just sitting beside each other.  package com.foo.bar is not an inner
package to com.foo and has no provileged access to it.

> i can save files here "com"  folder  with a package statement "package
> com; " in all my  java files.
[quoted text clipped - 4 lines]
> import com.pack1.packe2.pack3.*;
> import com.*;

None of them.  You need

import com.pack1.*;

or

import com.pack1.YourClass;

> i did not understand what do you mean  by hierrarchy

Hope I could clear this up a bit.

Kind regards

   robert
gk - 11 Jan 2006 11:47 GMT
hi, i am more confused.

is my question clear to you guys ?

here i am reposting it again

code 1:
--------
package com.pack1.packe2.pack3;

class klass1
{
// code

}

this code has been saved in com/pack1/packe2/pack3 directory.

code 2:
--------

package com;

class klass2
{
// code

}

this code has been saved in com directory.

code 3:
--------

package com.pack1;

import com.pack1.packe2.pack3.*; // is this OK
import com.*; // // is this OK

class MyClass
{
//  i want to use klass1 and klass2 here. so, how do i import those
classes now ? is now import statement correct ?

}

this code has been saved in com/pack1 directory.
Chris Smith - 11 Jan 2006 16:15 GMT
[...]
> package com.pack1;
>
[quoted text clipped - 9 lines]
>
> this code has been saved in com/pack1 directory.

Yep, you're fine.

(If you want additional nitpicking, it's a good idea to avoid wildcard
imports because they can lead to compatibility problems in later code.  
However, wildcards do work.)

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Alan Krueger - 11 Jan 2006 13:37 GMT
> package com.pack1;
>
[quoted text clipped - 3 lines]
>
> // java class here

It's not clear what you're asking.  The import of com.* will only import
classes directly in package com, it won't import anything deeper.

Many believe you shouldn't import using *, that you should import only
the classes you need.  Eclipse generally supports this by adding imports
as needed and by removing any unnecessary ones when you organize your
imports.
gk - 11 Jan 2006 14:00 GMT
look at my example code.

is that posible ?
Robert Klemme - 11 Jan 2006 14:47 GMT
> look at my example code.
>
> is that posible ?

Did *you* actually look at the explanations given?

   robert
Chris Smith - 11 Jan 2006 16:16 GMT
> > look at my example code.
> >
> > is that posible ?
>
> Did *you* actually look at the explanations given?

To be fair, they weren't very good.

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Alan Krueger - 12 Jan 2006 02:39 GMT
> To be fair, they weren't very good.

To be fair, neither was the original question.  It's hard to answer
something that isn't clear.


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



©2009 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.