0% found this document useful (0 votes)
11 views4 pages

Java 8 Coding Challenges & Concepts

The document outlines a comprehensive guide on Java 8 features, including coding questions categorized by difficulty levels from easy to expert. It covers various topics such as lambda expressions, stream processing, functional interfaces, method references, and advanced operations on collections and custom classes. Additionally, it includes practical exercises related to employee data, string manipulation, and functional operations.

Uploaded by

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

Java 8 Coding Challenges & Concepts

The document outlines a comprehensive guide on Java 8 features, including coding questions categorized by difficulty levels from easy to expert. It covers various topics such as lambda expressions, stream processing, functional interfaces, method references, and advanced operations on collections and custom classes. Additionally, it includes practical exercises related to employee data, string manipulation, and functional operations.

Uploaded by

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

🧩 List<String> names = Arrays.

asList("Shiva","Krsna","Krsna","Phani");

· Java 8+ features in depth

· Oops concepts knowledge and usage

· Collections

· Multithreading

· Spring core

· Spring JDBC

· Spring restful services

· Spring boot

· JUnit test cases writing

· Experience on working on micro services architecture

· Design patterns experience like factory design pattern.

· Working on multi tier architecture like extracting data from different source systems and
processing the data to target systems to files or in db.

Java 8 Coding Questions (Novice → Expert)

🟢 Level 1 — Easy (Basic Hands-On, Core Syntax)

1. Write a lambda expression to print all elements of a list.

2. Convert a list of integers to their squares using a stream.

3. Use a lambda to sort a list of strings by length.

4. Create a functional interface Calculator with one method operate(int a, int b) and implement
addition using a lambda.

5. Write a program to filter even numbers from a list using Stream API.

6. Count how many strings start with “A” in a list using streams.

7. Create a list of names and print only those names with length greater than 4 using streams.

8. Use a Consumer functional interface to print all items of a list.

9. Create a stream from an array and find the maximum number.

10. Write a lambda expression to check if a number is prime.

🟡 Level 2 — Medium (Realistic Stream Processing)

11. Given a list of employees, filter only those with salary > 50,000 and collect their names into a
list.
12. Convert a list of strings to uppercase and remove duplicates using streams.

13. Find the sum of all even numbers in a list using reduce().

14. Use Optional to handle possible null values safely in a method that returns a string length.

15. Given a list of integers, find the second highest number using streams.

16. Sort a list of custom objects (e.g., Employee by age) using a lambda comparator.

17. Use Predicate chaining to filter numbers greater than 10 and even.

18. Use a stream to count the number of words in a text file.

19. Concatenate a list of strings into a single string separated by commas using
[Link]().

20. Create a stream of random numbers and print the first 5 using limit().

🟠 Level 3 — Advanced Functional Interfaces

21. Implement your own version of Function<T, R> to convert Employee objects into their
names.

22. Combine two Functions using andThen() to first trim and then convert a string to uppercase.

23. Use a Supplier to generate a random UUID every time it’s called.

24. Use a BiPredicate to check if the sum of two integers is even.

25. Create a chain of Consumers to print a string, then its length, then its uppercase version.

26. Write a program that takes a List<Integer> and removes duplicates using a stream and
distinct().

27. Use a stream to partition a list of integers into even and odd numbers using
[Link]().

28. Implement a reusable method that accepts a Predicate and filters any list.

29. Write a lambda to sort a map by its values.

30. Demonstrate the use of peek() in a stream pipeline for debugging.

🔵 Level 4 — Method References & Optional Mastery

31. Replace a lambda with a method reference in a stream that prints all items.

32. Use a constructor reference to create a list of Employee objects from a list of names.

33. Demonstrate all 4 types of method references (static, instance, particular object,
constructor).

34. Use [Link]() and [Link]() difference in a real example.

35. Chain multiple Optional operations to safely fetch nested properties from an object.
36. Use [Link]() to provide a default value lazily.

37. Convert a List<Optional<String>> into a List<String> using flatMap().

38. Demonstrate how to throw a custom exception when Optional is empty using orElseThrow().

39. Filter out nulls from a list using Optional and streams.

40. Use [Link]() to perform conditional checks elegantly.

🔴 Level 5 — Expert (Complex Stream Operations)

41. Given a list of transactions, group them by type and find total value per type using
[Link]().

42. Write a program to find the most frequent element in a list using streams.

43. Read a CSV file and calculate the average of a numeric column using streams.

44. Flatten a list of lists (e.g., List<List<Integer>>) into a single list using flatMap().

45. Given a list of words, find all unique characters using streams.

46. Use reduce() to concatenate a list of strings with a space in between.

47. Parallelize a large computation (sum of squares of numbers 1–1,000,000) using


parallelStream() and compare time.

48. Create a custom collector that counts the total number of words in a stream.

49. Write a program to find the top 3 highest-paid employees using streams.

50. Use the new [Link] API to find the number of days between two given dates and print
formatted output.

Streams & Numbers

1. Using IntStream, print all prime numbers between 1 and 100.

2. Generate the first 20 Fibonacci numbers using [Link].

3. Find the factorial of a number using Java 8 Streams.

4. Using IntStream, find the sum of all even numbers between 1 and 50.

5. Find the maximum and minimum from a list of integers using Streams.

6. Count the number of numbers divisible by 3 and 5 in a given list using Streams.

7. Convert a list of integers into a list of their squares using Streams.

Strings & Characters

8. Count the frequency of each character in a given string using Streams.


9. Find the first non-repeated character in a string using Java 8 Streams.

10. Convert a list of sentences into a list of words using flatMap.

11. Find all palindromic words in a list of strings using Streams.

12. Given a string, find the number of vowels using Streams.

13. Sort words in a sentence alphabetically using Streams.

14. Group words in a sentence by their length using [Link].

Employee / Custom Class

15. Given a list of Employee(name, salary), find the highest paid employee.

16. Group employees by salary using [Link].

17. Sort employees by name and then by salary using Streams and Comparator.

18. Find the average salary of employees using [Link].

19. Partition employees into two groups: salary > 50000 and ≤ 50000.

20. Find employees whose names start with a specific letter using Streams.

21. Convert a list of employees into a map of <name, salary> using [Link].

Collectors & Grouping

22. Count the number of employees in each department using [Link].

23. Find the sum of salaries for each department using [Link] and
[Link].

24. Find the employee with the highest salary in each department.

25. Group a list of strings by their first character using Streams.

Miscellaneous / Functional Operations

26. Combine two functions using andThen or compose to transform a string (trim + uppercase).

27. Filter a list of integers to remove duplicates and sort them using Streams.

28. Flatten a list of lists of integers into a single list using flatMap.

29. Given a list of strings, find the top 3 most frequent strings using Streams.

30. Count the number of empty strings in a list using Streams.

You might also like