Premium Employer

10405090xyzabc

3.9
based on 19 Reviews
Filter interviews by

20+ Hitesh Infrabuild Interview Questions and Answers

Updated 26 Feb 2025

Q1. Explain the difference between ArrayList and LinkedList in Java. When would you choose one over the other?

Ans.

ArrayList and LinkedList are both implementations of the List interface in Java. ArrayList uses a dynamic array to store elements, while LinkedList uses a doubly linked list.

  • ArrayList is faster for accessing elements by index, while LinkedList is faster for adding or removing elements in the middle of the list.

  • ArrayList uses more memory as it needs to allocate space for the entire list upfront, while LinkedList only needs memory for each element and its pointers.

  • Choose ArrayL...read more

Add your answer

Q2. What is a Java Stream, and how does it differ from an Iterator? Explain how Streams can be used to process collections efficiently.

Ans.

Java Stream is a sequence of elements that supports functional-style operations. It differs from Iterator by allowing for more concise and declarative code.

  • Streams provide a way to process collections in a functional programming style, allowing for operations like map, filter, and reduce.

  • Unlike Iterators, Streams do not store elements, making them more memory efficient.

  • Streams can be parallelized to take advantage of multi-core processors for faster processing.

  • Example: List<S...read more

Add your answer

Q3. Explain the concept of immutability in Java. How does the String class achieve immutability, and what are the advantages of immutable objects?

Ans.

Immutability in Java means that an object's state cannot be changed after it is created. String class achieves immutability by not allowing its value to be modified.

  • Immutability means that once an object is created, its state cannot be changed.

  • String class achieves immutability by making its value final and not providing any methods to modify it.

  • Advantages of immutable objects include thread safety, caching, and easier debugging.

Add your answer

Q4. What is the difference between final, finally, and finalize in Java? Provide examples to illustrate their usage.

Ans.

final, finally, and finalize have different meanings in Java.

  • final is a keyword used to declare constants, immutable variables, or prevent method overriding.

  • finally is a block used in exception handling to execute code after try-catch block.

  • finalize is a method used for cleanup operations before an object is garbage collected.

Add your answer
Discover Hitesh Infrabuild interview dos and don'ts from real experiences

Q5. Explain the Singleton design pattern in Java. How can you implement it safely to ensure thread safety?

Ans.

Singleton design pattern ensures a class has only one instance and provides a global point of access to it.

  • Create a private static instance of the class.

  • Make the constructor private to prevent instantiation from outside the class.

  • Provide a public static method to access the instance, creating it if necessary.

  • Use synchronized keyword or double-checked locking to ensure thread safety.

Add your answer

Q6. Can you explain the difference between method overloading and method overriding in Java? Provide examples where each should be used.

Ans.

Method overloading involves creating multiple methods in the same class with the same name but different parameters. Method overriding involves creating a method in a subclass that has the same name, return type, and parameters as a method in the superclass.

  • Method overloading is used to provide different implementations of a method based on the number or type of parameters passed.

  • Method overriding is used to provide a specific implementation of a method in a subclass that is ...read more

Add your answer
Are these interview questions helpful?

Q7. What are Java annotations, and how are they used in frameworks like Spring? Explain the difference between built-in and custom annotations.

Ans.

Java annotations are metadata that provide data about a program but do not affect the program itself. They are used in frameworks like Spring to simplify configuration and reduce boilerplate code.

  • Java annotations are used to provide metadata about classes, methods, fields, etc. They are defined using the @ symbol.

  • In Spring framework, annotations are used to configure various aspects of the application, such as dependency injection, transaction management, and MVC mappings.

  • Bui...read more

Add your answer

Q8. What are the advantages and disadvantages of using Java’s synchronized keyword for thread synchronization? Can you explain how the ReentrantLock compares to synchronized?

Ans.

Using Java's synchronized keyword for thread synchronization has advantages like simplicity and disadvantages like potential deadlock. ReentrantLock offers more flexibility and control.

  • Advantages of synchronized keyword: easy to use, built-in support in Java

  • Disadvantages of synchronized keyword: potential for deadlock, lack of flexibility

  • ReentrantLock advantages: more control over locking, ability to try and acquire lock, support for condition variables

  • ReentrantLock disadvant...read more

Add your answer
Share interview questions and help millions of jobseekers 🌟

Q9. How does the Java garbage collector work? Can you describe the different types of garbage collection algorithms available in Java?

Ans.

The Java garbage collector automatically manages memory by reclaiming unused objects.

  • Garbage collector runs in the background to reclaim memory from objects no longer in use.

  • Different types of garbage collection algorithms include Serial, Parallel, CMS, G1, and ZGC.

  • Serial collector is best for single-threaded applications, while G1 is suitable for large heap sizes.

  • CMS (Concurrent Mark Sweep) collector minimizes pause times by running most of the collection concurrently with t...read more

Add your answer

Q10. What is the Java Memory Model, and how does it affect multithreading and synchronization? How does volatile help ensure memory visibility?

Ans.

The Java Memory Model defines how threads interact through memory and how changes made by one thread are visible to others.

  • Java Memory Model specifies how threads interact with memory, ensuring visibility and consistency.

  • It defines the rules for reading and writing variables in a multithreaded environment.

  • Synchronization ensures that only one thread can access a shared resource at a time.

  • Volatile keyword in Java ensures visibility of changes made by one thread to other thread...read more

Add your answer

Q11. How do Java Streams handle parallel processing? What are the potential pitfalls of using parallel streams, and how can they be mitigated?

Ans.

