This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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
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.
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.
Joined: Aug 26, 2001
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