filename

C

chirs

What is the rules/requirements to name a .java file. Are there some
books or online documents explain these? I only heard

1 If a file contains a class that has main(), the filename should be
that class name.

2 If it is an applet, the filename should be the (unique) public class
name.

Are they ture?

My next question is if a file has many classes and they do not have
main(), is there a rule to choose a filename? What are the rules for
other type of programs, such as JavaBeans and servlets

Thanks a lot

Chris
 
J

Joona I Palaste

chirs said:
What is the rules/requirements to name a .java file. Are there some
books or online documents explain these? I only heard
1 If a file contains a class that has main(), the filename should be
that class name.
2 If it is an applet, the filename should be the (unique) public class
name.
Are they ture?
My next question is if a file has many classes and they do not have
main(), is there a rule to choose a filename? What are the rules for
other type of programs, such as JavaBeans and servlets

If the file has a class that is public, then the filename should be that
class name. That goes for applets, classes with main(), or any other
classes.
 
C

chirs

If a file has many classes and it does not have a public class, is
there a rule to choose a filename?

Thank you.
 
M

Michael Borgwardt

chirs said:
If a file has many classes and it does not have a public class, is
there a rule to choose a filename?

No, but there should *never* be many classes in a file; in fact, there should
rarely (if at all) be more than one class in a file (excepting nested classes),
simply for the reason that it makes the whole affair much clearer.
 
T

Tim

Michael said:
No, but there should *never* be many classes in a file; in fact, there
should
rarely (if at all) be more than one class in a file (excepting nested
classes),
simply for the reason that it makes the whole affair much clearer.

Are you two refering to jar files?
 
A

Andrew Thompson

..
| Michael Borgwardt wrote:
....
| >> If a file has many classes and it does not have a public
class, is
| >> there a rule to choose a filename?
....
| > No, but there should *never* be many classes in a file; in
fact, there
| > should
| > rarely (if at all) be more than one class in a file
(excepting nested
| > classes),
| > simply for the reason that it makes the whole affair much
clearer.
| >
|
| Are you two refering to jar files?

No. Michael is referring to .java files, it
is recommended that each class has it's
own .java file.

jar files typically contain many files.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top