aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes single type import...?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "single type import...??" Watch "single type import...??" New topic
Author

single type import...??

lusha tak
Ranch Hand

Joined: Dec 30, 2000
Posts: 185
what does it mean when one says,
"a single-type import will take precedence over an import-on-demand"
moreover
what do we mean by
single type import??
import-om demand??
what's the difference b/w above two??
Thanks in advance
Lusha
[This message has been edited by lusha tak (edited May 27, 2001).]
Charlie Swanson
Ranch Hand

Joined: Jan 29, 2001
Posts: 213
When you use the import statement, you can import the exact
thing that you need and no more (the exact class name for example).
You can also refer to whole class and have the system import
what is needed in the class when it needs it. When you use the class in you program, it will look in the import <...>.* and locate what you need.
Hope this clears it up.
Scott Appleton
Ranch Hand

Joined: May 07, 2001
Posts: 195

"a single-type import will take precedence over an import-on-demand"

I'm not sure what is meant by "take precedence". You can have both types of imports in a single source file. Anyone able to explain the meaning of this statement?
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4462
    
    6

Originally posted by Scott Appleton:
I'm not sure what is meant by "take precedence". You can have both types of imports in a single source file. Anyone able to explain the meaning of this statement?

Probably means that if you had a Foo class in two different packages, e.g. package1 and package2, then
import package1.Foo;
import package2.*;
Foo f = new Foo(); // pulls in package1.Foo, not package2.Foo

Junilu

Junilu - [How to Ask Questions] [How to Answer Questions]
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi all,
When determining which class to use, the compiler follows a set of 'lookup' rules. First it checks the source file for the type, then it looks for a single-type import that matches the classname, then it checks the import-on-demand packages. It stops checking when it finds a type that matches the required one; if no class is found or the declarations are ambiguous, you get a compile error
See JLS �6.5.5 Meaning of Type Names
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
[This message has been edited by Jane Griscti (edited May 29, 2001).]


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: single type import...??