aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes IMPORTS Doubt 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 "IMPORTS Doubt" Watch "IMPORTS Doubt" New topic
Author

IMPORTS Doubt

sravanthi pulukuri
Ranch Hand

Joined: Mar 15, 2007
Posts: 125
Can anyone explain me the difference between static imports and ordianry imports
iam unable to solve questions from imports concept please
Thanks in advance
swapnil dangore
Ranch Hand

Joined: Jun 05, 2006
Posts: 46
Hi sravanthi ,
With static import , you can import only static members of the class. So , no need to type classname to access members imported statically.


Regards
Swapnil


Cheers<br />-------------<br />Swapnil<br /> <br />SCJP5-81%<br /> <br />"Dictionary is the only place where Success come before Work"
sravanthi pulukuri
Ranch Hand

Joined: Mar 15, 2007
Posts: 125
Hey
the with ordianry import cant we import static members/?
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Originally posted by sravanthi pulukuri:
Hey
the with ordianry import cant we import static members/?


No, that is why there is static import, otherwise what would be difference
between normal import and static import.

static import just gives a facility to avoid some keystrokes.
It enables us to use PI, E,etc constants of the Math class to be used directly without writing Math.PI or Math.E for example.



Thanks,


cmbhatt
sravanthi pulukuri
Ranch Hand

Joined: Mar 15, 2007
Posts: 125
Thanks chandra
sravanthi pulukuri
Ranch Hand

Joined: Mar 15, 2007
Posts: 125
So suppose if i use
import com.sun,scjp.class.*;
where in class is the file name,imports only the nonstatic members of the class??
then in that case i should use
import static com.sun.scjp.class.Enum;
Where in Enum is declared in the class and we can use constants present in Enum
Please clarify
venkata ramana sanku
Greenhorn

Joined: May 25, 2007
Posts: 2
The static import construct allows unqualified access to static members without inheriting from the type containing the static members. Instead, the program imports the members, either individually:

import static java.lang.Math.PI;

or en masse:
import static java.lang.Math.*;


Once the static members have been imported, they may be used without qualification:
double x = cos(PI * theta);

The static import declaration is analogous to the normal import declaration. Where the normal import declaration imports classes from packages, allowing them to be used without package qualification, the static import declaration imports static members from classes, allowing them to be used without class qualification
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: IMPORTS Doubt