Solved

static imports  j2SE 5.0

Posted on 2013-11-25
3
256 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 26

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 26

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Receive file in Servlet 1 36
count8 challlenge 13 87
Unable to start eclipse ? 17 87
how do i compare an object based on two fields 6 34
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now