• Post Reply Bookmark Topic Watch Topic
  • New Topic

Linking a group of classes togather  RSS feed

 
matthew christensen
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im still kinda new to java, how would i link a bunch of classes together so i could use all the methods and variables in each class?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hint: package.
 
matthew christensen
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Hint: package.


that really annoying thing that eclipse keeps warning me about?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no idea.
 
matthew christensen
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:I have no idea.


can you give me a quick example of how to use a package?

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look up Java packages. Essentially it's ha ierarchy for organizing classes. The default access allows classes in the same package to share elements.
 
matthew christensen
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Look up Java packages. Essentially it's ha ierarchy for organizing classes. The default access allows classes in the same package to share elements.

i see, thats ingenious! this includes methods and variables?
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
matthew christensen wrote: . . . this includes methods and variables?
See the Java™ Tutorials, but the short answer is yes.
 
Alex Hurtt
Ranch Hand
Posts: 98
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Look up Java packages. Essentially it's ha ierarchy for organizing classes. The default access allows classes in the same package to share elements.


Sorry but I have to correct this. While packages in Java may appear to be hierarchical in nature because of the corresponding file system directories that they create, they are in fact NOT conceptually hierarchical. They are really more akin to namespace than hierarchy.

For instance, classes declared in package my.package have no 'hierarchical' relationship to classes defined in a package called my.package.two (unless the classes/interfaces within these packages themselves happen to extend or implement one another) even though they both begin with a common substring 'my.package'

The full package name where a class resides is the most atomic unit. Classes can inherit, packages do not. I have seen more than a few novice Java learners get tripped up by this, falsely believing that because classes can be hierarchical that so can packages.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice explanation It should prevent users from trying to import java.util.* and then expect everything from java.util.concurrent to be imported as well. I've seen a few of threads about that.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are correct; packages aren't hierarchical.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!