Presentation on theme: "Java Packages CSci 1130 Intro to Computer Programming with Java Instructor Tatyana Volk."— Presentation transcript:
Java Packages CSci 1130 Intro to Computer Programming with Java Instructor Tatyana Volk
Packages. Java is a relatively simple language, but it has a set of standard packages which can be used by any of the program. A package is a collection of classes which logically fit together and which may interact between themselves.
Sun Microsystem provides a version of two of those programs together, together with some other useful programs, in Java Development Kit (JDK). Important resource provided by JDK is Application Programming Interface (API), which gives details of all the classes provided by Sun Microsystems for Java language.
Package import java.applet.*; import java.awt.*; Packages are used to group related classes for use in other programs. There are several class packages that come with Java. By default, every Java application imports the classes contained within the java.lang package, so you do not have to manually import this package.
applet - for creating Java applet to run on the Web awt -for graphics and and graphical user interfacing io - for input and output lang - for routine language functions net - for networking util - for additional utilities Java Packages
Accessing a package: import java.package.* ;
Appendix O contains a summary of the Java application Programming Interface (API), version 1.1 Note: class System is a part of java.lang (does not need import statement)
Note: using import statement to include packages is similar to using the include statement in C. The * character in import statement tells the Java compiler to use all the classes stored within the package. You could also specify which classes to use, but because you are usually need many classes within the single package it is easier to use the asterisk. Also Java compiler understands which classes are used and which are not, so using the asterisk does not eat up any additional memory.
We can use several individual imports, one for each class. For example, Date and Random are classes in the java.util package. We can say import java.util.Date ; import java.util.Random; or import java.util.* ; the effect will be the same.