Language Package in Java
(java.lang)
Core classes, usage, and examples
Introduction to java.lang Package
• • java.lang is the core language package in
Java.
• • It contains classes fundamental to the Java
programming language.
• • Automatically imported in every Java
program.
• • Provides support for basic data types,
strings, math functions, system utilities,
exceptions, and threads.
Important Classes in java.lang
• • Object – Base class for all Java classes.
• • String – Represents text.
• • System – Provides access to system-level
resources.
• • Math – Contains mathematical operations.
• • Thread – Used for multithreading.
• • Exception, Error, Throwable – For error and
exception handling.
• • Wrapper classes – Integer, Double, Boolean,
Wrapper Classes
• • Used to represent primitive data types as
objects.
• • Useful in collections and for object-oriented
features.
• Examples:
• Integer, Double, Character, Float, Boolean,
Byte, Short, Long.
Math and System Classes
• Math Class:
• • Contains static methods for common
mathematical operations.
• • Examples: sqrt(), pow(), abs(), sin(), cos(),
random().
• System Class:
• • Provides system-level operations like I/O and
environment access.
Thread and Runnable Classes
• • Thread: Used to create and manage threads.
• • Runnable: Interface for defining thread
tasks.
• Example:
• class MyThread extends Thread {
• public void run() {
• System.out.println('Thread is running...');
• }
Exception Handling in java.lang
• • Throwable – Base class for all errors and
exceptions.
• • Exception – Recoverable conditions in a
program.
• • Error – Serious problems that applications
should not try to handle.
• Example:
• try {
Summary of java.lang Package
• • Automatically imported package.
• • Core of the Java programming language.
• • Contains classes for:
• - Object handling
• - Strings and math operations
• - System utilities
• - Multithreading
• - Exception handling
• - Wrapper classes