Sometimes we may need to write many statements similar to system. Out. println () in the class. Every time we write so much trouble, with Java 5, this becomes very simple. Let's take a look at the static import example:
Package Com. Kay. java5.test1;
Import StaticJava. Lang. system. out;//Static import of Java 5
Import StaticJava. Lang. system. Err;
Public ClassStaticimportclass {
Public Static VoidMain (string [] ARGs ){
Out. println ("Hello, world");
Err. println ("Error");
}
}
We can also use static import methods:PackageCom. Kay. java5.test1;
Import StaticJava. Lang. system. out;//Static import of Java 5
Import StaticJava. util. arrays. Sort;//Imported the static method sort () in the arrays class ()
ImportJava. util. arrays;
Public ClassStaticimportclass {
Public static void main (string [] ARGs) {
int [] I = { 3 , 1 , 2 };
// sort method call
sort (I);
out. print (arrays. tostring (I);
}< BR >}
sometimes we need to import a bunch of static methods in a class. If one write is too tired, we can use the wildcard in static import: package COM. kay. java5.test1;
Import static JAVA. lang. system. out; // static import of Java 5
Import static JAVA. lang. math. * ; // static import wildcard
Public class staticimportclass {
Public Static VoidMain (string [] ARGs ){
Out. Print (PI );
}
}