Add office photos
Engaged Employer

Tech Mahindra

3.6
based on 33.1k Reviews
Filter interviews by

Reliable Hubs Engineering Interview Questions and Answers

Updated 10 Sep 2024
Popular Designations

Q1. write program in java to print even no by one thread and odd no by another thread

Ans.

Program to print even and odd numbers using two threads in Java

  • Create two threads, one for even numbers and one for odd numbers

  • Use a loop to generate numbers and check if they are even or odd

  • Print the numbers using the respective threads

  • Use synchronization to ensure alternate printing of even and odd numbers

Add your answer

Q2. In java How hasmap works internally

Ans.

HashMap is a data structure that stores key-value pairs and uses hashing to retrieve values.

  • HashMap uses an array of buckets to store key-value pairs

  • The hash code of the key is used to determine the index of the bucket

  • If multiple keys have the same hash code, they are stored in a linked list within the bucket

  • HashMap allows null keys and values

  • HashMap is not thread-safe and requires synchronization for concurrent access

Add your answer

Q3. What is flatMap in java 8?

Ans.

flatMap in Java 8 is a method used to transform each element of a stream into another stream and then concatenate all the streams into a single stream.

  • flatMap is used to flatten nested collections in streams.

  • It is commonly used with streams of collections or arrays.

  • Example: List> list = Arrays.asList(Arrays.asList(1, 2), Arrays.asList(3, 4)); list.stream().flatMap(Collection::stream).forEach(System.out::println);

Add your answer

Q4. Find LCA of a node in BST

Ans.

LCA of a node in BST is the lowest common ancestor of two nodes in a binary search tree.

  • Traverse the BST from the root node to find the LCA of the given nodes.

  • Compare the values of the nodes with the current node to determine the LCA.

  • If one node is on the left subtree and the other is on the right subtree, the current node is the LCA.

Add your answer
Discover Reliable Hubs Engineering interview dos and don'ts from real experiences

Q5. What is final and finally

Ans.

final is a keyword in Java used to declare constants, while finally is a block used in exception handling to ensure code is executed regardless of an exception.

  • final keyword is used to declare constants in Java

  • final variables cannot be reassigned once initialized

  • finally block is used in exception handling to ensure code is executed regardless of an exception

  • finally block is often used to release resources like closing a file or database connection

Add your answer

Q6. optimise the above solution

Ans.

Optimize the solution by using efficient data structures and algorithms.

  • Use HashMap instead of ArrayList for faster lookup

  • Implement caching to store previously calculated results

  • Consider using multithreading for parallel processing

Add your answer
Contribute & help others!
Write a review
Share interview
Contribute salary
Add office photos
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Top Senior Java Developer Interview Questions from Similar Companies

3.7
 • 23 Interview Questions
3.9
 • 19 Interview Questions
3.8
 • 18 Interview Questions
3.7
 • 16 Interview Questions
3.8
 • 15 Interview Questions
3.7
 • 13 Interview Questions
View all
Share an Interview
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
70 Lakh+

Reviews

5 Lakh+

Interviews

4 Crore+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter