String.valueOf(Object): turn an object or null into text
This method returns the text `"null"` for a null reference and delegates to the object's `toString()` otherwise. That rule applies to the `Object` overload.
CKTIS / Knowledge base
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
This method returns the text `"null"` for a null reference and delegates to the object's `toString()` otherwise. That rule applies to the `Object` overload.
SynchronousQueue transfers an element directly between threads. Its put and take operations wait for a matching partner rather than using a buffer.
System.arraycopy copies elements into an existing array, supporting overlapping ranges while requiring compatible types and valid bounds.
System.identityHashCode returns an object's identity-based hash code, bypassing an overridden hashCode() method. It returns 0 for null. The result is not a unique identifier and does not replace reference comparison with ==.
System.lineSeparator() returns the system-dependent line separator. Use it when building text with native line endings, but not instead of a separator required by a data format.
System.nanoTime() returns a long reading in nanoseconds. Subtract readings to measure elapsed time, not a date.
Apply calendar rules through LocalDate.with(...). Distinguish next from nextOrSame and find the last day of a month with lastDayOfMonth, without modifying the input date.
The `Thread(Runnable)` constructor creates a platform thread and associates it with a task without starting it. Use `start()` to launch the thread and `join()` to wait for it to finish.
Get the Thread object for the code that is running now, and learn how to restore its interrupt status after catching InterruptedException.
Thread.getName() returns the specified thread's name as a String. The method takes no arguments and does not start the thread.
An interrupt is a signal, not a forced stop. Learn when `InterruptedException` means the interrupt status was cleared and how to restore it.
Use `Thread.join` to wait for a thread to terminate. Learn which overloads confirm termination and when the waiting thread can safely read the worker’s result.
One shared `ThreadLocal` instance keeps a separate value for each thread. Removing a value lets the next read initialize it again, but the mechanism does not copy objects.
Create platform threads from Runnable tasks, start them once, read their results after joining, and handle cooperative cancellation without losing interrupt status.
Thread.onSpinWait() tells the runtime that a loop is busy-waiting. It may enable an optimization, but it neither replaces synchronization nor guarantees a speedup.
ThreadPoolExecutor manages a worker pool and a task queue. Learn when it creates threads or queues work, how ThreadPoolExecutor.CallerRunsPolicy handles overload, and how shutdown() and awaitTermination() support orderly termination.
Give worker threads names such as `worker1`, `worker2`, and `worker3` so you can tell them apart in logs and while debugging.
`Thread.sleep(long)` pauses the current thread for a requested number of milliseconds. It does not wait for another thread to finish or guarantee task order.
`Thread.start()` schedules code to run in a separate thread. Calling `run()` directly does not start a thread; use `join()` when you need to wait for it to finish.
`getCause()` returns an exception’s immediate cause or `null`. Call it on an `ExecutionException` to inspect the exception thrown by the task.
`getMessage()` returns an exception’s detail message, or `null` if there is no message. Calling the method does not print anything.
Use `getSuppressed()` to read secondary exceptions recorded on a primary exception, such as when both a `try` block and automatic resource cleanup fail.
Use `TimeUnit.MILLISECONDS` to give `tryLock` a timeout in milliseconds. Each call gets its own timeout and can acquire the lock immediately.
Convert milliseconds to nanoseconds and pass the matching unit when setting a timeout for `tryLock`.