Java Tutorial: Packages & Imports
Organise code with packages, import statements, access modifiers in the context of packages, and Java module system basics.
Organisation at scale
A `package` is a namespace — `com.company.project.model`. Without packages, every class name in the world would have to be unique. With packages, `User` in `com.myapp.model` doesn't conflict with `User` in `org.otherapp.model`.
Every real Java project has a package structure. Every IDE generates it automatically — but you should understand what it means.
What you'll learn in this Java packages & imports tutorial
This interactive Java tutorial has 6 hands-on exercises. Estimated time: 15 minutes.
- Using the standard library — Java ships with thousands of ready-made classes in packages like `java.util`, `java.io`, `java.net`. Import them to use …
- Static imports — `import static` lets you use a class's static members without the class name:
- java.util.Random — `Random` and `Math.random()` generate random numbers. `Random` is more flexible.
- java.time — modern date/time — Java 8 introduced `java.time` — the correct way to handle dates.
- Useful java.util classes — Quick tour of commonly used utilities:
- Build a simple logger — Final challenge — no starter code.
Java Packages & Imports concepts covered
- Organisation at scale