Here are 30 "write a program" questions drawn from your first 15 topics. I skipped Java Basics, JVM/JDK Tools and a dedicated Garbage Collection block, since they don't lend themselves to full programs (Q24 still covers GC). Each question should be its own .java file with a main method, unless it says otherwise.

Data Types & Variables

  1. Print the min and max of every primitive type. Show int overflow, then detect it safely with Math.addExact in a try/catch. Also show widening, and narrowing by casting 200 to byte.
  2. Demonstrate the Integer cache: compare == and equals for values 127 and 128. Add an autoboxing/unboxing case that throws a NullPointerException, and handle it.
  3. Show why 0.1 + 0.2 != 0.3, then compare doubles using an epsilon. Compute compound interest with BigDecimal, rounded to 2 decimals with HALF_UP.

Operators & Control Statements

  1. Write a bitwise toolkit: check for power of two, count set bits without Integer.bitCount, swap two ints without a temp, reverse the bits of an int, and find the single non-repeating element in an array using XOR.
  2. Evaluate an arithmetic expression string with + - * / and parentheses using two stacks (no scripting engine, no libraries).
  3. In a 2D matrix, use a labeled break to find the first row whose sum is a perfect square, and a labeled continue to skip rows containing a negative number.
  4. Given a month and year, print the number of days using a Java 14+ switch expression with yield, handling leap years correctly.
  5. Create a @FunctionalInterface TriFunction<A,B,C,R>. Build a calculator that maps operator strings to BinaryOperator<Double> lambdas and method references. Show andThen composition and a lambda capturing an effectively final variable.

Arrays

  1. Rotate an N×N matrix 90° clockwise in place, then print it in spiral order.
  2. Implement Kadane's algorithm returning the max sum plus start and end indices. Then extend it to the maximum product subarray.
  3. Build Pascal's triangle for n rows using a jagged array and print it center-aligned.
  4. Merge overlapping intervals from an int[][], sorting with Arrays.sort and a custom comparator.
  5. Implement binary search, first/last occurrence in a sorted array with duplicates, and search in a rotated sorted array, all in O(log n).
  6. Implement the Dutch National Flag algorithm to sort an array of 0s, 1s and 2s in one pass. Add a method that moves all zeros to the end while preserving the order of the rest.

OOP (Classes, Encapsulation, Inheritance, Polymorphism)

  1. Model a bank: Account with private fields, validated deposit/withdraw, transfer between accounts, and an immutable Transaction class. Store history in a plain array that grows when full (no collections).