You are currently viewing Mastering java.lang: A Guide with Examples

Mastering java.lang: A Guide with Examples

  • Post author:
  • Post category:Java
  • Post comments:0 Comments
  • Post last modified:January 26, 2024


The java.lang package is a fundamental part of the Java Standard Edition API, providing core classes and utilities that are automatically imported into every Java program. In this tutorial, we will explore some key classes in java.lang and demonstrate their usage through practical examples.

1. Object Class:

The Object class is the root of the Java class hierarchy. All classes inherit from this class, and it provides essential methods such as equals(), hashCode(), and toString(). Let’s create a simple example:

2. String Class:

The String class represents a sequence of characters and is widely used in Java programming. It provides various methods for manipulating strings. Here’s an example:

3. System Class:

The System class provides access to the standard input, output, and error streams, as well as methods for interacting with the environment. Here’s an example of using System.out for printing:

4. Math Class:

The Math class contains methods for performing basic numeric operations, including trigonometry, exponential, logarithmic, and rounding functions. Example:

5. Wrapper Classes:

Java provides wrapper classes for primitive data types in java.lang such as Integer, Double, Boolean, etc. These classes allow primitive data types to be treated as objects. Example:


The java.lang package provides essential classes and utilities that form the foundation of Java programming. This tutorial covered some key classes like Object, String, System, Math, and wrapper classes, along with practical examples to illustrate their usage. As you delve deeper into Java development, a solid understanding of these core classes will prove invaluable.

Leave a Reply