50 Java Programs for Beginners with Output

50 Java programs with output, organized by topic — the coding questions asked in interviews, written tests, and beginner assignments. Each program links to a full tutorial with code and output. Updated September 2026.

Basic programs

  1. Hello World Program in Java — the first program everyone writes.
  2. Add Two Numbers — reading input and printing a sum.
  3. Check Even or Odd Number — the modulus operator in action.
  4. Find the Sum of Digits — loops and arithmetic.
  5. Find the Factorial of a Number — recursion vs iteration.
  6. Print Prime Numbers — a classic loop exercise.
  7. Fibonacci Series Program — the most-asked series question.
  8. Find the Area of a Circle — working with constants and doubles.
  9. Convert Decimal to Binary — number-system conversion.
  10. Convert Binary to Decimal — the reverse conversion.

String programs

  1. Reverse a String — the single most-asked string question.
  2. Check Whether a String is a Palindrome — two-pointer technique.
  3. Print Vowels in a String — character iteration.
  4. Check Whether a String Has All Unique Characters — HashSet thinking.
  5. Remove Duplicate Characters from a String in O(n) — optimal-time solution.
  6. Check Balanced Parentheses in O(n) — the stack classic.

Array programs

  1. Find the Missing Number in an Array — sum-formula trick.
  2. Find the Second Largest Number in an Array — single-pass logic.
  3. Print Repeated Numbers in an Array — frequency counting.
  4. Find Duplicate Elements in an Array — asked in almost every screening.
  5. Find Common Elements Between Two Arrays — intersection logic.

OOP and language programs

  1. instanceof Operator Example — runtime type checking.
  2. Anonymous Class Tutorial — one-off implementations.
  3. Create Your Own ArrayList — implement add/get/remove/size from scratch.
  4. Program Using the Comparable Interface — natural ordering.
  5. Program Using the Comparator Interface — custom ordering.
  6. How to Create an Immutable Class — final fields, no setters.
  7. Immutable Classes — Examples — the pattern in practice.
  8. Why String is Immutable in Java — the design behind the most-asked question.

Collections programs

  1. HashMap in Java with Example — the workhorse map.
  2. Hashtable in Java with Example — the legacy synchronized map.
  3. LinkedHashMap in Java with Example — insertion-order iteration.
  4. How to Sort a HashMap — sorting by keys and values.
  5. Ways to Iterate a HashMap — entrySet, keySet, forEach.
  6. Fail-Fast vs Fail-Safe Iterators — with code for both.

Exception handling programs

  1. Java Exception Tutorial — try/catch/finally foundations.
  2. Checked Exceptions in Java — compile-time enforcement.
  3. Runtime Exceptions in Java — unchecked exceptions.
  4. Checked vs Unchecked Exceptions — when to use which.
  5. How to Create a Custom Exception — domain-specific errors.
  6. ClassNotFoundException vs NoClassDefFoundError — the confusing pair.

Serialization programs

  1. What is Serialization in Java — objects to bytes.
  2. Serializable vs Externalizable — control vs convenience.
  3. The Externalizable Interface — custom serialization.
  4. The transient Keyword with Example — excluding fields.

Concurrency programs

  1. BlockingQueue Tutorial — producer-consumer foundation.
  2. ArrayBlockingQueue Tutorial — bounded blocking queue.
  3. LinkedBlockingQueue Tutorial — optionally-bounded queue.
  4. PriorityBlockingQueue Tutorial — ordered concurrent queue.
  5. SynchronousQueue Tutorial — zero-capacity handoff.

Want the full index? See the Java Programs hub and the Java Interview Prep hub.

Comments

Popular posts from this blog

Java Banking Finance Services and Insurance (BFSI) domain interview questions

JSP Servlet Interview Questions For Freshers Series 1

Java program to check even or odd number