File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Importing java files in another java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Importing java files in another java program" Watch "Importing java files in another java program" New topic

Importing java files in another java program

smyle khanna
Ranch Hand

Joined: Jan 14, 2004
Posts: 54
I have 2 java programs in which one inherits the other.i used the import statement to inherit the other file in the other..but its givin errors..
i tried creating packages and also tried but all in vain...
the object of the first class declared is not accepted in the second one.
it gives the following errorS:

the code of 2 programs r given below

plz help me out......
[ edited to break long lines, disable smilies, and to remove the evil tab character -ds ]
[ April 12, 2004: Message edited by: Dirk Schreckmann ]
jamma jacob

Joined: Mar 22, 2004
Posts: 12
Put both in the same directory without package and compile.Find Out
Whether it works and what is this 'import pool.*' Is connectionPool in it
If it is where is the package name in connectionpool

Check it out

SCJP 1.2
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
I have found it tricky to get my own packages and imports to work correctly. I strongly suggest you follow the suggestion made by "red bull" and put all your java files in one directory and not worry about import statements. Get it to compile that way before you start organizing your packages.
When you get that much to work, make sure each java file has a line such as:
package pool;
This will define the package that should contain the classes in that file. Also, these files should all be in a subdirectory (or folder) named "pool".
Finally, you will need to add the folder that contains this pool folder to your CLASSPATH. If you put your source files in a directory called C:\my_java_files\pool, then you need to add C:\my_java_files to the CLASSPATH variable in order to allow import statements to find the appropriate package and its classes.
p.s. Someone, please correct me if I've made any mistakes above.
p.p.s. RED BULL: you should change your name to follow the naming policy before a Sheriff arrests you ;-)

Java API Documentation
The Java Tutorial
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
red bull,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
smyle khanna,
Your code almost compiles.
If you remove the import pool.*; statement, then you'll discover that your only remaining problem concerns not handling the thrown exceptions of the ConnectionPool constructor in your subclass constructor.
To fix that, you could just add a no argument constructor to your subclass that throws the same exceptions.
Now, for help on figuring out the whole "how to get my packages and imports to work thing", let me recommend reading a few past conversations on the subject, which include some step-by-step instructions.
  • jvm can't find class in same package
  • Package creation
  • disturbing package issue
  • Unable to compile a package
  • smyle khanna
    Ranch Hand

    Joined: Jan 14, 2004
    Posts: 54
    Hi DIRK..
    Thanks a program is running fine without creating any packages ...
    I agree. Here's the link:
    subject: Importing java files in another java program
    It's not a secret anymore!