Skip to main content

Introduction to java.lang

The java.lang package provides classes that are fundamental to the design of the Java programming language. It is the most important package in Java.

Because these classes are so essential, the java.lang package is automatically imported by the Java compiler into all programs. You do not need to explicitly write import java.lang.*; at the top of your Java files.


Core Features of java.lang

The java.lang package contains the core classes and interfaces that form the backbone of Java. Some of its most critical features and classes include:

1. The Object Class

The Object class is the root of the class hierarchy in Java. Every class in Java has Object as a superclass, either directly or indirectly. It provides fundamental methods like equals(), hashCode(), and toString().

2. String Manipulation

This package provides the String, StringBuffer, and StringBuilder classes, which are used extensively for creating and manipulating text data in virtually every Java application.

3. Wrapper Classes

Java is an object-oriented language, but it has primitive data types (like int, char, double) for performance reasons. The java.lang package provides Wrapper Classes (Integer, Character, Double, etc.) to wrap these primitives into objects so they can be used in collections and generic programming.

4. System Operations

The System class provides access to system-level resources, such as standard input/output streams (System.out, System.in), environment variables, and the garbage collector.

5. Math Operations

The Math class contains a collection of static methods for performing basic numeric operations such as exponential, logarithm, square root, and trigonometric functions.

6. Multithreading

The Thread class and the Runnable interface, which are essential for creating concurrent applications (as we covered in the Multithreading section), also reside in this package.

7. Exceptions and Errors

The root classes of the exception handling hierarchy, Throwable, Exception, Error, and RuntimeException, are all part of java.lang.


In the upcoming sections, we will take a deep dive into the most frequently used classes in the java.lang package and understand how to leverage their built-in methods effectively.