The java.lang Package: Automatically Imported
What You'll Learn
You'll discover why fundamental classes like String, System, and Math work without any import statements—they're part of the automatically imported java.lang package.
The Special Status of java.lang
Every Java program automatically has access to all classes in the java.lang package without requiring an explicit import statement. This package contains the most fundamental classes that virtually every Java program needs.
Think of java.lang as the essential toolkit that Java assumes you'll always need—like having basic utensils automatically included in your kitchen rather than buying them separately each time.
Why This Matters
You've been using classes from java.lang throughout your learning journey:
Stringfor text manipulationSystemfor console input/output (System.out.println())Mathfor mathematical operationsInteger,Double, and other wrapper classesObject, the root of all classesExceptionand error handling classes
None of these required an import statement because the Java compiler automatically imports java.lang.* for every source file.
The Implicit Import
It's as if every Java file invisibly starts with:
import java.lang.*;
You never write this line yourself—the compiler does it automatically. This is why you can write:
String greeting = "Hello";
int max = Math.max(10, 20);
System.out.println(greeting);
...without any imports at the top of your file.
Other Packages Still Need Imports
Remember: only java.lang gets this special treatment. Classes from java.util, java.io, and other packages still require explicit import statements.
Key Takeaway: The java.lang package is automatically imported into every Java program, which is why fundamental classes like String, System, and Math are always available without explicit import statements.