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 / October 2006

Tip: Looking for answers? Try searching our database.

importing

Thread view: 
man4*.* - 27 Oct 2006 21:44 GMT
if I say:
import java.awt.*;
<cut>
ActionListener and ActionPerformed won't work until
I import java.awt.event.*;

Didn't I already imported event when I say import java.awt.*; ???
Eric Sosman - 27 Oct 2006 22:07 GMT
man4*.* wrote On 10/27/06 16:44,:
> if I say:
> import java.awt.*;
[quoted text clipped - 3 lines]
>
> Didn't I already imported event when I say import java.awt.*; ???

   No -- as you've already discovered!

   Packages contain classes and only classes; they do not
contain other packages.  The term "sub-package" is a misnomer,
as it seems to imply that a package can be contained inside
a "super-package."  The way the package names are constructed
and the way the packages' classes are located by the usual
ClassLoaders also conspire to support this illusion of package
containment, but it's only an illusion: Packages contain only
classes and nothing else.

Signature

Eric.Sosman@sun.com

man4*.* - 27 Oct 2006 22:14 GMT
THX dude...
like the son "just an ilusion..." :-))
Ed - 28 Oct 2006 17:08 GMT
Eric Sosman skrev:

> man4*.* wrote On 10/27/06 16:44,:
> > if I say:
[quoted text clipped - 18 lines]
> --
> Eric.Sosman@sun.com

(Door opens to reveal a windy, rainy night. Enter Victorian policeman,
who takes off his domed helmet and places it quietly on a door-side
table. Tapping his truncheon against his wet trouser leg, he quietly
clears his throat before announcing ...)

>From JLS:

7.1 Package Members
The members of a package are subpackages and all the top level (§7.6)
class (§8) and top level interface (§9) types declared in all the
compilation units (§7.3) of the package.

For example, in the Java Application Programming Interface:

   * The package java has subpackages awt, applet, io, lang, net, and
util, but no compilation units.
   * The package java.awt has a subpackage named image, as well as a
number of compilation units containing declarations of class and
interface types.

(Policeman nods and with an, "At your service," disappears out the door
into the miserable night. Door closes behind.)

(Door opens again. Hand reaches in to collect the helmet. Door closes
again.)

.ed

--

www.EdmundKirwan.com - Home of The Fractal Class Composition
Tor Iver Wilhelmsen - 28 Oct 2006 23:02 GMT
> (Door opens to reveal a windy, rainy night. Enter Victorian policeman,
> who takes off his domed helmet and places it quietly on a door-side
> table. Tapping his truncheon against his wet trouser leg, he quietly
> clears his throat before announcing ...)
>
> >From JLS:

[Delendam ex JLS § 7.1]

The bit the policeman left out is significant:

"The hierarchical naming structure for packages is intended to be
convenient for organizing related packages in a conventional manner,
but has no significance in itself other than the prohibition against a
package having a subpackage with the same simple name as a top level
type (§7.6) declared in that package. There is no special access
relationship between a package named oliver and another package named
oliver.twist, or between packages named evelyn.wood and evelyn.waugh.
For example, the code in a package named oliver.twist has no better
access to the types declared within package oliver than code in any
other package."

So: It's just a partitioning of namespaces; you are just as well off
writing com_foo as com.foo other than for the directories involved for
a file-based classpath. Import statements, reflection calls involving
packages and acess modifiers all totally ignore the concept of a
"subpackage".
Ed - 29 Oct 2006 17:55 GMT
Tor Iver Wilhelmsen skrev:

> > (Door opens to reveal a windy, rainy night. Enter Victorian policeman,
> > who takes off his domed helmet and places it quietly on a door-side
[quoted text clipped - 23 lines]
> packages and acess modifiers all totally ignore the concept of a
> "subpackage".

Well-quoted, Meister Wilhelmsen.

The writers of the Java specification did indeed make a mistake with
their first draft, as they themselves have now recognised.

Hierarchical decomposition of system behaviour is a singularly powerful
design aid. As Sun's Victoria Livschitz said, "The power of intuitively
understanding the meaning and relationship between things is the
proverbial silver bullet, if there is one, in the war against
complexity:"
http://java.sun.com/developer/technicalArticles/Interviews/livschitz_qa.html

And what is a more intuitive aid to comprehension than having
subpackages relate to their parents more than they relate to more
distant packages, precisely the opposite of the current JLS text?

For example, given the following package structure, a good designer
will clearly identify the software in com.game.view.gui as being more
related to the software in com.game.view than the software in
com.game.model.player:

com.game.model;
com.game.model.rules;
com.game.model.player;
com.game.controller;
com.game.view.gui;
com.game.view.html;

This is simply because the software in the view subpackages all relate
to presenting the game view, whereas the software in the model
subpackages relate to the game's playing behaviour. When the new
requirement pops up there the game should have an ascii-picture view
for old, text consoles, the designer will immediately think that most
of the work will be in the view subpackage somewhere, and not in the
player subpackage.

In other words, the hierarchical subpackages under the view package
represent a clearly identifiable encapsulation unit which is larger
than a package but smaller than the system as a whole. There is not,
however, an access modifier associated with this encapsulation unit, as
you correctly pointed out.

At least, not yet.

Gilad Bracha, JLS author, submitted JSR 277 for certification, and it
has zipped along at the usual JSR-process speed of around 2 milimetres
per year; this has led to JSR 294. One of Gilad's initial intentions
was precisely to introduce this
greater-than-package/less-than-system-wide encapsulation level (though
in trying to emulate .NET's deployment-based access modifier they,
IMHO, are taking a bit of a tangent):
http://blogs.sun.com/gbracha/entry/developing_modules_for_development

And a short summary of JSR itself:
http://jcp.org/en/jsr/detail?id=294

Bring on Java 7.

.ed

--

www.EdmundKirwan.com - Home of The Fractal Class Composition
adwords@pulpjava.com - 28 Oct 2006 05:28 GMT
The wildcard imports everything from a given folder, but not from any
subfolders. You'd have to explicity import packages from the event
package as well.

Just as a word of note, imports using the wildman, or the wildcard, is
a poor programming practice. It's always best to explictly state the
classes you wish tom import.

Cheers,

-Cameron McKenzie
Author of What is WebSphere?

For Free Java Certification Mock Exams: www.scja.com
Free Java and J2EE Multimedia Tutorials: www.mcnz.com
www.pulpjava.com www.technicalfacilitation.com

> if I say:
> import java.awt.*;
[quoted text clipped - 3 lines]
>
> Didn't I already imported event when I say import java.awt.*; ???


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.