Java.lang package in Java

Last Updated : 24 Jun, 2026

The java.lang package is one of the most fundamental packages in Java. This package provides essential functionality such as object manipulation, string handling, mathematical operations, exception handling, threading, and system-level operations.

  • Automatically imported by the Java compiler.
  • Contains core classes required by every Java program.
  • Provides support for strings, wrappers, threads, exceptions, and system operations.

Why is the java.lang Package Important?

  • It is automatically available in every Java program.
  • It contains the most commonly used classes in Java.
  • It provides the Object class, which is the parent of all Java classes.
  • It offers classes for working with strings, such as String and StringBuilder.
  • It provides mathematical functions through the Math class.
  • It supports exception handling using classes like Exception and Throwable.

Common Classes in java.lang

ClassDescription
ObjectRoot superclass of all Java classes.
StringRepresents an immutable sequence of characters.
StringBuilderMutable sequence of characters for efficient string manipulation.
StringBufferThread-safe mutable sequence of characters.
SystemProvides access to system resources, standard input/output, and environment variables.
MathContains methods for performing mathematical operations.
ThreadRepresents a thread of execution in a Java program.
RunnableInterface used to define tasks executed by threads.
ExceptionBase class for exceptions that can be handled by applications.
ErrorRepresents serious system-level errors that applications typically do not handle.
ThrowableSuperclass of both Exception and Error.
RuntimeProvides access to the Java runtime environment.
ProcessRepresents a process running in the operating system.
ClassRepresents metadata about classes and interfaces at runtime.
IntegerWrapper class for the primitive int type.
LongWrapper class for the primitive long type.
DoubleWrapper class for the primitive double type.
FloatWrapper class for the primitive float type.
CharacterWrapper class for the primitive char type.
BooleanWrapper class for the primitive boolean type.
ByteWrapper class for the primitive byte type.
ShortWrapper class for the primitive short type.
VoidRepresents the void return type.
EnumBase class for all Java enumerations.
PackageContains information about Java packages.

Advantages of java.lang Package

  • Automatically Imported: No need to explicitly import the package in Java programs.
  • Provides Core Java Classes: Contains fundamental classes required for almost every Java application.
  • Supports Object-Oriented Programming: Includes the Object class, the root of the Java class hierarchy.
  • Simplifies String Handling: Offers classes like String, StringBuilder, and StringBuffer.
  • Built-in Mathematical Functions: The Math class provides common mathematical operations.
  • Exception Handling Support: Contains classes for handling exceptions and errors.
  • Multithreading Capabilities: Provides the Thread and Runnable classes.
  • Wrapper Class Support: Includes wrapper classes such as Integer, Double, and Boolean.
  • System-Level Operations: The System and Runtime classes allow interaction with the JVM and operating system.

Relatable articles

Comment