Loading…
Loading…
Language
Articles and problems tagged Java.
Exit loops early with break, skip to the next iteration with continue, and escape nested loops with labeled break and labeled continue. Covers why Java has no goto, labeled blocks, how continue behaves in for loops, and cleaner alternatives such as extracting a method.
Java's switch statement explained: arrow-form switch statements for menus, the classic colon form with break and fall-through, -Xlint:fallthrough, the four forms of switch (statement or expression, arrow or colon), why yield exists, and which form to choose.
Repeat work in Java with while, do-while and for loops: how each one tests its condition, a savings-target calculator, counting team combinations, counting down, the scope of loop variables, floating-point loop traps, infinite loops, and how to choose the right loop.
How Java blocks define variable scope (and why you can't redeclare a variable in a nested block), and how to make decisions with if, if/else and if/else if chains, including the dangling else, braces style, and common pitfalls like a stray semicolon.
Read text files with Scanner and Path.of, write them with PrintWriter, and use the modern Files.readString, readAllLines and writeString. Covers UTF-8 and character encodings, relative paths and the working directory, throws IOException, try-with-resources, and shell redirection.
Read keyboard input with Scanner (nextLine, next, nextInt, hasNextInt) and avoid the nextInt/nextLine trap, read passwords with Console, and format output precisely with printf, String.format and formatted: conversions, flags, width, precision, argument indexes and locales.
A working tour of the String API (strip, startsWith, replace, indexOf ranges, formatted, lines, isBlank and more), how to read the Javadoc, iterating over code points correctly, building strings fast with StringBuilder, and writing multi-line text with text blocks.
The essentials of Java's String class: joining strings with + and String.join, repeat and split, indexes and substring, why strings are immutable and shared, why you must compare strings with equals instead of ==, compareTo, and empty vs null strings.
Choose among many values with Java's switch expression: the arrow syntax, selector types, several labels per case, enums without prefixes, exhaustiveness and default, blocks with yield, throwing from a case, and handling null with case null.
A complete guide to the remaining Java operators: ++ and -- in prefix and postfix form, comparisons, && || ! and short-circuit evaluation, the ?: conditional operator, bitwise & | ^ ~ and shifts, plus the full operator precedence table.
When Java converts numbers automatically and when you need a cast. Covers widening conversions and precision loss, the rules for mixed-type expressions, casts and how they truncate, out-of-range casts, compound assignment's hidden cast, and assignment as an expression.
How + - * / % behave in Java, why 15 / 2 is 7, how remainder works with negative numbers, when to use Math.floorMod and floorDiv, the most useful Math methods (pow, sqrt, round, clamp…), overflow-safe exact methods, and StrictMath.
How to declare and initialize variables in Java, the naming rules, why the compiler rejects uninitialized variables, local type inference with var, constants with final and static final, and a first look at enumerated types.
A complete Java keywords list for Java 21+: all 51 reserved keywords, 17 contextual keywords such as var, record, sealed and yield, and the literals true, false and null, with meanings, the version that introduced each and links to the lessons.
Finish the Java module system: requires transitive and aggregator modules, requires static, qualified exports and opens, ServiceLoader with uses and provides, then jdeps, jlink custom runtime images and JMOD files, with a complete runnable example.
Migrate Java applications to modules step by step: automatic modules from plain JARs, how their names are derived, Automatic-Module-Name, the unnamed module and class path, bottom-up migration, and the --add-exports, --add-opens and @argfile launcher options.
Package Java modules as modular JARs with jar, --module-version and a main class, then learn why deep reflection fails across modules and fix it with opens, open modules, resource access rules and MethodHandles.Lookup.
Declare Java module dependencies with requires and publish packages with exports: the "package is not visible" error, the module graph and readability, why requires is not transitive, hiding implementation packages, compiling and running multi-module apps, and split packages.
Get started with the Java Platform Module System (JPMS): why modules exist, strong encapsulation and reliable configuration, how to name modules, write module-info.java, compile a modular Hello World and run it with --module-path and --module.
Process annotations at the bytecode level: the class file format, javap, CLASS-retention annotations, inserting logging code with ASM's AdviceAdapter, the new Class-File API, and rewriting classes at load time with a Java agent and ClassFileTransformer.