Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 334
  • Last Modified:

static imports j2SE 5.0

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
gudii9
Asked:
gudii9
  • 2
1 Solution
 
dpearsonCommented:
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
 
gudii9Author Commented:
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
 
dpearsonCommented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now