Interactive Computer Science Tutoring

Learn programming concepts interactively

AHA Schools Logo

What Is a Package?

Discover how packages organize and namespace your Java code

Understanding Packages

A package is a namespace that organizes a set of related classes and interfaces. Think of packages as being similar to different folders on your computer!

Just like you organize project files in different folders, Java uses packages to organize hundreds or thousands of classes into logical groups.

The Java platform provides an enormous class library (API) with packages for everything from basic strings to network sockets and GUI components.

Java Project StructureFolder Analogy
Click folders to explore - just like package organization!
src/main/java

Source code directory - like java.* packages

lib/

External libraries - like javax.* packages

src/main/resources

Configuration files - like java.util.properties

Java Package Explorer5 packages
Explore common Java API packages and their classes
Search Packages
Find packages or classes by name

java.lang

Core

Core language classes automatically imported in every Java program

Classes:
String- Immutable sequence of characters
Integer- Wrapper class for int primitive
System- System-specific operations
+2 more classes...

java.util

Utilities

Utility classes including collections, date/time, and more

java.io

I/O

Input/Output operations through streams, files, and serialization

java.net

Networking

Network programming classes for URLs, sockets, and protocols

javax.swing

GUI

GUI components for desktop applications

Java API Reference

The Java Platform API Specification contains the complete listing for all packages, interfaces, classes, fields, and methods.

Demo Controls
Current package: java.lang
Java Code
Live Java representation with highlighted changes
// Understanding Java Packages - Organized Namespaces
// Package declaration (if this was in a custom package)
// package com.example.myapp;
// Import statements bring classes from other packages
// java.lang.* is automatically imported - no import needed!
public class PackageDemo {
public static void main(String[] args) {
// Using classes from java.lang
String text = "Hello from java.lang!";
System.out.println(text.length());
Integer obj = new Integer();
// Wrapper class for int primitive
System obj = new System();
// System-specific operations
System.out.println("Packages organize your code!");
}
}
History0/5
Recent package and folder interactions

No operations yet

Start by adding or modifying elements