The java.lang
package is a part of the Java Standard Library and contains a number of core Java classes that are used in almost all Java programs. These classes include fundamental data types, basic input and output functions, and essential system functions.
Commonly used classes in java.lang package
Some of the most commonly used classes in the java.lang
package are:
Object
: The root class of the Java class hierarchy. All Java classes inherit fromObject
, which provides basic methods such asequals
,hashCode
, andtoString
.Class
: Represents the class of an object. TheClass
class provides methods for getting information about a class, such as its name, its superclass, and the interfaces it implements.String
: A class that represents character strings. Strings are immutable, meaning that once they are created, they cannot be modified.Math
: A class that provides basic math functions such as trigonometric functions, logarithms, and square roots.System
: A class that provides access to system resources, such as standard input and output streams and the current time.Thread
: A class that represents a thread of execution. A thread is a separate flow of control within a program, and theThread
class provides methods for creating and manipulating threads.Throwable
: The base class for all exceptions and errors in Java. It provides methods for printing the stack trace of an exception and for obtaining the cause of an exception.
The java.lang
package also includes a number of wrapper classes for primitive data types, such as Integer
for int
, Long
for long
, and Boolean
for boolean
. These wrapper classes provide methods for converting between primitive types and their corresponding wrapper types, as well as for performing basic operations such as parsing strings and comparing values.
Overall, the java.lang
package is an essential part of the Java Standard Library, providing a wide range of basic functions that are used in almost all Java programs.