[Java Review] 6: Package & import

The following notes are based on video series: 手把手教你用Java基础教程 - 北京尚学堂 - 马士兵

package & import are used to resolve repeated class names.

package
  • Declare what package the class(es) belongs to.
  • Declared at 1st line in java:
1
package pk1.pk2.pk3;
  • If none package line —> nameless package .
  • Java manages packages by directory. For instance, the above .java will located at ./pk1/pk2/pk3.
import
1
2
3
4
5
6
7
8
//specific class
import pk1.pk2.pk3.classname;

// all classes of a package
import pk1.pk2.pk3.*;

//without import
pk1.pk2.pk3.classname abc = new pk1.pk2.pk3.classname()
JDK main packages
  • java.lang: String, Math, Integer, System, Thread (default import)
  • java.awt: abstract window toolkits
  • java.applet
  • java.net
  • jave.io
  • java.util
1
jar -cvf xx.jar *.*
0%