This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

import statement

 
sandip sangale
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only ONE *, that is last one that represents all the classess of that package
 
Vinod Tiwari
Ranch Hand
Posts: 466
1
IntelliJ IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
* is wild, it would import all classes/packages under it, so it is written only once.

Thanks
Vinod
 
Campbell Ritchie
Sheriff
Posts: 48453
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 466
1
IntelliJ IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48453
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry.
 
Max Rahder
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 466
1
IntelliJ IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48453
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not just me . . .


I am pleased that you have managed to make up
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic