Java dynamic proxies: chaining reflective method calls
Choose a class loader for an interface proxy, identify the intercepted method, and follow its arguments and result through two handlers to the real service.
CKTIS / Java
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
Choose a class loader for an interface proxy, identify the intercepted method, and follow its arguments and result through two handlers to the real service.
`offer(E e)` tries to insert an element without waiting for space. It returns `true` if the element was added and `false` if no space is available.
Use `peek()` to read the head of a queue without removing it. If the queue is empty, the method returns `null`.
`Queue.poll()` retrieves and removes the head of a queue. If the queue is empty, it returns `null` rather than throwing an exception.
Several threads can read shared data at once, but writing requires exclusive access. Selecting a lock does not acquire it.
RecursiveTask<V> represents a fork/join task that returns a result of type V. Its compute() method defines the computation: handle a small problem directly or split it into subtasks and combine their results.
Distinguish blocking `lock()` from both `tryLock()` overloads, balance every successful acquisition with `unlock()`, and use distinct conditions on the same lock.
Reference provides operations on reference objects. Learn referent retrieval, reference clearing, and strong-reachability control in Java SE 21.
Learn when a reference can return its referent, what enters a reference queue, and how `reachabilityFence` keeps an object strongly reachable.
ReferenceQueue lets you retrieve registered reference objects after the garbage collector or an explicit enqueue() adds them. Learn the difference between nonblocking poll() and the blocking remove() variants.
Reference.reachabilityFence(ref) keeps an object strongly reachable at least until the call completes. It is useful when premature reclamation could interfere with an operation.
Array.newInstance creates arrays from a Class<?> object. It supports primitive types, reference types, and multiple dimensions.
In Java SE 21, `Field` and `Method` let you inspect metadata and annotations, change field values, and invoke methods. Finding a private member does not grant access, and `setAccessible(true)` is subject to module rules.
ResolverStyle controls how parsed fields become a date or time. The behavior of ResolverStyle.STRICT depends on the fields: for an ISO calendar date given as year, month, and day, it rejects February 29 in a non-leap year.
The RuntimeException(Throwable) constructor creates an unchecked exception, preserving the original cause and deriving its message from that cause.
`Scanner.close()` closes a scanner and can also close its input source. Learn when to call it and why shared standard input needs special care.
`Scanner.nextDouble()` reads the next input token as a primitive `double`. The scanner’s locale controls which decimal and grouping separators it recognizes.
Read the next token as an `int`, check whether it is valid before reading, and see why a following `nextLine()` can return an empty string.
`Scanner.nextLine()` returns the rest of the current line without its line separator. Immediately after `nextInt()`, the result can be an empty string.
Set the locale for one scanner so it reads numbers using the conventions of the input, such as a comma as the decimal separator.
SecureRandom generates cryptographically strong random values. nextBytes fills the supplied byte array.
Learn when a semaphore waits for a permit, why `tryAcquire()` differs from `tryAcquire(0)`, and how to avoid adding extra permits during cleanup.
`Set.add` returns `true` when it inserts an element and `false` when an equivalent element is already present. `HashSet` and `TreeSet` identify duplicates differently.
Check whether a set has an element equal to the object you supply, and see why a newly created instance with the same ID can match.