This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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: 38412
    
  23
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: 19672
    
  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: 19672
    
  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: 38412
    
  23
That was the sort of thing I was thinking about, Rob. Thank you.
 
Don't get me started about those stupid light bulbs.
 
subject: import static??