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.
Java:Tutorial - Getting Started
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
Which imports the JFrame class. You could also do thisCode:import javax.swing.JFrame;
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:Code:import javax.swing.*;
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:Code:package foobar; import javax.swing.*; public class MyClass { }
ConclusionCode: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.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks