File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes import statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "import statement " Watch "import statement " New topic
Author

import statement

sandip sangale
Greenhorn

Joined: Jun 22, 2009
Posts: 15


How many times we can use * in import statement

like


import java.anypackage.*.*.*.*;


is such a think is possible if yes then how many times we can use it.
M K Rayapudi
Ranch Hand

Joined: Feb 19, 2007
Posts: 158
Only ONE *, that is last one that represents all the classess of that package


R6i
Vinod Tiwari
Ranch Hand

Joined: Feb 06, 2008
Posts: 466
    
    1

* is wild, it would import all classes/packages under it, so it is written only once.

Thanks
Vinod
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Not quite. The * imports any classes in a package, not packages too. If it is a static import, then * can import any static members of that class.

It isn't all, but any; the compiler only imports the classes it needs, not every class in the package.
Vinod Tiwari
Ranch Hand

Joined: Feb 06, 2008
Posts: 466
    
    1

Thanks Campbell for clarification, I wanted to mean that only, the class under the package (n level) and classes are umported (only required one's) at complie time.
M K Rayapudi
Ranch Hand

Joined: Feb 19, 2007
Posts: 158
Vinod Tiwari wrote:umported


@Vinod Tiwari
Where did you found the word umported ?
I coudn't able to find it in (Word Web, wikipedia, Google, etc.), can you please tell me the meaning and source if any?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Rayapudi Murali Krishna wrote: . . . can you please tell me the meaning and source if any?
Shame upon you, saying that sort of thing. Read this, and apologise.
M K Rayapudi
Ranch Hand

Joined: Feb 19, 2007
Posts: 158
I am sorry.
Max Rahder
Ranch Hand

Joined: Nov 06, 2000
Posts: 177
Vinod Tiwari wrote:Thanks Campbell for clarification, I wanted to mean that only, the class under the package (n level) and classes are umported (only required one's) at complie time.


"import" is poorly named. It doesn't import anything -- it's just letting the compiler know what package names to use when resolving class names.

If you're using Eclipse, use the "Source | Organize Imports" option to automatically create imports for every class referenced in the source.

And... some people think it's bad style to use "*" to specify any class in a given package. The idea is that doing so (1) is less self-documenting (i.e., the reader can't just look at the imports to see a list of all classes), and (2) increases the possibility of referencing the wrong class (in case, coincidentally, the class name you are using happens to also exist in one of the classes in the *'d package).

:-)
Vinod Tiwari
Ranch Hand

Joined: Feb 06, 2008
Posts: 466
    
    1

Sorry Murali, I had a typo there and thanks to Max for clarifying.

I would be failing in my duties if I do not thanks Campbell who not only asked Murali to apologise (which he gently did) but also sent me a message to accept that, thanks Campbell a ton for this nice gesture of your's.

It's because of people like you that Javaranch is touching great heights, kudos to all.

Vinod
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Not just me . . .


I am pleased that you have managed to make up
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: import statement