Static import in Java is used to access the static members like fields and methods without using the complete name. It helps in code where static methods and variables are used a lot. For instance, if you do not want to type the same thing in your code again and again then import static is helpful. For example, if your code needs a lot of mathematical calculations then static import will eliminate the issue of retyping the same code.
How to Employ Static Import in Java?
The static import in Java works in a manner that all static data is imported without using the class name. Static import has two forms and we use these forms according to the need when coding. One of the forms is known as a single static import that imports the declared static member. In the other form, all the static members are imported and are called static members in demand.
This write-up will contain the details to employ static import in Java.
Syntax
The syntax for static import in Java is described below:

The code will describe the implementation of static import in Java.
Example 1: Without Using Static Import
The code below has been developed without any imports in Java.
class example1{
public static void main(String args[])
{//Declare integer values
double fun1=6 ;
double func = 2;//Use Math function since the package has not been imported.
double fun2=Math.sqrt(100);//Declare the output
System.out.println("Power of 6 is:"+ Math.pow(fun1,func));
System.out.println( "Square root of 100 is:"+ fun2);
}
}
In the code above:
- The integer values have been declared.
- Using Math.sqrt() function the square root has been declared.
- The Math.pow() function will print the power of the entered value.
- The output have been displayed on the screen using the println() function.
Output

In the above output, the power of 6 has been printed and the square root of 100 has been printed.
Example 2: Using Static Import to Print the Results
The code below has been developed to import several packages in Java.
//The packages using static has been importedimport static java.lang.System.out;
import static java.lang.Math.*;
class Example2{
public static void main(String args[])
{
double fun1=6 ;
double func = 2;
double fun2=sqrt(100);
System.out.println("Power of 6 is:"+pow(fun1,func));
System.out.println( "Square root of 100 is:"+ fun2);
}
}
In the above-designed code:
- Static import has been implemented in the form of import static java.lang.System.out; and import static java.lang.Math.*;
- Therefore there is no need to use the Math library that was previously used in example 1.
- As compared to the previous code where static import was not implemented.
Output

Example 3: Ambiguity for the Compiler
There is a case in which the static members having the same name are imported from different classes in which ambiguity occurs for the compiler. The case is discussed below:
import static java.lang.Integer.*;
import static java.lang.Byte.*;
public class importstatic {
public static void main(String[] args)
{//Since both Byte and Integer contains MIN_VALUE
system.out.println(MIN_VALUE);
}
}
Output

In the output above the compiler is generating an error regarding the MIN_VALUE that the value is ambiguous. The MIN_VALUE is present in both Integer and Byte therefore, the compiler is confused as to which class is called for the specified value.
Drawbacks of Static Import in Java
There are some drawbacks to using static imports. Static Import makes the code unmaintainable and unreadable if it is applied multiple times. Since the users won’t be able to understand which class responds to which static object.
Conclusion
Static import in Java has access to all the static methods and fields. It works in such a way that all static data is imported without calling each class name separately. The static import is useful when there arises a need to get the same classes in a code repeatedly. In this write up we have discussed how the code works if the static import is implemented and what difference it makes when the static import is implemented.