A package is a namespace that groups related classes and interfaces together — like a folder for Java classes. Packages help organize large projects, avoid class name conflicts, control access using access modifiers, and enable code reuse. Built-in Packages java.lang (imported automatically), java.util (collections, date), java.io (input/output). Creating your own: use the "package" keyword as the first line (e.g., package com.mycompany.app;). Importing: import a single class (import java.util.Scanner;), import entire package (import java.util.;), or use fully qualified name. Sub-packages can be nested (e.g., com.company.project.module) but don't automatically inherit from parent packages. Comments are non-executable statements the compiler ignores. Three types: Single-line (// comment)…
Key Takeaways
Packages organize classes and prevent naming conflicts.
java.lang is imported automatically in every Java program.
Package statement must be the first line of the source file.
Sub-packages do NOT automatically inherit parent package classes.