?
Solved

static imports  j2SE 5.0

Posted on 2013-11-25
3
Medium Priority
?
304 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 28

Accepted Solution

by:
dpearson earned 2000 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 28

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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
A solution for Fortify Path Manipulation.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

771 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