try-with-resources — automatic resource closing
The try-with-resources statement automatically calls close() on AutoCloseable resources. It defines their usage lifetime and specifies how closing exceptions are handled.
CKTIS / Java
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
The try-with-resources statement automatically calls close() on AutoCloseable resources. It defines their usage lifetime and specifies how closing exceptions are handled.
Java checks type arguments at compile time, but `ArrayList<String>` and `ArrayList<Integer>` do not have separate runtime classes. This distinction explains restrictions on arrays and `instanceof`.
In Java SE 21, a varargs parameter accepts separate arguments or an existing array. With `T...`, type erasure also introduces a risk of heap pollution.
A private `<T>` helper lets you swap two elements of the same `List<?>` without a cast or exposing the element type in the public method signature.
Learn what `?`, `? extends T`, and `? super T` let you read or write, and how Java SE 21 applies those rules to lists, arrays, class tokens, and reference queues.
A Java array is a fixed-length object storing elements of one component type. Learn the T[] declaration, creation with new T[n], zero-based indexing, and shared references.
boolean is a primitive type with two values: true and false. It stores conditions and comparison results. Boolean is its wrapper class; a variable of this type can also hold null, which requires care when automatic unboxing occurs.
The primitive byte type stores integers from -128 to 127. Learn the limits Byte.MIN_VALUE and Byte.MAX_VALUE, the distinction between byte and Byte, promotion to int, and the effects of a narrowing cast.
char is an unsigned primitive integral type that stores one 16-bit UTF-16 code unit. That unit does not necessarily represent a complete Unicode character; characters outside the BMP require a pair of char values.
Character is an immutable wrapper for primitive char values. It also provides static methods for recognizing letters and converting case, with overloads for char values and int code points.
double is Java's primitive 64-bit IEEE 754 binary64 floating-point type. Learn its precision limits, how it differs from Double, and the rules for comparison, maximum selection, and hashing.
float is a Java primitive numeric type based on the 32-bit IEEE 754 binary32 format. It stores approximations of many fractions. Float is its wrapper class, not an alternative spelling of the same type.
int is a primitive signed integer type in Java SE 21. Its range is fixed; integer division normally discards the fractional part, and overflow does not throw an exception.
Integer wraps an int value in an object. Learn creation with valueOf, boxing and unboxing, the sum, max, compare, equals and hashCode methods, and why to avoid the Integer(int) constructor.
The primitive long type stores signed 64-bit integers. Learn the L suffix, the difference between long and Long, and the rules for value equality and hash codes.
A multidimensional array in Java is an array of arrays. T[][] denotes two levels: the outer array stores references to rows, which may have different lengths or be null.
Number is an abstract base class for numeric objects such as Integer. It provides conversion methods to primitive types, including intValue() and doubleValue(); details and potential information loss depend on the subclass.
Object is the root of Java's class hierarchy. Learn the difference between a reference type and an object's class, and how getClass(), wait(), and notifyAll() work with a monitor.
short is a signed primitive integer type ranging from -32768 to 32767. Learn how it differs from the Short wrapper class, why arithmetic promotes it to int, and how narrowing can lose information.
String represents immutable text in Java. Learn content versus reference comparison, value conversion, regular expressions, and explicit byte encoding and decoding.
The `void` keyword indicates that a method returns no value. The method can still perform actions, such as printing text. Do not confuse `void` with the value `null` or with the `java.lang.Void` class.