Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Java:Tutorial - Importing Files

import

  • Please log in to reply
No replies to this topic

#1 John

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.

Prerequisites
You should have JDK installed and an editing environment you are comfortable with.
http://forum.codecal...ng-started.html

You should know how to create classes within your IDE
http://forum.codecall.net/java-tutorials/1706-java-tutorial-hello-world.html

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

Solution
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.*;

Conclusion
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