Java Streams can handle parallel processing using parallel streams. Pitfalls include increased complexity and potential for race conditions.

  • Java Streams can utilize parallel processing by using parallel streams, which automatically divide the data into multiple chunks and process them concurrently.

  • Potential pitfalls of using parallel streams include increased complexity, potential for race conditions, and overhead of managing parallel threads.

  • To mitigate these pitfalls, ensur...read more

Add your answer

Q12. What is the difference between == and .equals() in Java? When should each be used, and what issues can arise from improper usage?

Ans.

In Java, == compares memory addresses while .equals() compares values. Improper usage can lead to unexpected results.

  • Use == to compare primitive data types and object references.

  • Use .equals() to compare the actual values of objects.

  • Improper usage of == with objects can lead to comparing memory addresses instead of values.

  • Improper usage of .equals() can lead to NullPointerException if used with null objects.

Add your answer

Q13. What are the main features of Java 8? Can you explain how lambdas and the Stream API have changed the way Java applications are written?

Ans.

Java 8 introduced features like lambdas and Stream API which have revolutionized the way Java applications are written.

  • Lambdas allow for more concise and readable code by enabling functional programming paradigms.

  • Stream API provides a way to process collections of objects in a functional style, allowing for easier parallel processing and improved performance.

  • Java 8 also introduced default methods in interfaces, allowing for backward compatibility with existing code while stil...read more

Add your answer

Q14. What are functional interfaces in Java? How do they work with lambda expressions? Provide an example of a custom functional interface.

Ans.

Functional interfaces in Java are interfaces with a single abstract method. They can be used with lambda expressions for functional programming.

  • Functional interfaces have only one abstract method, but can have multiple default or static methods.

  • Lambda expressions can be used to implement the single abstract method of a functional interface concisely.

  • An example of a custom functional interface is 'Calculator' with a single abstract method 'calculate'.

Add your answer

Q15. Describe the differences between checked and unchecked exceptions in Java. Provide examples and explain how to handle them properly.

Ans.

Checked exceptions are checked at compile time, while unchecked exceptions are not. Proper handling involves either catching or declaring the exception.

  • Checked exceptions must be either caught or declared in the method signature using 'throws'. Example: IOException.

  • Unchecked exceptions do not need to be caught or declared. Example: NullPointerException.

  • Proper handling of exceptions involves using try-catch blocks for checked exceptions and ensuring null checks for potential u...read more

Add your answer

Q16. What is a use case diagram, and in what scenarios is it typically utilized?

Ans.

A use case diagram is a visual representation of the interactions between users and a system, showing the various use cases and actors involved.

  • Use case diagrams are typically utilized in software development to capture the functional requirements of a system.

  • They help in identifying the different ways users can interact with the system and the various scenarios that can occur.

  • Use case diagrams show the relationships between actors (users) and use cases, helping in understand...read more

Add your answer

Q17. What is a transaction in DBMS, what are ACID properties? Explain the difference between SQL and NoSQL databases. How would you optimize a slow running query?

Ans.

A transaction in DBMS is a unit of work that must be executed as a whole. ACID properties ensure data integrity. SQL is relational, NoSQL is non-relational.

  • A transaction in DBMS is a set of operations that must be executed as a single unit.

  • ACID properties (Atomicity, Consistency, Isolation, Durability) ensure data integrity in transactions.

  • SQL databases are relational and use structured query language, while NoSQL databases are non-relational and offer more flexibility.

  • To opt...read more

Add your answer

Q18. What is a use case diagram, and in which scenarios is it typically used?

Ans.

A use case diagram is a visual representation of the interactions between users and a system, showing the different ways users can interact with the system.

  • Use case diagrams are typically used in software development to capture the functional requirements of a system.

  • They help in identifying the actors (users) and their interactions with the system.

  • Use case diagrams show the various use cases or scenarios in which the system can be used.

  • They are useful for communicating syste...read more

Add your answer

Q19. Define encapsulation and provide an example. Discuss the principles of inheritance and polymorphism.

Ans.

Encapsulation is the concept of bundling data and methods that operate on the data into a single unit. Inheritance allows a class to inherit attributes and methods from another class. Polymorphism allows objects of different classes to be treated as objects of a common superclass.

  • Encapsulation helps in data hiding and abstraction

  • Example: A class 'Car' encapsulates data like make, model, and methods like start(), stop()

  • Inheritance allows for code reusability and promotes the c...read more

Add your answer

Q20. Explain how to detect a cycle in a linked list.

Ans.

Use Floyd's Tortoise and Hare algorithm to detect a cycle in a linked list.

  • Start with two pointers, slow and fast, moving at different speeds.

  • If there is a cycle, the two pointers will eventually meet at some point.

  • If there is no cycle, the fast pointer will reach the end of the list.

  • Example: 1->2->3->4->5->2 (cycle at node 2), slow and fast pointers will meet at node 2.

Add your answer

Q21. how to reverse a linklist

Ans.

To reverse a linked list, iterate through the list and change the direction of pointers.

  • Iterate through the linked list and keep track of the previous, current, and next nodes.

  • Update the pointers of each node to reverse the direction.

  • Set the head of the linked list to the last node encountered during iteration.

Add your answer
Contribute & help others!
Write a review
Share interview
Contribute salary
Add office photos

Interview Process at Hitesh Infrabuild

based on 1.4k interviews
Interview experience
3.0
Average
View more
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Top Interview Questions from Similar Companies

4.0
 • 734 Interview Questions
3.3
 • 457 Interview Questions
3.9
 • 215 Interview Questions
3.3
 • 150 Interview Questions
3.8
 • 149 Interview Questions
4.3
 • 135 Interview Questions
View all
Top 10405090xyzabc Interview Questions And Answers
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

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