Import static elements for more readable Java code
May 21
One of the welcome additions to Java language in Java 5 release is the static import declaration. static import works in the same way as traditional import declaration but it imports only the static members of a class.
Traditional import declaration looks like this
import java.util.*;
The above statement will import all the classes under java.util package.
The format of static import declaration is similar with the addition of keyword static. E.g;
import static java.lang.Math.*;
This statement will import all the static members of java.lang.Math class.
Similar to import declaration the static import offers two options. You can import all static members of a class or import only the members that you need in your program.
import static java.lang.Math.PI;
will import only PI.
import static java.lang.Math.*;
will import all static elements from Math class.
More


