13 - 20:33:40 CS 61B Lecture 13 Friday Todays reading...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
02/19/09 20:33:40 1 13 CS 61B: Lecture 13 Friday, February 20, 2009 Today’s reading: JAVA PACKAGES ============= In Java, a "package" is a collection of classes and Java interfaces, and possibly subpackages, that trust each other. Packages have three benefits. (1) Packages can contain hidden classes that are used by the package but are not visible or accessible outside the package. (2) Classes in packages can have fields and methods that are visible by all classes inside the package, but not outside. (3) Different packages can have classes with the same name. For example, java.awt.Frame and photo.Frame. Here are two examples of packages. (1) java.io is a package of I/O-related classes in the standard Java libraries. (2) Homework 4 uses "list", a package containing the classes DList and DListNode. You will be adding two additional classes to the list package. Package names are hierarchical. java.awt.image.Model refers to the class Model inside the package image inside the package awt inside the package java. Using Packages -------------- You can address any class, field, or method with a fully-qualified name. Here’s an example of all three in one. java.lang.System.out.println("My fingers are tired."); Java’s "import" command saves us from the tedium of using fully-qualified names all the time. import java.io.File; // Can now refer to File class, not just java.io.File. import java.io.*; // Can now refer to everything in java.io. Every Java program implicitly imports java.lang.*, so you don’t have to import it explicitly to use System.out.println(). However, if you import packages that contain multiple classes with the same name, you’ll need to qualify their names explicitly throughout your code. java.awt.Frame.add(photo.Frame.canvas);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/21/2010 for the course CS 61B taught by Professor Canny during the Spring '01 term at Berkeley.

Page1 / 2

13 - 20:33:40 CS 61B Lecture 13 Friday Todays reading...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online