Add office photos
Engaged Employer

Wissen Technology

3.9
based on 447 Reviews
Filter interviews by

30+ Interview Questions and Answers

Updated 7 Aug 2024
Popular Designations

Q1. Parent class has run() and walk() . Parent run() - calls walk() Child Class overrides Parent class Inside run() - calls super.run() Walk() - calls super.walk In main class Parent p = new child() p.run() What wi...

read more
Ans.

The order of execution will be: parent's run() -> child's run() -> parent's walk()

  • When p.run() is called, it will first execute the run() method of the parent class

  • Inside the parent's run() method, it will call the walk() method of the parent class

  • Since the child class overrides the parent class, the child's run() method will be executed next

  • Inside the child's run() method, it will call the run() method of the parent class using super.run()

  • Finally, the walk() method of the pa...read more

View 4 more answers

Q2. 2. What will happen if hashcode only returns a constant? How will it affect the internal working of the HashMap?

Ans.

If hashcode returns a constant, all elements will be stored in the same bucket, resulting in poor performance.

  • All elements will be stored in the same bucket of the HashMap.

  • This will lead to poor performance as the HashMap will essentially become a linked list.

  • Retrieving elements will take longer as the HashMap will have to iterate through the linked list to find the desired element.

View 2 more answers

Q3. How to sort a list of students on the basis of their First name?

Ans.

To sort a list of students on the basis of their First name, use the Collections.sort() method with a custom Comparator.

  • Create a custom Comparator that compares the first names of the students.

  • Implement the compare() method in the Comparator to compare the first names.

  • Use the Collections.sort() method to sort the list of students using the custom Comparator.

View 5 more answers

Q4. Write a program to return the length of the longest word from a string whose length is even?

Ans.

This program returns the length of the longest word from a string whose length is even.

  • Split the string into an array of words using a space as the delimiter.

  • Iterate through the array and check if the length of each word is even.

  • Keep track of the length of the longest even word encountered.

  • Return the length of the longest even word.

View 3 more answers
Discover null interview dos and don'ts from real experiences

Q5. 5. If we have a mutable object inside immutable class then how will you handle it?

Ans.

To handle a mutable object inside an immutable class, make the object private and provide only read-only access methods.

  • Make the mutable object private to encapsulate it within the immutable class.

  • Provide read-only access methods to retrieve the state of the mutable object.

  • Ensure that the mutable object cannot be modified from outside the class.

  • If necessary, create defensive copies of the mutable object to prevent unintended modifications.

View 2 more answers

Q6. 1. Can we keep an object of a Class as key in HashMap?

Ans.

Yes, we can keep an object of a Class as a key in HashMap.

  • The key in a HashMap can be any non-null object.

  • The key's class must override the hashCode() and equals() methods for proper functioning.

  • If two objects have the same hashCode(), they will be stored in the same bucket and compared using equals().

  • If the key is mutable, its state should not be modified after it is used as a key in the HashMap.

View 2 more answers
Are these interview questions helpful?

Q7. Write a query to find name of authors who have written more than 10 books. Table - Bookauthhor Column - Book Column - Author

Ans.

Query to find authors who have written more than 10 books

  • Use the GROUP BY clause to group the records by author

  • Use the HAVING clause to filter the groups with a count greater than 10

  • Join the Bookauthor table with the Author table to get the author names

View 3 more answers

Q8. 3. What if we do not override Equals method ? What is we do not override Hashcode method?

Ans.

Not overriding equals method can lead to incorrect comparison of objects. Not overriding hashCode method can lead to incorrect behavior in hash-based data structures.

  • If equals method is not overridden, the default implementation from Object class will be used which compares object references.

  • This can lead to incorrect comparison of objects where two different objects with same content are considered unequal.

  • If hashCode method is not overridden, the default implementation from...read more

View 1 answer
Share interview questions and help millions of jobseekers 🌟

Q9. Using Java 8 find the sum of squares of all the odd numbers in the arraylist.

Ans.

Using Java 8, find the sum of squares of all the odd numbers in the arraylist.

  • Use the stream() method to convert the ArrayList to a stream

  • Use the filter() method to filter out the even numbers

  • Use the mapToInt() method to square each odd number

  • Use the sum() method to find the sum of the squared odd numbers

View 1 answer

Q10. 6. Advantages and Disadvantages of immutable class?

Ans.

Immutable classes have advantages like thread safety, security, and simplicity, but also have disadvantages like memory usage and performance overhead.

  • Advantages of immutable classes:

  • - Thread safety: Immutable objects can be safely shared among multiple threads without the need for synchronization.

  • - Security: Immutable objects cannot be modified, which can prevent unauthorized changes to sensitive data.

  • - Simplicity: Immutable objects are easier to reason about and debug since...read more

View 1 answer

Q11. 4. How to make a class immutable?

Ans.

To make a class immutable, we need to ensure that its state cannot be modified after creation.

  • Make all fields private and final

  • Do not provide any setters

  • Ensure that mutable objects are not returned from methods

  • Make the class final or use a private constructor

  • Consider using defensive copying

Add your answer

Q12. How to create Thread in Java and What are the ways?

Ans.

Threads in Java allow concurrent execution of multiple tasks. They can be created in multiple ways.

  • Using the Thread class

  • Implementing the Runnable interface

  • Using the Executor framework

  • Using the Callable interface with ExecutorService

Add your answer

Q13. Write a Java program using multithreading to print below output: n=10 Thread-1 : 1 Thread-2 : 2 Thread-3 : 3 Thread-1 : 4 Thread-2 : 6 . . Thread-1 : 10

Ans.

A Java program using multithreading to print numbers from 1 to 10 in a specific pattern.

  • Create three threads and assign them to print numbers in a specific pattern

  • Use synchronization to ensure the correct order of printing

  • Use a loop to iterate from 1 to 10 and assign the numbers to the threads

  • Print the thread name and the assigned number in the desired format

Add your answer

Q14. Object level Lock vs Class level lock?

Ans.

Object level lock is used to synchronize access to an instance method or block, while class level lock is used to synchronize access to a static method or block.

  • Object level lock is acquired on a per-object basis, while class level lock is acquired on a per-class basis.

  • Object level lock is useful when multiple threads are accessing the same instance method or block, while class level lock is useful when multiple threads are accessing the same static method or block.

  • Object lev...read more

Add your answer

Q15. Do you have location constraints?

Ans.

No location constraints.

  • I am open to working in any location.

  • I am willing to relocate if required.

  • I do not have any personal or family commitments that tie me to a specific location.

Add your answer

Q16. What is Serialization?

Ans.

Serialization is the process of converting an object into a stream of bytes to store or transmit it over a network.

  • Serialization is used to save the state of an object and recreate it later.

  • It is also used to send objects over a network as a byte stream.

  • Java provides Serializable interface to implement serialization.

  • Serialization can be used for deep cloning of objects.

  • Example: Saving an object to a file or sending it over a network.

Add your answer

Q17. Synchronized Map vs Concurrent hashmap

Ans.

Synchronized Map is thread-safe but slower, while Concurrent HashMap is faster but not entirely thread-safe.

  • Synchronized Map locks the entire map during write operations, causing other threads to wait.

  • Concurrent HashMap allows multiple threads to read and write simultaneously, using a lock-free approach.

  • Synchronized Map is useful for small maps or low-concurrency scenarios.

  • Concurrent HashMap is better suited for large maps or high-concurrency scenarios.

  • Example: Synchronized M...read more

View 1 answer

Q18. How to detect a loop into LinkedList?

Ans.

To detect a loop in a LinkedList, we can use the Floyd's cycle-finding algorithm.

  • Initialize two pointers, slow and fast, both pointing to the head of the LinkedList.

  • Move slow pointer by one step and fast pointer by two steps at a time.

  • If there is a loop, the slow and fast pointers will eventually meet.

  • If either of the pointers reaches the end of the LinkedList, there is no loop.

Add your answer

Q19. What will happen if you start a thread which is already running

Ans.

The thread will continue running as it is already active

  • The thread will not be started again if it is already running

  • Attempting to start a thread that is already running will not have any effect

  • The thread will continue its execution without any interruption

View 1 answer

Q20. Difference between Callable and Runnable Class?

Ans.

Callable and Runnable are interfaces in Java used for concurrent programming. Callable returns a result and can throw an exception, while Runnable does not return a result or throw an exception.

  • Callable is a generic interface with a method called 'call()', while Runnable is a functional interface with a method called 'run()'.

  • Callable can return a result using the 'Future' interface, while Runnable cannot.

  • Callable can throw checked exceptions, while Runnable cannot.

  • Callable is...read more

Add your answer

Q21. What is the contract between hashCode and equals method?

Ans.

The contract between hashCode and equals method is that if two objects are equal according to the equals method, then their hash codes must also be equal.

  • hashCode and equals method must be consistent - if two objects are equal according to equals method, their hash codes must be equal

  • If two objects have the same hash code, they may or may not be equal according to equals method

  • Overriding equals method in a class requires overriding hashCode method as well to maintain the cont...read more

View 1 answer

Q22. One sql query to find the highest salary from each department from Employee database.

Ans.

Use SQL query to find highest salary from each department in Employee database.

  • Use GROUP BY clause to group results by department.

  • Use MAX() function to find highest salary in each group.

  • Join Employee table with Department table to get department information.

Add your answer

Q23. Convert String camel case to snake case.

Ans.

Converts a camel case string to snake case.

  • Split the string by uppercase letters

  • Convert each word to lowercase

  • Join the words with underscores

Add your answer

Q24. What is immutable class how can we create it?

Ans.

An immutable class is a class whose objects cannot be modified after they are created.

  • To create an immutable class, make the class final so that it cannot be extended.

  • Make all the fields private and final, so they cannot be modified.

  • Do not provide any setter methods, only provide getter methods.

  • If the class contains mutable objects, make sure to return a copy of the object instead of the original.

  • Ensure that the class does not have any methods that can modify its state.

