• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem with using packages

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator









why do I get this error?(T.class file is in the required folder)
thanks
 
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of import p1.*;, try import p1.a.b.*;. Or, better yet, import p1.a.b.T;. When using imports, it is better explicity import the class you want, unless you are using so many classes that it would be very cumbersome to write all the imports. Of course a lot of IDEs, to my understanding, will automatically organize your imports for you.

EDIT: Messed up my imports. Fixed them .
 
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kevinn:

Despite how they look, packages are not hierarchical in Java. So, if you have two packages like this:

tld.website.project.subproject.package.sub1
tld.website.project.subproject.package.sub1.sub2

Doing an import on tld.website.project.subproject.package.sub1.* will not find any classes from tld.website.project.subproject.package.sub1.sub2.

John.
 
kevinn lee
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

W. Joe Smith wrote:Instead of import p1.*;, try import p1.a.b.*;. Or, better yet, import p1.a.b.T;. When using imports, it is better explicity import the class you want, unless you are using so many classes that it would be very cumbersome to write all the imports. Of course a lot of IDEs, to my understanding, will automatically organize your imports for you.

EDIT: Messed up my imports. Fixed them .


thank you
code compiles when all the 3 qualified names of the classes are presenet.But why doesnt it work with "*"?
 
kevinn lee
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John de Michele wrote:Kevinn:

Despite how they look, packages are not hierarchical in Java. So, if you have two packages like this:

tld.website.project.subproject.package.sub1
tld.website.project.subproject.package.sub1.sub2

Doing an import on tld.website.project.subproject.package.sub1.* will not find any classes from tld.website.project.subproject.package.sub1.sub2.

John.



thanks a lot John
 
Ranch Hand
Posts: 63
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Kevin Lee,

Simply remember this...



1) import statement just makes avilable the classes that are only present in the packages which are being imported.
2) it does not avail the classes in the sub package of the imported package.




Example :

1) import java.util.*; ------ avails only the classes which are in the java.util package.
2) import java.util.concurrent.*; ------ avails the classes of java.util.concurrent package but not the classes in the util package;
3) import java.util.Scanner; ------ avails only the Scanner Class to our program from util package.

i Hope, This will help you.
 
kevinn lee
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you ravi
 
Catch Ernie! Catch the egg! And catch this tiny ad too:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic