9
Java Packages CSci 1130 Intro to Computer Programming with Java Instructor Tatyana Volk

Java Packages

Embed Size (px)

DESCRIPTION

Java Packages. CSci 1130 Intro to Computer Programming with Java Instructor Tatyana Volk. Packages. - PowerPoint PPT Presentation

Citation preview

Page 1: Java Packages

Java Packages

CSci 1130

Intro to Computer Programming with Java

Instructor Tatyana Volk

Page 2: Java Packages

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.

Page 3: Java Packages

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.

Page 4: Java Packages

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.

Page 5: Java Packages

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

Page 6: Java Packages

Accessing a package:

import java.package.* ;

Page 7: Java Packages

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)

Page 8: Java Packages

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.

Page 9: Java Packages

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.