Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Is it Ok to put many classes in one file ?

843785Jul 11 2008 — edited Jul 12 2008
Hi all,

This is another beginner question. I was wondering, is it good practice to put many classes in one single file? Sometimes I notice there are many classes inside one big file and sometimes each class is in its own separate file. Is there an advantage in separating each class in each different file? For e.g. one big file, called A.java:
class A {
    public static void main(String[] args) { }
}

class B {}    
class C {}
class D {}
Is it better to have class B in a B.java file, and class C in C.java, etc? In the real-world workplace, what is the usual practice?
Thank you for your replies.

P/S : I love Java, it's so cool. :-)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 9 2008
Added on Jul 11 2008
22 comments
970 views