Wednesday, 21 March 2018

Static Import in Java

java, JavaXpert, TheJavaXpert, JavaTutorial, JavaForBeginners,  CoreJava, JavaForLeaners, JavaBlog, Piyushdahi, Piyushdabhiblog ,Static Import in java, Java Static, dynamic, static keyword, java static word

Static Import

The static import feature of Java 5 facilitates the Java programmer to access any static member of a class directly.

There is no need to qualify it by the class name.

The Advantage of static import Less coding is required if you have access any static member of a class often.

The Disadvantage of static import: If you overuse the static import feature, it makes the program unreadable and unmaintainable.

Example of static import in Java :

import static java.lang.System.*;    
class StaticImportExample

  public static void main(String args[])





What is the difference between import and static import?

The import feature allows the Java programmer to access classes of a package without package qualification whereas the static import feature allows accessing the static members of a class without the class qualification. The import provides accessibility to classes and interfaces whereas static import provides accessibility to static members of the class.

Post a Comment

Click Here