Loading…
Loading…
Topic
Articles and problems tagged Exceptions and Logging.
The Lock framework and coordination tools for the OCP 21 exam: ReentrantLock with lock, unlock and tryLock, fairness, hold counts, IllegalMonitorStateException, ReentrantReadWriteLock, CyclicBarrier with barrier actions, plus CountDownLatch and Semaphore.
try-with-resources for the OCP 21 exam: AutoCloseable versus Closeable, declaring resources, var and effectively final resources, scope, reverse closing order, the implicit finally, close() exceptions, suppressed exceptions and what happens when a finally block throws.
Handling exceptions for the OCP 21 exam: try and catch syntax, ordering chained catch blocks, unreachable catches, multi-catch rules, finally execution order, return values and finally, exceptions thrown from finally, System.exit, wrapping causes and rethrowing.
The exception classes the OCP 21 exam expects you to recognize: ArithmeticException, ArrayIndexOutOfBounds, ClassCastException, NullPointerException, IllegalArgument and NumberFormat, IOException and FileNotFound, ParseException, and Errors like StackOverflowError and ExceptionInInitializerError.
Exception fundamentals for the OCP 21 exam: the Throwable hierarchy, checked versus unchecked, the handle-or-declare rule, throw versus throws, unreachable catch blocks, exception rules for overriding methods and constructors, custom exceptions and printing exceptions.
How Graphics2D renders: the stroke, transform, clip, fill and compose pipeline, rendering hints, the Shape hierarchy with Float and Double classes, rectangles, ellipses, arcs, curves, Path2D with winding rules, and combining shapes with Area.
Run SQL with Statement: executeUpdate, executeQuery and execute, reading ResultSet rows with typed getters, column labels, NULL handling and java.time, closing resources, query timeouts and fetch sizes, and analyzing SQLException chains, SQLStates, subclasses and warnings.
Go deeper into java.util.logging: ConsoleHandler and FileHandler, log file patterns and rotation, handler levels, filters, custom formatters and handlers, the SimpleFormatter format string, LogRecord details, and a practical logging recipe for real applications.
Get started with logging in Java: frontends versus backends, the platform System.Logger API, log levels, lazy messages with suppliers, logging exceptions, MessageFormat placeholders, and configuring java.util.logging with logging.properties and logger hierarchies.
Learn Java assertions: the two forms of the assert statement, enabling them with -ea and -da per class or package, why conditions must have no side effects, when to assert versus throw, preconditions, documenting assumptions, and the ClassLoader assertion API.
Practical Java exception handling best practices: don't use exceptions for control flow, keep try blocks coarse, use precise types, never swallow exceptions, throw early and catch late, validate with Objects methods, and keep stack traces away from users.
Learn how Java's finally clause runs on every path, why return in finally is a trap, how try-with-resources closes AutoCloseable resources in reverse order with suppressed exceptions, and how to read and walk stack traces with StackWalker.
Master catching exceptions in Java: how try/catch changes control flow, when to catch versus propagate, ordering multiple catch clauses, multi-catch with |, unnamed catch variables, and rethrowing, wrapping and chaining exceptions without losing the cause.
Learn how to throw exceptions in Java with the throw statement, pick the right standard exception, write your own checked or unchecked exception classes with the four conventional constructors, and attach extra data and causes.
Start Java exception handling the right way: why exceptions beat error codes, the Throwable hierarchy with Error, Exception and RuntimeException, checked vs unchecked exceptions, declaring exceptions with throws, and the rules for overriding methods that throw.
Start with Java reflection: what it is for, getting Class objects with getClass, Class.forName and .class literals, odd array type names, comparing Class objects, creating instances by name, a primer on checked exceptions, and loading resources with getResource and getResourceAsStream.