This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes importing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "importing" Watch "importing" New topic
Author

importing

Atrus Greyor
Ranch Hand

Joined: Mar 07, 2004
Posts: 110
do you have to import each section of the API indivdualy?
For example instead of:
import java.awt.*;
import java.lang.*;
couldn't you just do:
import java.*;
Thanks in advance!
Wai Hung
Greenhorn

Joined: Apr 15, 2004
Posts: 23
I don't think you can do that
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Despite appearances, a package x.y is not, in any meaningful sense, "part of" a package x. "import x" imports only classes directly in package "x", not those in "x.y". Since there actually are no classes in the "java" package, the answer is no, "import java.*" does nothing useful.


[Jess in Action][AskingGoodQuestions]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
I'm thinking that Ernest might have meant to say:
"import x.*" imports only classes directly in package "x", not those in "x.y"


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
walter kirsch
Greenhorn

Joined: May 10, 2004
Posts: 1
Then, will
import "java.*.*"
do the trick?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: importing