java.lang Package
Core classes that are automatically imported in every Java program.
Object
The root class of all Java classes.
toString
Returns a string representation of the object.
equals
Compares this object to another for equality.
hashCode
Returns a hash code value for the object.
getClass
Returns the runtime class of this object.
clone
Creates and returns a shallow copy of this object.
String
Immutable sequence of characters.
Length and Access
Returns the number of characters.
Returns the character at the specified index.
Returns true if length is 0.
Substring Operations
Returns substring from beginIndex to end.
Returns substring from beginIndex to endIndex (exclusive).
String s = "Hello World";
s.substring(6); // "World"
s.substring(0, 5); // "Hello"
Search Operations
Returns index of first occurrence, or -1 if not found.
Returns index starting from specified position.
Returns index of last occurrence.
Returns true if this string contains the sequence.
Tests if string starts with the prefix.
Tests if string ends with the suffix.
Comparison
Compares content for exact equality.
Compares ignoring case differences.
Compares lexicographically. Returns negative, zero, or positive.
Transformation
Converts all characters to uppercase.
Converts all characters to lowercase.
Removes leading and trailing whitespace.
Replaces all occurrences of a character.
Replaces all occurrences of a sequence.
Concatenates the specified string to the end.
Splitting and Joining
Splits string around matches of the delimiter.
"a,b,c".split(","); // ["a", "b", "c"]
Static Methods
Returns string representation of the argument.
Returns formatted string. Supports %d, %f, %s, %c, %b, %x, %n.
String.format("Name: %s, Age: %d", "John", 25);
StringBuilder
Mutable sequence of characters for efficient string building.
Constructor
Constructs an empty StringBuilder.
Append Methods
Appends the string representation to this sequence. Returns this for chaining.
Other Methods
Returns the current length.
Sets the length (truncates if shorter).
Reverses the sequence.
Returns a String containing the characters.
StringBuilder sb = new StringBuilder();
sb.append("Hello").append(" ").append("World");
String result = sb.toString(); // "Hello World"
System
System utilities and standard I/O streams.
Fields
Standard output stream.
Standard error stream.
PrintStream Methods
Prints with newline.
Prints without newline.
Formatted print.
Time Methods
Returns current time in milliseconds since Unix epoch.
Returns high-resolution time for measuring elapsed time.
Other Methods
Terminates the JVM with the given exit code.
Suggests garbage collection (not guaranteed).
Gets a system property.
Gets an environment variable.
Copies array elements from source to destination.
Available System Properties
| Property | Value |
|---|---|
java.version | "17" |
java.vendor | "rava2" |
os.name | "Linux" |
line.separator | "\n" |
file.separator | "/" |
user.dir | Current directory |
Math
Mathematical functions and constants.
Constants
Basic Operations
Returns the absolute value.
Returns the greater of two values.
Returns the smaller of two values.
Power and Roots
Returns a raised to the power of b.
Returns the square root.
Returns the cube root.
Returns e raised to the power of a.
Logarithms
Returns the natural logarithm (base e).
Returns the base-10 logarithm.
Trigonometry
Trigonometric functions (argument in radians).
Inverse trigonometric functions.
Returns the angle theta from polar coordinates.
Angle unit conversion.
Rounding
Returns largest integer less than or equal to a.
Returns smallest integer greater than or equal to a.
Returns the closest integer.
Other
Returns a random double between 0.0 (inclusive) and 1.0 (exclusive).
Returns -1.0, 0.0, or 1.0 based on sign.
Returns sqrt(x² + y²) without overflow.
Thread
Thread of execution in a program.
Constants
Constructor
Creates a thread with the given runnable task.
Instance Methods
Starts the thread execution.
Waits for this thread to complete.
Tests if the thread is still running.
Gets/sets the thread name.
Gets/sets the thread priority.
Static Methods
Pauses execution for the specified milliseconds.
Hints that the thread is willing to yield its current use of a processor.
Returns a reference to the currently executing thread.
Thread t = new Thread(() -> {
System.out.println("Running in thread");
Thread.sleep(1000);
System.out.println("Done");
});
t.start();
t.join(); // Wait for completion
Wrapper Classes
Integer
Parses a string as an integer.
Returns an Integer instance.
Returns the int value.
Long
Parses a string as a long.
Returns the long value.
Double
Parses a string as a double.
Tests for special values.
Returns the double value.
Boolean
Parses "true" (case-insensitive) as true, anything else as false.
Returns the boolean value.
Character
Character classification methods.
Case conversion methods.
Throwable and Exceptions
Throwable
Returns the detail message.
Returns the cause of this throwable.
Prints the stack trace to standard error.
Exception Hierarchy
ThrowableExceptionRuntimeExceptionNullPointerExceptionArrayIndexOutOfBoundsExceptionIllegalArgumentExceptionNumberFormatException
IllegalStateExceptionArithmeticExceptionClassCastException
IOExceptionClassNotFoundException
Error
Class
Represents classes and interfaces at runtime.
Returns the fully qualified name.
Returns the simple name without package.
Returns the superclass.
Type checking methods.
Creates a new instance using the default constructor.