- 1Class Diagram in UML | Beginner-Friendly Guide with Examples
- 2Object Diagram in UML | Simple, Visual Examples for Beginners
- 3Component Diagram in UML | Beginner-Friendly Tutorial with Java Examples
- 4Deployment Diagram in UML | Beginner’s Guide with Examples and Java Use Cases
- 5Package Diagram in UML | Java-Focused Tutorial with Real Examples
- 6Composite Structure Diagram in UML | Java Examples & Complete Guide for Beginners


- 1Class Diagram in UML | Beginner-Friendly Guide with Examples
- 2Object Diagram in UML | Simple, Visual Examples for Beginners
- 3Component Diagram in UML | Beginner-Friendly Tutorial with Java Examples
- 4Deployment Diagram in UML | Beginner’s Guide with Examples and Java Use Cases
- 5Package Diagram in UML | Java-Focused Tutorial with Real Examples
- 6Composite Structure Diagram in UML | Java Examples & Complete Guide for Beginners

- 1Use Case Diagram in UML | Beginner's Guide with Java and Real-World Examples
- 2Activity Diagram in UML | Java-Centric Beginner's Guide with Real Examples
- 3Sequence Diagram in UML | Step-by-Step Java Guide with Real-World Examples
- 4UML Communication Diagram | Java-Based Tutorial with Real-Life Examples
- 5UML State Machine Diagram | Java-Centric Tutorial with Real Examples
- 6UML Interaction Overview Diagram | Java Tutorial with School-Based Examples
- 7UML Timing Diagram | Java Tutorial with Real-World Timing Examples

- 1UML Relationships in Java: Association, Aggregation, Composition Explained with Examples
- 2UML Inheritance and Generalization | Java Examples for Beginners
- 3Interfaces vs Abstract Classes in UML with Java Examples
- 4Multiplicity and Navigability in UML – Easy Guide with Real-Life Examples
- 5Constraints and Notes in UML – Beginner-Friendly Guide with Java Examples

- 1UML in Software Development Lifecycle (SDLC) – Complete Guide with Examples
- 2How to Create UML Diagrams from Requirements – Step-by-Step with Examples
- 3UML and Agile: A Practical Guide for Beginners
- 4Case Study: UML for an E-commerce Application – Step-by-Step UML Design
- 5UML Best Practices and Common Mistakes – A Beginner’s Guide with Examples


- 1Quiz: UML Concepts – Test Your Understanding of UML Diagrams and Principles
- 2Practical Assignment: UML Modeling – Step-by-Step UML Design Task for Java Beginners
- 3UML Review and Feedback – How to Evaluate and Improve UML Models in Java Projects
- 4UML Certificate of Completion – How to Earn and Use Your Certification
Package Diagram in UML
Next Topic ⮕Composite Structure Diagram in UML | Java Examples & Complete Guide for Beginners
Introduction
As software systems grow, managing complexity becomes more about organization than just writing code. In Java, we use packages
to group related classes. Similarly, in UML, we use Package Diagrams to visually organize large systems into logical containers and show how these containers relate to one another.
This tutorial will help you understand how to use UML Package Diagrams to group classes, manage dependencies, and improve codebase structure. We'll walk through Java-based examples using a school management system scenario to make concepts easy and relatable.
What is a Package Diagram?
A Package Diagram in UML is a structural diagram that groups related classes into packages and shows the dependencies between those packages. It gives you a high-level view of the system architecture — helping you visualize the logical partitioning of the system.

Why Use Package Diagrams?
- Organize large systems: Divide the system into manageable parts
- Visualize module interaction: Show which packages rely on others
- Improve maintainability: Reduce tight coupling and circular dependencies
- Align code structure: Match your UML packages with Java package structure
Basic Elements of a Package Diagram
1. Package
Represented as a folder icon. Each package may contain other packages, classes, interfaces, or diagrams.
package student
2. Class Inside a Package
Classes or interfaces can be placed inside the package visually. Alternatively, we just show dependencies at the package level.
3. Dependency
A dashed arrow from one package to another shows that one package depends on the other — meaning it uses its classes or interfaces.
student --> database

Example: School Management System
Let’s say we have a Java-based school management system. We might logically group it into the following packages:
com.school.student
com.school.teacher
com.school.result
com.school.database
Java Package Structure
// com.school.student.Student.java
public class Student {
private String name;
private int rollNumber;
}
// com.school.teacher.Teacher.java
public class Teacher {
private String name;
private String subject;
}
// com.school.result.ResultService.java
public class ResultService {
public void generateResult(Student student) {
// logic
}
}
// com.school.database.DBConnection.java
public class DBConnection {
public static Connection connect() { ... }
}
UML Package Diagram
Here’s how we could represent the above in a package diagram:
package com.school.student
package com.school.teacher
package com.school.result
package com.school.database
com.school.result --> com.school.student
com.school.result --> com.school.database
com.school.teacher --> com.school.database

How to Create a Package Diagram: Step-by-Step
Step 1: Identify Packages
Group classes based on functionality, responsibility, or layer (e.g., controller, service, DAO).
Step 2: Define Package Relationships
Draw dependencies based on actual usage. For example, if ResultService
uses Student
, draw a dependency from result
to student
.
Step 3: Keep the Diagram High-Level
Package diagrams should focus on inter-package relationships, not internal class details. You can always complement it with a class diagram later.
Step 4: Use UML Notation
- Package: Folder-like rectangle with name
- Dependency: Dashed arrow from dependent to provider package
Advanced Concepts
Nested Packages
Packages can be nested to show deeper hierarchies.

Import Relationships
Use notes or stereotypes to indicate import or access restrictions, such as "public API" or "internal only."
Package Merge
Merge is a special kind of dependency that unifies two packages into one logical package. Rarely used but useful in frameworks.
Best Practices
- Keep packages cohesive: Group only closely related classes
- Minimize dependencies: Avoid circular dependencies and tight coupling
- Follow naming conventions: Use consistent, readable names (e.g., com.school.result)
- Align with code: Make sure your UML packages reflect your actual Java package structure
Use Cases of Package Diagrams
- Planning: Before writing code, structure your packages visually
- Refactoring: Identify and break circular dependencies or tightly coupled packages
- Documentation: Show high-level architecture to new developers or stakeholders
- Testing: Understand module-level boundaries for unit and integration testing
Tools to Create Package Diagrams
- StarUML: Drag-and-drop UML package support with clean visuals
- PlantUML: Great for text-based diagram generation
- Lucidchart: Collaborative, intuitive UI for modular designs
- draw.io: Free tool with templates for UML packages
PlantUML Example
@startuml
package "com.school.student" {
}
package "com.school.teacher" {
}
package "com.school.result" {
}
package "com.school.database" {
}
com.school.result --> com.school.student
com.school.result --> com.school.database
com.school.teacher --> com.school.database
@enduml

Conclusion
Package diagrams are your blueprint for organizing and understanding system structure at scale. They bring order to complexity, prevent architectural drift, and provide clarity during design, refactoring, and onboarding.
Especially in Java development, where code is naturally organized into packages, UML Package Diagrams make it easy to visualize and communicate your system’s logical architecture.
Next, we’ll transition into behavioral modeling with Use Case Diagrams — perfect for defining what users can do within your system.
QUIZ
Question 1:What is the main purpose of a UML package diagram?
Question 2:A package in UML can only contain class diagrams.
Question 3:Which of the following elements can be included in a UML package?
Question 4:If a university system has separate packages for ‘Admissions’, ‘Academics’, and ‘Finance’, what does the diagram help illustrate?
Question 5:Dependencies in a package diagram indicate that one package uses or depends on elements from another package.
Question 6:Which symbols and notations are standard in a UML package diagram?
Question 7:Which type of relationship is most commonly illustrated between packages in a package diagram?
Question 8:Package diagrams are helpful in managing access control and visibility of classes across different modules.
Question 9:Consider the following:
package studentServices {
class Student {}
class Enrollment {}
}
What does this indicate?
package studentServices {
class Student {}
class Enrollment {}
}