0% found this document useful (0 votes)
5 views2 pages

Core Java Exercises for Backend Development

The document outlines a series of core Java coding exercises focused on backend development, covering topics such as OOP, Collections Framework, Exception Handling, Java 8 features, Multithreading, Generics, File Handling, JDBC Basics, and JVM & Memory. Each section contains specific tasks aimed at enhancing programming skills in Java, including class creation, exception management, stream operations, and database connectivity. The exercises are designed for learners to practice and apply Java concepts effectively.

Uploaded by

Official
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Core Java Exercises for Backend Development

The document outlines a series of core Java coding exercises focused on backend development, covering topics such as OOP, Collections Framework, Exception Handling, Java 8 features, Multithreading, Generics, File Handling, JDBC Basics, and JVM & Memory. Each section contains specific tasks aimed at enhancing programming skills in Java, including class creation, exception management, stream operations, and database connectivity. The exercises are designed for learners to practice and apply Java concepts effectively.

Uploaded by

Official
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

# Core Java Coding Exercises (Backend-Oriented)

## 1. OOP (Classes, Objects, Inheritance, Polymorphism)

1. Create a class `BankAccount` with deposit(), withdraw(), and getBalance(). Create SavingsAccount
& CurrentAccount and override withdraw().

2. Implement a Student class with constructor chaining and a display() method.

3. Implement method overriding for a class hierarchy: Shape → Circle, Rectangle.

4. Demonstrate encapsulation with private fields and getter/setter validation.

5. Create an abstract class Vehicle with abstract start() and stop() methods.

## 2. Collections Framework

6. Write code to find the second largest element in an ArrayList.

7. Implement a custom sorting on a list of Employee objects based on salary.

8. Remove duplicate elements from a List without using Set.

9. Count word frequency using HashMap.

10. Implement an LRU Cache using LinkedHashMap.

## 3. Exception Handling

11. Create a custom exception InvalidAgeException and throw if age < 18.

12. Demonstrate multiple catch blocks for NullPointerException and NumberFormatException.

13. Write a program that reads a number from user and handles input mismatch.

14. Implement a method that throws IOException and handle using try-with-resources.

15. Create a division program that throws custom DivisionByZeroException.

## 4. Java 8 Features

16. Use Streams to filter even numbers from a list.

17. Convert a List to Map where value = length.

18. Use reduce() to compute the sum of all integers in a list.

19. Group employees by department using [Link]().

20. Use Optional to avoid NullPointerException while accessing nested objects.

## 5. Multithreading & Concurrency

21. Create a thread using Thread class and Runnable interface.

22. Print numbers 1–10 from two threads alternately.

23. Use ExecutorService with a fixed thread pool.


24. Demonstrate synchronization by a shared counter incremented by threads.

25. Use CompletableFuture to run async tasks and combine results.

## 6. Generics

26. Create a generic class Box to store and return any type.

27. Write a generic method that accepts any type of List and prints all items.

28. Implement bounded generics that accept only Number subclasses.

29. Demonstrate wildcard usage with List.

30. Convert a List to an array using generics.

## 7. File Handling

31. Read a file and print its content using BufferedReader.

32. Write user input to a file using FileWriter.

33. Serialize and deserialize an Employee object.

34. List all files in a folder and print full paths.

35. Copy content from one file to another.

## 8. JDBC Basics

36. Connect to a MySQL database and print all rows from Employee table.

37. Insert a new record using PreparedStatement.

38. Update a record and show affected rows count.

39. Delete a record using a parameterized query.

40. Implement a method that returns all employees in a List.

## 9. JVM & Memory

41. Demonstrate garbage collection by creating many temporary objects.

42. Illustrate StackOverflowError via recursive call.

43. Explain difference between heap and stack through a sample program.

44. Print classloader of a class.

45. Show how finalize() is invoked before GC.

You might also like