Java reference
Java reference
Java functions, classes and methods: syntax, parameters, return values and examples.
Keywords and operators
- @DeprecatedMarks an outdated class, method or field. The compiler warns when they are used.
- @FunctionalInterfaceMarks an interface with exactly one abstract method — it can be implemented with a lambda.
- @OverrideMarks a method that overrides a method of a parent class or interface. The compiler checks that it really does.
- @SuppressWarningsTurns off chosen compiler warnings for a class, method or variable.
- abstractMarks a class that cannot be instantiated and a method without a body that subclasses implement.
- public / protected / privateAccess modifiers control where a class, field, method or constructor is visible from.
- assertA check of an internal program condition. Disabled by default, enabled with the -ea option.
- break / continuebreak exits a loop, continue jumps to the next iteration; a label lets you leave a nested loop.
- classDeclares a class — a description of objects: their fields and methods.
- enumDeclares an enum — a type with a fixed set of values.
- extendsDeclares inheritance: the class gets the parent's fields and methods.
- finalForbids reassigning a variable, overriding a method or extending a class.
- forA loop with a counter, or iteration over every element of an array or collection (for-each).
- if / elseRuns a block of code only if a condition is true.
- implementsLists the interfaces that a class implements.
- import / packagepackage sets the file's package, import lets you use short names of classes from other packages.
- instanceofChecks whether an object is an instance of a type and binds a variable of that type.
- interfaceDeclares an interface — a set of methods that a class promises to implement.
- module / requires / exportsA module declaration in module-info.java: which modules it needs and which packages it exposes to others.
- newCreates a new object or array and calls the constructor.
- returnEnds a method and gives a value back to the caller.
- sealed / permitsRestricts which classes may extend a class or implement an interface.
- staticMakes a field or method belong to the class itself rather than to each object.
- superRefers to the parent class: calls its constructor or its version of a method.
- switchPicks a branch by value; as an expression it returns a result.
- thisA reference to the current object — the one whose method or constructor is running.
- throwThrows an exception and stops the method.
- throwsDeclares which checked exceptions a method may throw.
- try / catch / finallyCatches exceptions; finally always runs, and try-with-resources closes resources for you.
- varDeclares a local variable whose type the compiler infers from the value.
- while / do-whileRepeats a block while a condition is true; do-while runs it at least once.
- yieldReturns a value from a block inside a switch expression.
- & | ^ ~ << >> >>>Bitwise operators work with individual bits of integers: AND, OR, XOR, NOT and shifts.
- += -= *= /=Performs an operation and stores the result back in the same variable.
- == vs equals()== compares primitive values and object references; equals() compares object contents.
- ++ / --Increases or decreases a variable by one.
- && || !Logical AND, OR and NOT for boolean values.
- %Returns the remainder of a division.
- ? :Picks one of two values by a condition — a short form of if-else.
Strings
- Character.isDigit()Checks whether a character is a digit. Related checks are isLetter(), isWhitespace(), isUpperCase().
- Text block """A multi-line string literal in triple quotes.
- StringBuilderA mutable string: useful when text is built piece by piece, especially in a loop.
- StringBuilder.append()Adds a value to the end of a StringBuilder.
- StringBuilder.deleteCharAt()Removes one character at an index. For a range there is delete(start, end).
- StringBuilder.insert()Inserts a value at the given position of a StringBuilder.
- StringBuilder.reverse()Reverses the contents of a StringBuilder.
- StringBuilder.toString()Returns the contents of a StringBuilder as a regular String.
- String.charAt()Returns the character at the given index.
- String.chars()Returns a stream of the character codes of a string.
- String.codePoints()Returns a stream of Unicode code points. Unlike chars(), an emoji counts as one character.
- String.compareTo()Compares two strings in dictionary (lexicographic) order.
- String.contains()Checks whether a string contains a substring.
- String.endsWith()Checks whether a string ends with the given suffix.
- String.equals()Compares the contents of two strings.
- String.equalsIgnoreCase()Compares two strings ignoring letter case.
- String.format()Builds a string from a template with placeholders such as %s and %d.
- String.formatted()Uses the string itself as a template and fills it in — a shorter form of String.format().
- String.indent()Adds or removes n spaces at the start of every line of text.
- String.indexOf()Finds the position of the first occurrence of a character or a substring.
- String.isBlank()Checks whether a string is empty or contains only whitespace.
- String.isEmpty()Checks whether the string length is zero.
- String.join()Joins strings with a separator.
- String.lastIndexOf()Finds the position of the last occurrence of a character or a substring.
- String.length()Returns the number of characters in a string.
- String.lines()Splits a string at line breaks and returns the lines as a stream.
- String.repeat()Repeats a string the given number of times.
- String.replace()Replaces every occurrence of a substring or a character with another string.
- String.replaceAll()Replaces every match of a regular expression.
- String.split()Splits a string into an array of parts by a separator.
- String.startsWith()Checks whether a string starts with the given prefix.
- String.strip()Removes any Unicode whitespace from both ends of a string.
- String.substring()Returns the part of a string between two indexes.
- String.toCharArray()Copies the characters of a string into a new char[] array.
- String.toLowerCase()Returns a copy of the string with all letters in lower case.
- String.toUpperCase()Returns a copy of the string with all letters in upper case.
- String.trim()Removes spaces and control characters from both ends of a string.
- String.valueOf()Converts a value of any type to a string.
Numbers and Math
- BigDecimalAn exact decimal number — for money and calculations where double rounding errors are unacceptable.
- BigIntegerAn integer of any size — for when even long is not enough.
- Double.parseDouble()Converts a string with a decimal number to a double.
- Integer.compare()Compares two int values: negative means x is smaller, 0 means equal, positive means x is larger.
- Integer.MAX_VALUEThe largest int value; its partner is Integer.MIN_VALUE.
- Integer.parseInt()Converts a string containing an integer to an int.
- Integer.toBinaryString()Writes a number in binary. Related methods are toHexString() and toOctalString().
- Integer.valueOf()Returns an Integer wrapper object for a string or an int.
- Long.parseLong()Converts a string with an integer to a long — for numbers that do not fit in an int.
- Math.abs()Returns the absolute value of a number — the value without a minus sign.
- Math.addExact()Adds two numbers and throws ArithmeticException on overflow. See also multiplyExact() and toIntExact().
- Math.ceil()Rounds up to the nearest integer that is greater than or equal.
- Math.clamp()Limits a number to a range: below min returns min, above max returns max.
- Math.floor()Rounds down to the nearest integer that is less than or equal.
- Math.floorMod()A remainder that always has the sign of the divisor.
- Math.max()Returns the larger of two numbers.
- Math.min()Returns the smaller of two numbers.
- Math.pow()Raises a number to a power.
- Math.random()Returns a random decimal number from 0 (inclusive) to 1 (exclusive).
- Math.round()Rounds a number to the nearest integer.
- Math.sqrt()Returns the square root of a number.
- NumberFormatFormats numbers, money and percentages by the rules of a chosen country.
- RandomA random number generator: integers in a range, decimals, booleans.
- ThreadLocalRandomA ready random number generator that you do not need to create; fast in multithreaded code too.
Arrays
- array.lengthThe length of an array — the number of elements. A field, not a method: no parentheses.
- Arrays.asList()Returns a fixed-size list backed by an array.
- Arrays.binarySearch()Quickly finds a value in a sorted array by repeatedly halving it.
- Arrays.copyOf()Copies an array into a new one of the same or another length. copyOfRange() copies a part.
- Arrays.equals()Compares the contents of two arrays element by element.
- Arrays.fill()Fills the whole array or part of it with one value.
- Arrays.sort()Sorts an array in place — in ascending order or by a given comparator.
- Arrays.stream()Creates a stream from an array — for sums, filters and transformations.
- Arrays.toString()Returns the contents of an array as a string like [1, 2, 3].
- System.arraycopy()Copies part of one array into another (or the same) array.
Lists
- ArrayListA resizable list backed by an array — the most common `List` implementation.
- LinkedListA doubly linked list that implements both `List` and `Deque`.
- List.add()Adds an element to the end of a list or at a given position.
- List.addAll()Adds all elements of another collection to a list.
- List.contains()Checks whether a list contains an element.
- List.copyOf()Creates an unmodifiable list copy of a collection.
- List.get()Returns the list element at an index.
- List.getFirst()Returns the first or the last element of an ordered collection.
- List.indexOf()Finds the position of an element in a list.
- List.isEmpty()Checks whether a list is empty.
- List.of()Creates an unmodifiable list from the listed elements.
- List.remove()Removes a list element by index or by value.
- List.replaceAll()Replaces every list element with the result of a function.
- List.reversed()Returns the list in reverse order without copying it.
- List.set()Replaces the list element at an index.
- List.size()Returns the number of elements in a list.
- List.sort()Sorts a list in place using a given rule.
- List.subList()Returns the part of a list between two indexes.
Sets
- EnumSetA set of values of one enum. Works like a set of bit flags, but with readable code.
- HashSetA set without duplicates backed by a hash table; order is not guaranteed.
- LinkedHashSetA set that remembers the insertion order of elements.
- Set.add()Adds an element if it is not in the set yet.
- Set.addAll()Merges a set with another collection (union).
- Set.contains()Checks whether a set contains an element.
- Set.copyOf()Creates an unmodifiable set from a collection, dropping duplicates.
- Set.of()Creates an unmodifiable set from the listed elements.
- Set.remove()Removes an element from a set.
- Set.removeAll()Removes all elements of another collection from a set (difference).
- Set.retainAll()Keeps only the elements that are also in another collection (intersection).
- TreeSetA set that keeps its elements in sorted order.
Maps
- EnumMapA map whose keys are values of one enum. Fast, and keeps keys in declaration order.
- HashMapA map backed by a hash table: fast lookup by key, no guaranteed order.
- LinkedHashMapA map that remembers the insertion order of keys.
- Map.compute()Computes a new value for a key from the old one (or from null if the key is absent).
- Map.computeIfAbsent()Returns the value for a key, creating it with a function if the key is absent.
- Map.computeIfPresent()Changes the value for a key only if the key is already in the map.
- Map.containsKey()Checks whether a map has a key.
- Map.EntryA single key and value pair of a map.
- Map.entrySet()Returns all key and value pairs for iteration.
- Map.forEach()Runs an action for every pair of a map.
- Map.get()Returns the value for a key, or `null`.
- Map.getOrDefault()Returns the value for a key, or a fallback when the key is absent.
- Map.keySet()Returns the set of all keys of a map.
- Map.merge()Adds a value under a key or combines it with the existing one.
- Map.of()Creates an unmodifiable map from key and value pairs.
- Map.put()Stores a value under a key, replacing the old one.
- Map.putIfAbsent()Stores a value only if the key is not present yet.
- Map.remove()Removes a pair by its key.
- Map.values()Returns a collection of all values of a map.
- TreeMapA map whose keys are always sorted.
Collections: general
- ArrayDequeA fast array-based double-ended queue — a replacement for `Stack` and `LinkedList`.
- Collection.removeIf()Removes all collection elements that match a condition.
- Collection.toArray()Copies collection elements into an array.
- Collections.emptyList()Returns an empty unmodifiable list. See also emptyMap() and emptySet().
- Collections.frequency()Counts how many times an element occurs in a collection.
- Collections.max()Finds the largest element of a collection.
- Collections.min()Finds the smallest element of a collection.
- Collections.nCopies()Returns an unmodifiable list of n identical elements.
- Collections.reverse()Reverses the order of list elements in place.
- Collections.shuffle()Shuffles list elements into a random order.
- Collections.sort()Sorts a list in place.
- Collections.unmodifiableList()Returns a view of a list that cannot be modified.
- DequeA double-ended queue: elements can be added and taken at both ends.
- Deque.pop()Removes and returns the element at the top of a stack.
- Deque.push()Pushes an element onto the top of a stack (the head of a deque).
- IterableThe interface of everything that a for-each loop can iterate over.
- IteratorAn object that hands out collection elements one by one.
- PriorityQueueA queue that always hands out the smallest (or highest-priority) element.
- QueueA queue: elements are added at the tail and taken from the head.
- Queue.offer()Adds an element to the tail of a queue.
- Queue.peek()Returns the head of a queue without removing it.
- Queue.poll()Takes and removes the head of a queue.
Stream API
- Collection.parallelStream()Returns a parallel stream: elements are processed in several threads at once.
- Collection.stream()Creates a stream over the elements of a collection.
- Collectors.averagingDouble()A collector that computes the mean of a numeric field.
- Collectors.counting()A counting collector, usually used inside `groupingBy()`.
- Collectors.flatMapping()Turns each element into a stream and gathers all values with another collector. See also filtering().
- Collectors.groupingBy()A collector that sorts elements into groups that share a key.
- Collectors.joining()A collector that joins the strings of a stream into one.
- Collectors.mapping()Transforms elements before passing them to another collector. Most often used inside groupingBy.
- Collectors.partitioningBy()Splits stream elements into two groups by a condition.
- Collectors.summingInt()A collector that sums a numeric field of the elements.
- Collectors.teeing()Sends each element to two collectors at once and combines their results.
- Collectors.toList()A collector that puts stream elements into a list.
- Collectors.toMap()A collector that builds a map from stream elements.
- Collectors.toSet()A collector that puts stream elements into a set without duplicates.
- IntStream.average()Computes the arithmetic mean of the numbers in a stream.
- IntStream.boxed()Turns a stream of int primitives into a stream of Integer objects.
- IntStream.range()Creates a stream of integers from a range.
- IntStream.sum()Adds up all numbers of a stream.
- Stream.allMatch()Checks whether all elements match a condition.
- Stream.anyMatch()Checks whether at least one element matches a condition.
- Stream.collect()Gathers stream elements into a collection, a string or another structure.
- Stream.count()Counts the elements of a stream.
- Stream.distinct()Removes duplicate elements from a stream.
- Stream.dropWhile()Drops elements while a condition holds and passes on everything after.
- Stream.filter()Keeps only the stream elements that match a condition.
- Stream.findFirst()Returns the first stream element as an `Optional`.
- Stream.flatMap()Turns each element into a stream and joins all streams into one.
- Stream.forEach()Runs an action for every stream element (a terminal operation).
- Stream.gather()Applies a custom intermediate operation to a stream, such as splitting it into groups of N.
- Stream.generate()Creates an infinite stream from the values of a supplier function.
- Stream.iterate()Creates a stream where each element is computed from the previous one.
- Stream.limit()Truncates a stream to its first N elements.
- Stream.map()Transforms every element of a stream.
- Stream.mapToInt()Turns a stream of objects into a stream of `int` numbers.
- Stream.max()Finds the largest element of a stream.
- Stream.min()Finds the smallest element of a stream.
- Stream.noneMatch()Checks that no element matches a condition.
- Stream.of()Creates a stream from the listed values.
- Stream.reduce()Folds all stream elements into a single value.
- Stream.skip()Skips the first N elements of a stream.
- Stream.sorted()Sorts the elements of a stream.
- Stream.takeWhile()Takes elements while a condition holds and stops at the first one that fails it.
- Stream.toList()Gathers stream elements into an unmodifiable list.
Optional and functional interfaces
- BiFunctionA function of two arguments.
- BinaryOperatorA two-argument function whose arguments and result share a type.
- ConsumerAn action that takes a value and returns nothing.
- FunctionA function that takes a value of type `T` and returns a value of type `R`.
- -> (lambda)A lambda expression — a short function that can be passed around as a value.
- :: (method reference)A method reference — an even shorter replacement for a lambda that only calls a method.
- OptionalA container that either holds a value or is empty — a replacement for returning `null`.
- Optional.empty()Returns an empty `Optional` — no value.
- Optional.ifPresent()Runs an action only if a value is present.
- Optional.isPresent()Checks whether an `Optional` holds a value.
- Optional.map()Transforms the value inside an `Optional` if there is one.
- Optional.of()Creates an `Optional` holding a non-null value.
- Optional.ofNullable()Wraps a value that may be `null` into an `Optional`.
- Optional.orElse()Returns the value, or a fallback if there is none.
- Optional.orElseGet()Returns the value, or calls a function to create a fallback.
- Optional.orElseThrow()Returns the value or throws an exception if there is none.
- PredicateA condition: a function that takes a value and returns a `boolean`.
- RunnableA task with no arguments and no result.
- SupplierA supplier: a no-argument function that returns a value.
- UnaryOperatorA function whose argument and result have the same type.
Classes, Object and records
- CloneableA marker interface that allows Object.clone(). New code uses copy constructors instead.
- Comparable.compareTo()Defines the natural order of a class — used by sort() and TreeSet.
- Comparator.comparing()Creates a comparator that compares objects by one key.
- Comparator.reversed()Returns a comparator with the opposite order. For the natural order there is Comparator.reverseOrder().
- Comparator.thenComparing()Adds a second sort criterion — for objects equal by the first one.
- Enum.values()Methods of every enum: values() gives all constants, valueOf() finds one by name, ordinal() and name() give its index and name.
- recordDeclares a record — an immutable data class with ready-made equals(), hashCode() and toString().
- Object.equals()Compares objects by meaning. By default it works like ==, so classes override it.
- Object.getClass()Returns the runtime class of an object.
- Object.hashCode()Returns the object's hash code — a number HashMap and HashSet use to find it quickly.
- Object.toString()Returns a text form of the object; called when printing and when concatenating with a string.
- Objects.equals()Compares two objects with equals(), safely for null.
- Objects.hash()Computes a hash code from several values — for implementing hashCode().
- Objects.isNull()Checks whether a value is null; its partner nonNull() does the opposite.
- Objects.requireNonNull()Checks that a value is not null and throws NullPointerException with a clear message right away.
- UUID.randomUUID()Creates a random UUID — a 128-bit identifier that practically never repeats.
Exceptions
- ArithmeticExceptionThrown on an invalid arithmetic operation, such as integer division by zero.
- ArrayIndexOutOfBoundsExceptionThrown when an array is accessed at an index that does not exist.
- AutoCloseableThe interface of a resource that can be closed by try-with-resources.
- ExceptionThe base class of exceptions a program can catch and handle.
- IllegalArgumentExceptionSignals that a method received an invalid argument.
- IllegalStateExceptionSignals that a method was called at the wrong time — the object is in the wrong state.
- IndexOutOfBoundsExceptionThrown when a list or a string is accessed at an index outside the valid range.
- IOExceptionA checked exception for input and output errors: files, network, data streams.
- NullPointerExceptionThrown when a method or field is accessed through a `null` reference.
- NumberFormatExceptionThrown when a string cannot be converted to a number.
- RuntimeExceptionThe base class of unchecked exceptions — bugs in program logic.
- Throwable.getCause()Returns the original exception wrapped by the current one.
- Throwable.getMessage()Returns the message text of an exception.
- Throwable.printStackTrace()Prints the exception and the chain of calls that led to it to the error stream.
- try-with-resourcesA `try` block that closes opened resources automatically — files, connections, streams.
- UncheckedIOExceptionAn unchecked wrapper around `IOException`, needed where checked exceptions are not allowed, such as in lambdas.
- UnsupportedOperationExceptionThrown when an operation is not supported by the object, such as changing an unmodifiable collection.
Input, output and files
- BufferedReaderReads text line by line with buffering — the classic way to process large files.
- Connection.setAutoCommit()Turns auto-commit on or off. With false several queries form a transaction: commit() or rollback().
- DriverManager.getConnection()Opens a connection to a database by its JDBC URL.
- Files.copy()Copies a file. By default it does not overwrite an existing file.
- Files.createDirectories()Creates a folder together with all missing parent folders.
- Files.delete()Deletes a file or an empty folder. deleteIfExists() does not throw if the file is missing.
- Files.exists()Checks whether a file or folder exists. Related: isDirectory(), isRegularFile(), size().
- Files.lines()Reads a file lazily as a stream of lines, without loading it into memory.
- Files.list()Returns a stream of the files and folders inside a folder (not nested). Files.walk() goes recursively.
- Files.move()Moves or renames a file or a folder.
- Files.readAllLines()Reads a text file into a list of lines.
- Files.readString()Reads a whole text file into one string.
- Files.walk()Walks a folder and all nested folders and returns a stream of every path found.
- Files.writeString()Writes a string to a file, creating or overwriting it.
- HttpClientThe built-in HTTP client: sends requests synchronously (send) or asynchronously (sendAsync).
- HttpRequestAn immutable HTTP request: address, method, headers and body. Created with newBuilder().
- HttpResponseThe server response: the status code, headers and a body of the type chosen by the BodyHandler.
- IO.print()Prints a value to the console without ending the line.
- IO.println()Prints a value to the console and ends the line.
- IO.readln()Prints a prompt and reads a line typed by the user.
- Path.of()Creates a Path object — a path to a file or folder.
- PreparedStatementA precompiled SQL query with ? parameters. Protects against SQL injection.
- ResultSetThe result of a SELECT query: a cursor that walks through the rows one by one.
- Runtime.getRuntime()Returns the Runtime object of the current JVM: memory, processor count, shutdown hooks.
- ScannerReads input piece by piece: whole lines (nextLine) or separate words and numbers.
- Scanner.nextInt()Reads the next integer from the input. Related: nextDouble(), next() and hasNextInt().
- System.exit()Terminates the program immediately with the given exit code.
- System.getProperty()Returns a JVM system property: the Java version, the OS name, or your own property set with -D.
- System.getenv()Returns the value of an environment variable, or null if it is not set.
- System.out.printf()Prints a string built from a template with %s, %d, %.2f placeholders.
- System.out.println()The classic way to print to the console: prints a value and ends the line.
Date and time (java.time)
- ChronoUnit.between()Counts the whole units (days, months, hours) between two dates or moments.
- DateTimeFormatter.ofPattern()Creates a formatter for printing and parsing dates with a pattern such as dd.MM.yyyy.
- DurationAn amount of time in seconds and nanoseconds — hours, minutes, seconds.
- InstantAn exact moment on the UTC timeline — for logs, timestamps and measurements.
- LocalDate.getDayOfWeek()Returns the day of the week of a date.
- LocalDate.now()Returns today's date from the computer's clock and time zone.
- LocalDate.of()Creates a date from a year, month and day.
- LocalDate.parse()Parses a date from a string — in ISO format (2025-03-14) or with a pattern.
- LocalDate.plusDays()Returns a date the given number of days later. Related: minusDays(), plusWeeks(), plusMonths(), plusYears().
- LocalDateTimeA date and time without a time zone — for example, a meeting in a calendar.
- LocalTimeA time of day without a date — for example, a shop's opening time.
- PeriodA calendar amount in years, months and days — for example, an age.
- System.nanoTime()Returns a high-resolution timer value in nanoseconds — for measuring durations. See also currentTimeMillis().
- ZonedDateTimeA date and time in a specific time zone — with daylight saving time taken into account.
Regular expressions
- Matcher.find()Searches for the next match of the pattern anywhere in the string.
- Matcher.group()Returns the text of the current match or of one of its parenthesized groups.
- Matcher.matches()Checks whether the whole string matches the pattern.
- Matcher.replaceAll()Replaces every match with a string or with the result of a function that receives each match.
- Matcher.results()Returns all matches at once as a stream — a short replacement for a find() loop.
- Pattern.compile()Compiles a regular expression into a Pattern object that can be reused many times.
- Pattern.matcher()Creates a Matcher that searches for the pattern in a specific string.
- String.matches()Checks whether the whole string matches a regular expression.
Concurrency
- AtomicIntegerAn integer that can be changed safely from several threads without locks.
- CompletableFuture.join()Waits for the result of a `CompletableFuture`; errors arrive as unchecked exceptions.
- CompletableFuture.supplyAsync()Runs a computation asynchronously and returns a `CompletableFuture`.
- CompletableFuture.thenApply()Adds a step that transforms the result once it is ready.
- CompletableFuture.thenCombine()Combines the results of two independent tasks once both are ready.
- ConcurrentHashMapA thread-safe map for concurrent use from many threads.
- ConcurrentLinkedQueueA thread-safe, non-blocking queue.
- CountDownLatchA counter that lets a thread wait until others have performed N actions.
- ExecutorServiceA service that runs tasks on a pool of threads.
- ExecutorService.close()Closes the pool and waits for all tasks; called automatically by try-with-resources.
- ExecutorService.shutdown()Closes the pool to new tasks and lets accepted ones finish.
- ExecutorService.submit()Sends a task to the pool and immediately returns a `Future` for its result.
- Executors.newFixedThreadPool()Creates a pool with a given number of threads.
- Executors.newVirtualThreadPerTaskExecutor()Creates a service that runs every task in its own virtual thread.
- Future.get()Waits for a task to finish and returns its result.
- InterruptedExceptionA checked exception: a waiting thread was asked to stop.
- synchronizedLets only one thread at a time run a block of code.
- volatileMarks a field whose changes are immediately visible to all threads.
- ReentrantLockAn explicit lock — a flexible replacement for `synchronized`.
- ScopedValueA value available to code only for the duration of a call — for example, the current user of a request. A replacement for ThreadLocal.
- ThreadA thread of execution that lets a program do several things at once.
- Thread.currentThread()Returns the thread that is running the current code.
- Thread.join()Waits for a thread to finish.
- Thread.ofVirtual()Creates a virtual thread — a lightweight thread you can start by the million.
- Thread.sleep()Pauses the current thread for a given time.
- Thread.start()Starts a thread: its code begins running in parallel with the caller.