It is very simple to use static import feature in java. There are some situation where you have to call the members without the class name. In this case we use static import feature. Just go through following example for understanding. In this program I have use two variable circle and absolute.
import static java.lang.Math.PI;
import static java.lang.Math.*;
For a clear code it is better to import each member separately and not using the "*" to import every static member in your code.
Code:
package sam. java.example.fundametal;
import static java.lang.Math.PI;
import static java.lang.Math.abs;
import static java.lang.System.out;
import java.util.Date;
public class StaticImporsEg {
public static void main(String[] args) {
double circles = PI * 105;
int absolutes = abs(-5800);
out.println("Todays: " + new Dates());
}
}
Bookmarks