Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Java Package Access

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

A package is used to store related classes. And a package is just like a folder.
In eclipse, I create a package "SimpleGUI" in src directory, and create another package "SimpleGUI.model". Actually, "SimpleGUI.model" is a folder "model" in .../src/SimpleGUI

So I should be able to regard everything in folder "model" as something that is also in folder "SimpleGUI". So I should also be able to regard a class in package "SimpleGUI.model" as a class in package "SimpleGUI". (Is this true?)

However, , in package "SimpleGUI", when I try to use a class that is defined in package "SimpleGUI.model", I have to import SimpleGUI.model.classname
Otherwise, type will not be able to be resolved.

Why is that? If it is true that a class in package "SimpleGUI.model" is also a class in package "SimpleGUI" (The logic is: package is folder, so "in sub-folder" means "a part of folder" means "a part of package"), "import" shouldn't be necessary.
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. If you import a package then (e.g. java.util.*) then the subpackages are not imported. You must import them separately (e.g. import java.util.concurrent.*).
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And Java conventions say that package names should be all lowercase.
 
Castor Tack
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, I'll just keep that in mind.
Thanks, guys
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic