Phase 12 of 20 · Topic 12.1

Package Architecture & Reverse Domain Naming Conventions

1Concept

Packages group related classes into hierarchical namespaces to avoid class name collisions. By global convention, package names use reversed internet domain names in all lowercase (e.g. `com.company.project.module`). Classes inside subpackages must be explicitly imported.

2Architecture Diagram

Directory Tree on Disk:
src/main/java/
  └── com/
      └── enterprise/
          └── banking/
              ├── model/     (Account.java, Customer.java)
              ├── service/   (TransferService.java)
              └── repository/(AccountRepository.java)

3Code Example

Core Java
package com.enterprise.banking.service;

// Explicit imports
import java.util.UUID;
import java.time.Instant;

public class TransactionLogger {
    public static void log(String txType, double amount) {
        String txId = UUID.randomUUID().toString().substring(0, 8);
        System.out.printf("[%s] TX-%s: %s of $%.2f recorded.%n", Instant.now(), txId, txType, amount);
    }

    public static void main(String[] args) {
        log("DEPOSIT", 1500.00);
    }
}

4Expected Output

[2026-09-03T14:17:04Z] TX-8f921e4a: DEPOSIT of $1500.00 recorded.

5Key Takeaways

  • Package declaration MUST be the very first non-comment line in a `.java` source file.
  • Subpackages do NOT inherit permissions or visibility from parent packages.
  • Wildcard imports (`import java.util.*`) do NOT cause runtime performance degradation (compiler-only resolution).