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
- Hello World Program in Java — the first program everyone writes.
- Add Two Numbers — reading input and printing a sum.
- Check Even or Odd Number — the modulus operator in action.
- Find the Sum of Digits — loops and arithmetic.
- Find the Factorial of a Number — recursion vs iteration.
- Print Prime Numbers — a classic loop exercise.
- Fibonacci Series Program — the most-asked series question.
- Find the Area of a Circle — working with constants and doubles.
- Convert Decimal to Binary — number-system conversion.
- Convert Binary to Decimal — the reverse conversion.
String programs
- Reverse a String — the single most-asked string question.
- Check Whether a String is a Palindrome — two-pointer technique.
- Print Vowels in a String — character iteration.
- Check Whether a String Has All Unique Characters — HashSet thinking.
- Remove Duplicate Characters from a String in O(n) — optimal-time solution.
- Check Balanced Parentheses in O(n) — the stack classic.
Array programs
- Find the Missing Number in an Array — sum-formula trick.
- Find the Second Largest Number in an Array — single-pass logic.
- Print Repeated Numbers in an Array — frequency counting.
- Find Duplicate Elements in an Array — asked in almost every screening.
- Find Common Elements Between Two Arrays — intersection logic.
OOP and language programs
- instanceof Operator Example — runtime type checking.
- Anonymous Class Tutorial — one-off implementations.
- Create Your Own ArrayList — implement add/get/remove/size from scratch.
- Program Using the Comparable Interface — natural ordering.
- Program Using the Comparator Interface — custom ordering.
- How to Create an Immutable Class — final fields, no setters.
- Immutable Classes — Examples — the pattern in practice.
- Why String is Immutable in Java — the design behind the most-asked question.
Collections programs
- HashMap in Java with Example — the workhorse map.
- Hashtable in Java with Example — the legacy synchronized map.
- LinkedHashMap in Java with Example — insertion-order iteration.
- How to Sort a HashMap — sorting by keys and values.
- Ways to Iterate a HashMap — entrySet, keySet, forEach.
- Fail-Fast vs Fail-Safe Iterators — with code for both.
Exception handling programs
- Java Exception Tutorial — try/catch/finally foundations.
- Checked Exceptions in Java — compile-time enforcement.
- Runtime Exceptions in Java — unchecked exceptions.
- Checked vs Unchecked Exceptions — when to use which.
- How to Create a Custom Exception — domain-specific errors.
- ClassNotFoundException vs NoClassDefFoundError — the confusing pair.
Serialization programs
- What is Serialization in Java — objects to bytes.
- Serializable vs Externalizable — control vs convenience.
- The Externalizable Interface — custom serialization.
- The transient Keyword with Example — excluding fields.
Concurrency programs
- BlockingQueue Tutorial — producer-consumer foundation.
- ArrayBlockingQueue Tutorial — bounded blocking queue.
- LinkedBlockingQueue Tutorial — optionally-bounded queue.
- PriorityBlockingQueue Tutorial — ordered concurrent queue.
- SynchronousQueue Tutorial — zero-capacity handoff.
Want the full index? See the Java Programs hub and the Java Interview Prep hub.
Comments
Post a Comment