Open In App

Difference Between java.lang and java.util

Last Updated : 17 Dec, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Java Packages contain classes, interfaces, and sub-packages. The packages java.lang and java.util are two of the most commonly used packages in Java Standard Library. Both packages contain useful classes and utilities.

In this article, we will learn about java.lang and java.util package with examples and also the difference between these two packages.

Package java.lang

The java.lang package in Java is a core package that includes the fundamental classes and features of Java language. It is automatically available in every Java program eliminating the need for explicit import statements.

Example of java.lang package:

Java




//Java program to demonstrate 'java.lang' package
import java.io.*;
import java.lang.*;
class GFG {
    
    public static void main(String args[])
    {
        String s1 = "Hello";
        String s2 = "Geeks";
        String result = s1+ " " +s2;
        System.out.println(result); 
    }
}


Output

Hello Geeks




Package java.util

The java.util package in Java is a versatile utility package encompassing numerous classes and interfaces designed for the various advanced programming tasks and it offers a broad range of the functionalities including data structures, input/output operations and many other commonly used utilities.

Example of java.util package:

Java




//Java program to demonstrate 'java.util package'
import java.util.ArrayList;
public class GFG {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("apple");
        list.add("banana");
        list.add("Mango");
        System.out.println("List: " + list);
    }
}


Output

List: [apple, banana, Mango]




Difference between java.lang and java.util

Characteristics

java.lang

java.util

Purpose

The Core package of the Java language that provides fundamental classes and features

Utility package that provides useful classes and features for the more advanced programming tasks

Classes

To Provides fundamental classes such as String, Integer and Object

Provides utility classes such as ArrayList, HashMap and Scanner

Auto-Import

The Classes are automatically imported in the every Java program

The Classes need to be explicitly imported in Java programs

Usage

Used for the basic programming tasks such as string manipulation and object manipulation

Used for the more advanced programming tasks such as data structures and date/time manipulation



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads