| Author |
Linking a group of classes togather
|
matthew christensen
Greenhorn
Joined: Sep 14, 2010
Posts: 17
|
|
|
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
Joined: Jan 10, 2002
Posts: 56204
|
|
|
Hint: package.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
matthew christensen
Greenhorn
Joined: Sep 14, 2010
Posts: 17
|
|
Bear Bibeault wrote:Hint: package.
that really annoying thing that eclipse keeps warning me about?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56204
|
|
|
I have no idea.
|
 |
matthew christensen
Greenhorn
Joined: Sep 14, 2010
Posts: 17
|
|
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
Joined: Jan 10, 2002
Posts: 56204
|
|
|
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
Joined: Sep 14, 2010
Posts: 17
|
|
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
Sheriff
Joined: Oct 13, 2005
Posts: 32694
|
|
matthew christensen wrote: . . . this includes methods and variables?
See the Java™ Tutorials, but the short answer is yes.
|
 |
Alex Hurtt
Ranch Hand
Joined: Oct 26, 2010
Posts: 98
|
|
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
Joined: Oct 27, 2005
Posts: 19216
|
|
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.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32694
|
|
|
You are correct; packages aren't hierarchical.
|
 |
 |
|
|
subject: Linking a group of classes togather
|
|
|