Course contentsShow
← Java
Lesson 671 of 2,87016. Packages, Imports, and JAR FilesFree lesson

The java.lang Package: Automatically Imported

Learn why classes like String, System, and Math don't require import statements—they're in the implicitly imported java.lang package.

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:

  • String for text manipulation
  • System for console input/output (System.out.println())
  • Math for mathematical operations
  • Integer, Double, and other wrapper classes
  • Object, the root of all classes
  • Exception and 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.