aspose file tools
The moose likes Beginning Java and the fly likes regarding package Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "regarding package" Watch "regarding package" New topic
Author

regarding package

Timothy Leong
Ranch Hand

Joined: May 25, 2005
Posts: 55
hi guys,

Let's say in class A I have import java.text and class B I also import java.text in my code. Class A and Class B are in A.java and B.java respectively.

the mainAB class is in mainAB.java and has a main static make use of class A and B. How do I package the 3 classes together so tt I only require to import java.text once instead of 2 times in A.java and B.java.

Thanks alot
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35224
    
    7
It's not a question of packaging the classes. The import statements are needed for compilation only, and each class is compiled separately, so each one needs to contain all the imports it utilizes.
Are you trying to save a few keystrokes for copying/pasting the import statements?


Android appsImageJ pluginsJava web charts
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 681
I think of the import statement as an extension of the classpath for the compiler. It helps the compiler find classes you are using and keeps you from having to type the full package names when you use a class: java.util.Vector vec = ....

It sort of controls the namespace for classes.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by Timothy Leong:
hi guys,

Let's say in class A I have import java.text and class B I also import java.text in my code. Class A and Class B are in A.java and B.java respectively.

the mainAB class is in mainAB.java and has a main static make use of class A and B. How do I package the 3 classes together so tt I only require to import java.text once instead of 2 times in A.java and B.java.

Thanks alot


The only way to make it so you only need one import statement is to put all three classes in the same file. However, I strongly suggest that you DON'T do this. Mostly because as the number of classes grow, a single file will be much, much too big for you to maintain. Just get used to the fact that every file needs to import the classes that it needs.

Layne


Java API Documentation
The Java Tutorial
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: regarding package
 
Similar Threads
Class path Doubt again.
package problems...
Import
using package getting compiler error
Using import and static import problem