Add your answer

Q25. Reverse the list node with head node having multiple values.

Ans.

Reverse a list node with multiple values in Java.

  • Create a new linked list to store the reversed nodes.

  • Traverse the original list and add each node to the front of the new list.

  • Update the head node of the original list to point to the new list.

Add your answer

Q26. what are the ways to create the threads and all

Ans.

There are two ways to create threads in Java: by extending the Thread class or by implementing the Runnable interface.

  • Extending the Thread class: Create a new class that extends the Thread class and override the run() method.

  • Implementing the Runnable interface: Create a new class that implements the Runnable interface and implement the run() method.

  • Example using Thread class: MyThread extends Thread { public void run() { // thread logic } }

  • Example using Runnable interface: My...read more

Add your answer

Q27. What are the ways to start a thread

Ans.

Ways to start a thread in Java

  • Extending the Thread class and overriding the run() method

  • Implementing the Runnable interface and passing it to a Thread object

  • Using a thread pool from the Executors class

Add your answer

Q28. sorting in the string

Ans.

Sorting strings in an array

  • Use Arrays.sort() method to sort the array of strings

  • You can also use a custom Comparator to define the sorting criteria

  • Remember that sorting is case-sensitive by default

Add your answer

Q29. priority queue in the array

Ans.

Priority queue can be implemented using an array by maintaining the order of elements based on their priority.

  • Maintain the order of elements in the array based on their priority level.

  • When adding elements, insert them in the correct position to maintain the priority order.

  • When removing elements, remove the element with the highest priority first.

  • Example: ["High Priority", "Low Priority", "Medium Priority"]

Add your answer

Q30. Nested array objects to single array.

Ans.

Convert nested array objects to single array of strings.

  • Iterate through the nested arrays and flatten them into a single array.

  • Use recursion to handle multiple levels of nesting.

  • Example: [["a", "b"], ["c", "d"]] -> ["a", "b", "c", "d"]

Add your answer

Q31. Explain about the join and sleep method

Ans.

Join method is used to wait for a thread to finish its execution, while sleep method is used to pause the execution of a thread for a specified amount of time.

  • Join method is used to wait for a thread to finish its execution before moving on to the next task.

  • Sleep method is used to pause the execution of a thread for a specified amount of time, allowing other threads to run.

  • Example: thread1.join() will wait for thread1 to finish before continuing with the execution.

  • Example: Th...read more

Add your answer

Q32. Merger two sorted array,

Ans.

Merge two sorted arrays into a single sorted array.

  • Create a new array with the combined length of the two input arrays

  • Use two pointers to iterate through the two input arrays and compare elements

  • Add the smaller element to the new array and move the pointer for that array forward

  • Repeat until all elements from both arrays are added to the new array

Add your answer

Q33. What are JOINS in MySql

Ans.

JOINS in MySql are used to combine rows from two or more tables based on a related column between them.

  • JOINS are used to retrieve data from multiple tables based on a related column

  • Types of JOINS include INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN

  • Example: SELECT * FROM table1 INNER JOIN table2 ON table1.column = table2.column

Add your answer

Q34. Internal implementation of hashmap.

Ans.

HashMap is internally implemented using an array of linked lists.

  • HashMap uses an array to store key-value pairs

  • Each array index is called a bucket

  • Each bucket can store multiple key-value pairs using a linked list

  • Hashing is used to determine the index of the array for a given key

  • If multiple keys hash to the same index, they are stored in the same bucket

Add your answer

Q35. What is Kafka ?

Ans.

Kafka is a distributed streaming platform used for building real-time data pipelines and streaming applications.

  • Kafka is designed to handle high-throughput, fault-tolerant, and scalable real-time data streams.

  • It allows for the publishing and subscribing to streams of records, similar to a message queue.

  • Kafka is often used for log aggregation, stream processing, event sourcing, and real-time analytics.

  • It provides features like fault tolerance, replication, and partitioning to ...read more

Add your answer

Q36. flatten an array

Ans.

Flatten an array of strings

  • Use a recursive function to iterate through the array and flatten it

  • Check if each element is an array, if so, recursively call the function

  • Concatenate the elements into a single array

Add your answer

Q37. Features introduced in Java 8

Ans.

Java 8 introduced several new features including lambda expressions, functional interfaces, streams, and default methods in interfaces.

  • Lambda expressions allow you to pass functions as arguments.

  • Functional interfaces have a single abstract method and can be used with lambda expressions.

  • Streams provide a way to work with sequences of elements.

  • Default methods allow interfaces to have method implementations.

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

Interview Process at null

based on 14 interviews in the last 1 year
2 Interview rounds
Coding Test Round
Technical Round
View more
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Top Java Developer Interview Questions from Similar Companies

3.0
 • 24 Interview Questions
3.6
 • 18 Interview Questions
3.9
 • 17 Interview Questions
3.6
 • 12 Interview Questions
4.4
 • 11 Interview Questions
3.7
 • 10 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