Solved

static imports  j2SE 5.0

Posted on 2013-11-25
3
276 Views
Last Modified: 2013-12-02
Hi,

What are advantages, practical uses of
static imports introduced in j2SE 5.0.


please advise
Any links resources ideas highly appreciated. Thanks in advance
0
Comment
Question by:gudii9
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
dpearson earned 500 total points
ID: 39676165
It just saves typing when you are working with static methods/values in a class:

Java 4:
import java.lang.* ;

double pi = Math.PI ;    // Each time I reference "PI" need to add "Math." to the front
double area = Math.PI * Math.PI * radius ;

Java 5:
import static java.lang.Math.*;

double pi = PI ;    // No need for Math. here any more
double area = PI * PI * radius ;

Doug
0
 
LVL 7

Author Comment

by:gudii9
ID: 39682148
Java 4:
import java.lang.* ;

double pi = Math.PI ;    // Each time I reference "PI" need to add "Math." to the front

why we need to refer Math every time in java 4? and how it got fixed in java 5. Please advise
0
 
LVL 27

Expert Comment

by:dpearson
ID: 39682437
why we need to refer Math every time in java 4? and how it got fixed in java 5. Please advise

In Java 4 that's just the way you had to write code to refer to a static value.  In Java 5 they added a new import statement so you didn't have to do it the old way.

That's really all there is to it.

Doug
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
oracle 11g 23 107
varialbe initialization 11 37
servlet example 11 50
Finding all private fields and their corresponding getters setters for nested classes 4 16
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question