java_lang_package.pptxjava_lang_package.pptx

ssuserec53e73 5 views 8 slides Oct 21, 2025
Slide 1
Slide 1 of 8
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8

About This Presentation

java_lang_package.pptx


Slide Content

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, Character, etc. • Enum – Defines enumeration types.

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. Boxing and Unboxing: int a = 10; Integer obj = Integer.valueOf(a); // Boxing int b = obj; // Unboxing

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. • Examples: System.out.println(), System.exit(), System.currentTimeMillis().

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...'); } } public static void main(String[] args) { new MyThread().start(); }

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 { int x = 5 / 0; } catch (ArithmeticException e) { System.out.println('Cannot divide by zero'); }

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 Without java.lang, no Java program can execute.
Tags