File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes import static?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "import static??" Watch "import static??" New topic
Author

import static??

mansi gupte
Ranch Hand

Joined: Dec 30, 2008
Posts: 72
import static sun.scjp.com.*;

Is the above statement valid? If so why is the keyword used over here, what is its significance?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Yes. If you search through this forum you will find it used, and you also find this link to the Sun website. I am not convinced I agree with the bit about "very sparingly."
By the way: is a package beginning with sun. safe for use? I can't remember the details, but there are some packages beginning with com. or sun. which are regarded as experimental.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

It's only valid if "sun.scjp.com" is a class. With static import you're saying: import all (or those named) static members from a class.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Campbell Ritchie wrote:By the way: is a package beginning with sun. safe for use? I can't remember the details, but there are some packages beginning with com. or sun. which are regarded as experimental.

Not experimental, but packages that start with sun, sunw and com.sun are not part of the public API, and any classes in those packages can change or even disappear from one JRE release to another. Therefore, you should not use them unless you are willing to restrict users of your application to a specific JRE version or a few specific versions.

I have seen one application that works only with Java 1.4.2_08 - even 1.4.2_10 breaks the code. The reason: the developers used a class that isn't part of the public API.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
That was the sort of thing I was thinking about, Rob. Thank you.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: import static??
 
Similar Threads
static imports
IMPORTS Doubt
static import
import
Static Imports