Link to home
Start Free TrialLog in
Avatar of perfect_tranquility
perfect_tranquilityFlag for United States of America

asked on

A Package spread over multiple files??

1).Can a JAVA package be spread over multiple files?
2).If yes,how do i name those files which have classes that do not have the main() in them?
3).How about naming those files?
4).How should I use the jar utility to make an archive out of all those files?

This will be of great help, experts.
ASKER CERTIFIED SOLUTION
Avatar of sbockelman
sbockelman

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of perfect_tranquility

ASKER

Regarding #1,

I am aware that there can only be one public class per file.However,why would I want to have multiple public classes when i would need just one main() function?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Breadstick
Breadstick

>   2.  You must name each file containing a public class by the class name + ".java" extension.
>   You need to use the import statement in the class containing main, then just use the classes.

This is generally true.  However, if you're program is not part of a package, and the rest of the classes you've written for it are in the same directory, then you do not have to import the other classes, as they will already be part of the classpath when you run your program.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
And one another thing on Netbeans IDE that I suggested on your previous questions has a utility to make a jar file for
you so that you wont have to worry about it.