Organization of Java packages ...

Posted on 2002-04-07
Last Modified: 2010-03-31
We are developing a Java based application and would need some recommendation regarding the organization of Java packages. The application is made up of 6-7 components. Hence it will at least have 6-7 packages. However, there are some miscellaneous packages as well such as Exceptions (which contains base exceptions), ValueObjects, interfaces etc.
Please consider an example:
org.mypackage.exceptions : contains base class for exceptions. All specific exceptions extend this base class.

org.mypackage.valueobjects : contains a base class for valueobjects. ValueObjects specific to a component extend this base class.

org.mypackage.Component1 : contains classes specific to a componet (specifc valueobects, exceptions etc.).

Should I place componet1 specific classes in the component1 package or should I place them in specific packages such as org.mypackage.valueobjects, org.mypackage.Exceptions.

as an example: should a  component1specifc exception class be present in the org.mypackage.exception package or in the org.mypackage.Component1 package.

should a  component1specifc valueobejct class be present in the org.mypackage.valueobject package or in the org.mypackage.Component1 package.

Which is the best practice?

Question by:shayad

Expert Comment

ID: 6924033
I should treat the exception classes in the same way as the other classes. I should make some kind of org.some_package_path_.common and put more general things there, such as classes that many other inherit from. That could be exceptions or regular classes that many other inherit from.

Accepted Solution

exorcist earned 50 total points
ID: 6924820
the package structure of specific components should resemble the package structure of the common package. So for example:




that's how I would do it.

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Application launch issue with Apache Tomcat 5 64
Spring Framework HTTPSession management 1 45
spring jars download 1 36
Tagging and Merging on Branch 1 30
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question