aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes import java.awt.event.*; Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "import java.awt.event.*;" Watch "import java.awt.event.*;" New topic
Author

import java.awt.event.*;

srinivas bolloju
Ranch Hand

Joined: Jan 23, 2001
Posts: 112
hi,
i thought .* meant what all comes under specified is taken into consideration. well, to my notice, import java.awt.* doesn't import all classes or whatever under awt.*, i mean,
import java.awt.*;
doesnt import
import java.awt.event.*;
so if someone who doesnt know about event, he/she still thinks that java.awt.* is equal to java.awt.event.*
Is there a way around for this??
why did they put java.awt.event as a different package? they could as well clubbed the whole thing under java.awt.* right? pls explain..
java.awt and java.awt.event are altogether different packages.
in the program..below, the program doesnt compile if java.awt.event.* is commented.


please use the [code][/code] tags when showing code. visit <a href="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=ubb_code_page" target="_blank" rel="nofollow">http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=ubb_code_page</a> ,for more details
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Basically, java.awt and java.awt.event are two different packages. As you have noticed, Java does not allow to type import java.* and thus import all Java classes within the SDK.
The people at Sun have done the thing this way because they probably had good reasons. They figured out that package modularizing is a good thing to help group related classes within different packages instead of having a big mess in a single package.
The bottom line is that whenever you want to use a class, you have to import it or the package which contains it. The Javadocs are well-organized enough to quickly find what you need.
so if someone who doesnt know about event, he/she still thinks that java.awt.* is equal to java.awt.event.*
Is there a way around for this??

If someone doesn't know about events, she learns how to use them and where to find them. This is part of the learning process.


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
srinivas bolloju
Ranch Hand

Joined: Jan 23, 2001
Posts: 112
Crettaz,thank you for fine tuning.
lesson i learnt,im sharing with the folks here in this forum:

importing
import java.awt.*; and
import java.awt.event.*;
in a java file
is not equivalent to importing only
importing java.awt.*;
in that file.,
there are so many other packages like java.awt.color,java.awt.datatransfer, java.awt.dnd,java.awt.event,java.awt.font
etc... in API which one should be aware of. not only in awt we also have them in lang and util.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
The objectives say that you should focus on java.awt which means that you have to concentrate on java.awt only and not java.awt.datatransfer, java.awt.font, etc. When a package is named, it means that specific package only and not the contained packages. Make the difference between a class hierarchy and a package hierarchy. Subpackages have nothing in common with their parent package while subclasses inherit the behavior and features of their parent class. In clear, java.awt.event and java.awt have nothing in common except their names maybe... The following JLS section may be worth reading:
JLS 7 Packages
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: import java.awt.event.*;