• Post Reply Bookmark Topic Watch Topic
  • New Topic

regarding event subpackage  RSS feed

 
Shivangi Joshi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why do we need an explicit call to event subpackage..like if i used any listener interface from awt.event,can i just write import statement like import java.awt.*;? .actually i tried it out already but it throws an error.so is it like that whenever i used event subpackage i need to specify it in import statement like import java.awt.event.*;.and if it is so,why?
 
Amit Ghorpade
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why do we need an explicit call to event subpackage.

we never call a package we import it.

And regarding your question, packages are just folders on your hard drive.
If you need a file in a folder say com/foo/bar/file.txt, then does the path
com/foo work?
Same applies to packages.

Hope this helps
 
Rajasekhar Devi Reddy
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you import a package you only import classes in that package, so if you need classes in a sub package you got to import that sub package too.
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another way to think of the import statement is as an extension to the classpath to help the compiler find class definitions. The classpath plus the import path needs to end where the class file is located. With subpackages, you need to continue the import path to get to the class file.
 
Shivangi Joshi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!