Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

Java:Tutorial - Importing Files


  • Please log in to reply
No replies to this topic

#1 John


    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 11 January 2007 - 12:00 PM

This tutorial will show you how to “include” other classes in your Java app.

You should have JDK installed and an editing environment you are comfortable with.

You should know how to create classes within your IDE

The Idea
In Java, you have the opportunity to import other class files that do most of the work for you.

In Java we import class files by simply writing the word include and then the path to the file you want to include. For example

import javax.swing.JFrame;
Which imports the JFrame class. You could also do this
import javax.swing.*;
The asterisk imports everything in the javax.swing package. The import code is placed after your package declaration and before your class header. For example:
package foobar;
import javax.swing.*;
public class MyClass {


Along the same lines you can import your own files in your own package. For example, if you name a package “mypackage” and in that package there is a class called “myclass” you can import that class like this:

import mypackage.myclass.*;

When programming in Java you are provided with many classes that do all the hard work for you. When creating even a basic program you will import at least one class.
  • 0

Also tagged with one or more of these keywords: import

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download