Download presentation
Presentation is loading. Please wait.
1
Java Import Statement Copyright © 1997-2010 Curt Hill
This is the media computation version Copyright © Curt Hill
2
Import Statement Gives access to existing classes and interfaces
Similar to #include of C Usually first lines in file Follows package, if present Often follows comments Example: import java.awt.Color; Copyright © Curt Hill
3
Import Form import is a keyword
Following that is the class you want to have access to Wildcards can be used: import java.awt.*; Using wildcards may slow the compile by 10% and who cares? Object code will usually be same Copyright © Curt Hill
4
Directories Java grew up in a UNIX environment
Its import statement reflects this tree shaped directory Each dot represents a boundary between one directory and another Thus the import import java.awt.Color; is in directory: java/awt and the file is named Color.CLASS Copyright © Curt Hill
5
Tree Shaped Directories
The disk of most file systems contains two types of files: Directories Files Each directory may then also contain other files and other directories First seen in MULTICS but popularized by UNIX Appeared in DOS 2 and later Copyright © Curt Hill
6
JAR Files Java also has its own archive file: JAR
JAR stands for Java ARchive A JAR file has exactly the same format as a zip file It may be maintained by zip utilities that allow different extensions A JAR or ZIP file may also contain a directory structure An import may reference the directory structure within a JAR file Copyright © Curt Hill
7
Common imports Basics in Java.Lang need no import
Applets will usually use: import java.applet.*; import java.awt.*; Applications may also use: import java.io; import java.net; import java.util; Developed code may also be imported Copyright © Curt Hill
8
Example The following picture shows a Windows C: disk
It contains several directories and files The Java runtime is in the Program Files directory The runtime contains a JREn.jar This contains where imports may be found, especially these: import java.awt.Color; import java.utils.Scanner; import java.awt.*; Copyright © Curt Hill
9
Tree Shaped Directories
C: Disk dir1 … Programs … Windows … File1 JRE File1 java awt utils Color.class … JButton.class … Scanner.class Copyright © Curt Hill
10
Developed Code World and Turtle are classes not part of the JRE
If incorporated into a JAR file they may be accessed with an import Otherwise the IDE may be directed to make them part of the global scope Copyright © Curt Hill
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.