#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
☕ FREE · 15 PROBLEMS

Java Practice Problems: Strings, Collections, OOP and Streams

Write Java for common interview tasks, run it with javac, and check your output against the expected results.

  • 🗂️ Collections and streams
  • 🏦 OOP classes
  • ✅ Output checker

How to use the Java Practice Problems

  1. 1. Pick a problemFilter by level and choose a problem. Its task and sample tests appear below.
  2. 2. Write and run it locallyWrite your Java solution here (it's saved in this browser), then run it with javac and java on each sample input.
  3. 3. Check your outputPaste what your program printed for each test and press Check. Solved problems get a tick.

What you'll practise

The problems move from basics (reversing a string, palindrome numbers, FizzBuzz, leap years) to the collections interviewers love (character counts with TreeMap, duplicates with HashSet, grouping anagrams with LinkedHashMap), algorithms (Kadane's maximum subarray, the missing number, a sieve of Eratosthenes), object-oriented design (a BankAccount with encapsulated balance, sorting students with a Comparator), and the Stream API.

Every solution uses a public class Main and was compiled with javac and run against its sample tests.

Worked example: bank account class

The input opens an account with 1000, then runs three operations: withdraw 300, withdraw 900 and deposit 50. The expected output is Insufficient funds followed by 750: the first withdrawal leaves 700, the second is refused because 900 is more than 700, and the deposit brings the balance to 750. The point of the exercise is encapsulation: the balance is private, and only deposit and withdraw can change it.

Tips for Java coding rounds

  • Read input with Scanner for practice; for very large inputs, BufferedReader is faster.
  • Use long wherever sums can pass about 2.1 billion.
  • Build big outputs in a StringBuilder and print once.
  • Before submitting anywhere, test the edge cases the samples hint at: an empty line, a single element, all-negative numbers or the largest allowed input.

Frequently asked questions

Which Java version do I need?

Java 17 or later; one solution uses a record.

Why must the class be called Main?

Most online judges and the run command here expect it. If you rename it, rename the file too.

Is my code sent anywhere?

No. It stays in this browser.

Is the Java practice problems free?

Yes. Everything in the Java practice problems works without signing up. The first time you ask for a result, we ask once for your name and WhatsApp number; after that the Java practice problems and every other Uncodemy tool open straight away.

More free tools

See all free tools