Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9034371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:27:33+00:00 2026-06-16T08:27:33+00:00

I just started developing in Java after not having touched it since my college

  • 0

I just started developing in Java after not having touched it since my college days. So far I’ve been able to remember a lot of things and read up on a whole bunch, this one is still not clear to me…

The problem I’m having is that a lot of books/examples/tutorials/SE posts focus on simpler, smaller problems where this type of question would not occur.

If you have a project with 1000’s of types (classes, interfaces or both)… is the best project structure/layout convention to simply create a new file for each type? Coming from C++/C# background, that doesn’t sit well with me (yet?) as I’m used to typically having one, or maybe few, files that would define interfaces used throughout the rest of the project. And small, related classes would often be implemented in one file.

As a more concrete example, I am currently refactoring an “Event” class which currently is handling 15 different event types, all in one class. The package where the class is defined also has other event-handling classes, such as readers, writers and parsers.

If I create base event class and 15 deriving classes, as each one has slightly different attributes/behaviors… these are my options:

  1. 15 new files all added to the existing package – seems I’d be “polluting” that package as number of files would go from 6 to 21 and orthogonality would break.
  2. Move all event classes into their own package and keep them together
  3. Create one file, called “Events.java” and put all 15 classes as nested static classes of that one main class (in essence “class Events” would become just a namespace) – appears that Google does that with their protocol buffers.

Having not enough Java experience, I just can’t decide which approach is an accepted standard. Is it ok to have 1000’s of files in one directory? Should I create more packages? (looking at other libraries/frameworks, it appears that they keep number of packages to a minimum)

In other cases, especially when implementing a strategy pattern, i would create one public base class with a static factory method and a number of non-public classes just so I could keep them in one file. Seems I’m making these “design” choices only based on this one public type per class rule and everything time I do that, this question comes back… maybe I’m just not doing it right.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T08:27:34+00:00Added an answer on June 16, 2026 at 8:27 am

    Having to get over the idea of “too many files” is common among programmers coming to java from other languages.

    There are special cases where you might want to have, say, a static inner class that you make public (see Map.Entry, for example), but generally, you want to stick with one class (one source file) per public class.

    It certainly makes sense to create sub-packages when classes can logically be sub-grouped. Don’t be afraid of creating “too many” packages either.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just started developing for Android. So far it's been surprisingly smooth sailing, but
Our team has just started developing for the Sitecore CMS. We find that after
Hello! I've been programming for a long time but just started developing for android,
I have just started having a go at developing a small KDE app as
I've just started developing Android applications. I'm having a little problem with networking. If
I’ve been developing Windows desktop applications for many years, but just started developing Windows
So I've just started developing C# WinForm applications and each project I've been working
I've only just really started android developing and have been reading about services here
I just started developing an application with Playframework (Java) and I thought it is
I have just started developing for iPhone (I've been an Android developer for quite

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.