Fluentgrid
OpsTree Solutions Interview Questions and Answers
Q1. Given a ArrayList of String containing some name with some name repeated. Write the code on a notepad printing only the single occurrence of each name in the ArrayList. iImplement the same using Java 8 Streams ...
read moreUsing Java 8 Streams API to print single occurrences of names in an ArrayList of Strings.
Use stream() method on the ArrayList to create a stream of elements.
Use filter() method to filter out elements that occur more than once.
Use distinct() method to get only unique elements.
Use forEach() method to print each unique element.
Q2. You are given a string, name and an integer which is year of birth. You need to print the reverse of year of birth followed by the reverse of name.
Reverse the year of birth and name, then print them in that order.
Reverse the year of birth using StringBuilder.reverse() method
Reverse the name using StringBuilder.reverse() method
Print the reversed year of birth followed by the reversed name
Q3. Given a ArrayList of String containing some names with some repeated names. Write the code on a notepad printing each name and the number of occurrences of each name in the ArrayList
Code to print each name and the number of occurrences in an ArrayList of Strings.
Iterate through the ArrayList and use a HashMap to store the count of each name.
Print each name along with its count from the HashMap.
Q4. What are Interfaces and Abstract classed in Java and code an example of an interface on Notepad
Interfaces and Abstract classes in Java are used for achieving abstraction and defining contracts for classes to implement.
Interfaces in Java are like blueprints for classes, defining methods that must be implemented by classes that implement the interface.
Abstract classes are classes that cannot be instantiated and can have both abstract and concrete methods.
Example of an interface in Java: public interface Shape { double calculateArea(); double calculatePerimeter(); }
Exampl...read more
Q5. What are lambda expressions in Java
Lambda expressions in Java are a concise way to represent anonymous functions.
Lambda expressions are used to provide implementation of functional interfaces.
They enable you to treat functionality as a method argument, or code as data.
Syntax: (parameters) -> expression or (parameters) -> { statements; }
Example: (int a, int b) -> a + b
Q6. What are functional interfaces in Java
Functional interfaces in Java are interfaces with only one abstract method, used for lambda expressions and functional programming.
Functional interfaces have only one abstract method, but can have multiple default or static methods.
They are used for lambda expressions and functional programming in Java.
Examples include java.lang.Runnable, java.util.Comparator, and java.util.function.Function.
Q7. What are Threads in Java
Threads in Java are lightweight sub-processes that allow concurrent execution within a single process.
Threads allow multiple tasks to be executed simultaneously in a Java program.
Threads share the same memory space and resources within a process.
Example: Creating a new thread using the Thread class or implementing the Runnable interface.
Q8. What are Streams in Java
Streams in Java are sequences of elements that support functional-style operations such as filter, map, reduce, etc.
Streams are not data structures, but rather a way to interact with collections of objects.
They allow for efficient processing of large amounts of data.
Streams can be sequential or parallel, allowing for concurrent processing.
Example: List
names = Arrays.asList("Alice", "Bob", "Charlie"); Stream stream = names.stream();
Top HR Questions asked in OpsTree Solutions
Top Java Developer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month