Premium Employer

HCLTech

3.6
based on 33.5k Reviews
Filter interviews by

50+ Interview Questions and Answers

Updated 18 Nov 2024
Popular Designations

Q1. 1. How to connect 2 DBs from spring boot application

Ans.

To connect 2 DBs from a Spring Boot application, configure multiple data sources and use JdbcTemplate or EntityManager for each DB.

  • Configure multiple data sources in the application.properties file

  • Create separate configuration classes for each data source

  • Use JdbcTemplate or EntityManager to interact with each DB

  • Specify the appropriate data source in the repository or service classes

Add your answer

Q2. What is System.out.println?

Ans.

System.out.println is a Java statement used to print output to the console.

  • System is a class in Java's core library.

  • out is a static member of the System class.

  • println is a method of the PrintStream class.

  • It is used to print output to the console.

  • It adds a newline character at the end of the output.

View 5 more answers

Q3. What is difference between sleep or wait method?

Ans.

Sleep method pauses the thread for a specified time, while wait method pauses the thread until notified.

  • Sleep method is a static method of Thread class, while wait method is an instance method of Object class.

  • Sleep method does not release the lock on the object, while wait method releases the lock and waits for notification.

  • Sleep method can be interrupted by another thread, while wait method can only be interrupted by a call to notify or notifyAll method.

  • Example: Thread.sleep...read more

View 1 answer

Q4. 1)Compare two string using Java 8 features without comparator and comparable 2) Given an array to print non duplicate in the array 3) Solid principles 4) Stereo type annotations 5) how to make list immutable 6)...

read more
Ans.

The interview questions cover a range of topics related to Java development, including Java 8 features, data structures, annotations, and database triggers.

  • Use Java 8 features like streams and lambda expressions to compare two strings without using comparator or comparable.

  • To print non-duplicate elements in an array, use a HashSet to store unique elements and then iterate through the array to check for duplicates.

  • Solid principles refer to a set of design principles for object...read more

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

Q5. 2. Difference between abstract method implementation and default method

Ans.

Abstract method implementation is mandatory while default method is optional.

  • Abstract method has no implementation in the abstract class and must be implemented by the subclass.

  • Default method has a default implementation in the interface and can be overridden by the implementing class.

  • Abstract method is used to enforce a contract while default method is used to provide a default behavior.

  • Example: abstract method - public abstract void draw(); default method - default void dis...read more

View 1 answer

Q6. What is static or final method?

Ans.

Static or final method is a method that belongs to a class rather than an instance of the class.

  • Static method can be called without creating an instance of the class.

  • Final method cannot be overridden by a subclass.

  • Static and final methods can be accessed using the class name.

  • Example: Math.max() is a static method in the Math class.

  • Example: String.toUpperCase() is a final method in the String class.

View 1 answer
Are these interview questions helpful?

Q7. What are the applications of java?

Ans.

Java is used for developing desktop, web, mobile, and enterprise applications.

  • Desktop applications like media players, IDEs, and scientific applications

  • Web applications like e-commerce websites, social media platforms, and banking portals

  • Mobile applications for Android devices

  • Enterprise applications like customer relationship management systems and supply chain management systems

View 1 answer

Q8. Write program to print odd and even number alternatively using 2 threads which contains odd number list and even number list

Ans.

Program to print odd and even numbers alternatively using 2 threads with separate lists

  • Create two separate lists for odd and even numbers

  • Use two threads to print numbers alternatively from each list

  • Ensure synchronization between threads to avoid race conditions

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

Q9. Add string or integer value using map?

Ans.

Yes, we can add string or integer value using map in Java.

  • We can use put() method to add values to a map.

  • For string values, we can use String as the value type.

  • For integer values, we can use Integer as the value type.

  • Example: Map map = new HashMap<>(); map.put("key", "value");

  • Example: Map map = new HashMap<>(); map.put("key", 123);

Add your answer

Q10. How to output in Java programming

Ans.

Output in Java is done using the System.out.println() method.

  • Use System.out.println() to print output to the console

  • Use System.out.print() to print output without a newline character

  • Use System.out.printf() to format output with placeholders

  • Use FileWriter or PrintWriter to output to a file

Add your answer

Q11. Different types of oops concepts in java?

Ans.

There are four main OOPs concepts in Java: Abstraction, Encapsulation, Inheritance, and Polymorphism.

  • Abstraction: Hiding implementation details and showing only necessary information.

  • Encapsulation: Wrapping data and methods into a single unit and restricting access to them.

  • Inheritance: Acquiring properties and behavior of a parent class by a child class.

  • Polymorphism: Ability of an object to take many forms and perform different actions based on the context.

Add your answer

Q12. Write a java program using java 8 , Print the name and count the each word in the name

Ans.

Java program using Java 8 to print name and count each word in the name

  • Use Java 8 streams to split the name into words

  • Use Collectors.groupingBy to count the occurrences of each word

  • Print the name and the count of each word

Add your answer

Q13. Remove duplicate from a list of employee object based on empID using streams

Ans.

Remove duplicates from a list of employee objects based on empID using streams

  • Use Java streams to group the employee objects by empID

  • Use a collector to collect the grouped objects and get the values as a list

  • Convert the list back to a stream and collect it to a new list

Add your answer

Q14. WHAT IS DIFFERENCE BETWEEN THROW AND THROWS?

Ans.

throw is used to explicitly throw an exception in a method, while throws is used to declare the exceptions that a method may throw.

  • throw is used within a method to throw an exception explicitly.

  • throws is used in method signature to declare the exceptions that the method may throw.

  • throw is followed by an instance of Throwable class, while throws is followed by the exception class names separated by commas.

  • Example: throw new IllegalArgumentException();

  • Example: public void metho...read more

Add your answer

Q15. What is collection?

Ans.

A collection is a group of objects that can be stored, manipulated, and retrieved as a single unit.

  • Collections are used to store and manage groups of related objects.

  • Java provides several built-in collection classes such as ArrayList, LinkedList, HashSet, etc.

  • Collections can be used to perform operations like sorting, searching, filtering, and more.

  • Collections can be generic or non-generic, depending on the type of objects they store.

Add your answer

Q16. Write a program for sum of numbers?

Ans.

A program to calculate the sum of numbers.

  • Create a variable to store the sum.

  • Iterate through the numbers and add each number to the sum.

  • Return the sum.

View 1 answer

Q17. Write code for controller, service and DAO layer for getEmployeeByID

Ans.

Code snippets for controller, service, and DAO layers to retrieve employee by ID

  • Controller layer: Create a method to handle GET request for employee by ID

  • Service layer: Implement logic to retrieve employee by ID from DAO layer

  • DAO layer: Write query to fetch employee by ID from database

Add your answer

Q18. What is oops concept?

Ans.

OOPs is a programming paradigm based on the concept of objects.

  • OOPs stands for Object-Oriented Programming.

  • It focuses on creating objects that contain both data and functions.

  • Encapsulation, Inheritance, Polymorphism, and Abstraction are the four main pillars of OOPs.

  • Java is an OOPs language.

  • Example: A car is an object that has properties like color, model, and functions like start, stop, and accelerate.

View 1 answer

Q19. Abstraction vs interface?

Ans.

Abstraction is a concept of hiding implementation details while interface is a contract that defines the behavior of a class.

  • Abstraction is achieved through abstract classes and methods

  • Interface is a collection of abstract methods and constants

  • Abstraction allows for flexibility in implementation

  • Interface allows for multiple inheritance

  • Abstraction is used for code reusability

  • Interface is used for achieving polymorphism

View 2 more answers

Q20. Overloading vs overriding?

Ans.

Overloading is when multiple methods have the same name but different parameters. Overriding is when a subclass provides a different implementation of a method inherited from its superclass.

  • Overloading is resolved at compile-time based on the method signature.

  • Overriding is resolved at runtime based on the actual object type.

  • Overloading is used to provide different ways to call a method with different parameters.

  • Overriding is used to provide a specific implementation of a meth...read more

View 1 answer

Q21. Explain how hashmap works internally ?

Ans.

HashMap works internally using an array of buckets where key-value pairs are stored based on the hash code of the keys.

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

  • When a key-value pair is added, the key's hash code is used to determine the bucket where it will be stored.

  • If two keys have the same hash code, they are stored in the same bucket using a linked list or a balanced tree for collision resolution.

  • To retrieve a value, the key's hash code is used...read more

Add your answer

Q22. Write program to sort list based on multiple conditions

Ans.

Program to sort list based on multiple conditions

  • Create a custom Comparator class to define the sorting logic

  • Implement the compare method to compare objects based on multiple conditions

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

Add your answer

Q23. What is controller advice annotation?

Ans.

Controller advice annotation is used to handle exceptions globally in Spring MVC.

  • It is used to handle exceptions thrown by multiple controllers.

  • It can be used to add common model attributes to multiple controllers.

  • It can be used to customize the response of HTTP status codes.

  • Example: @ControllerAdvice

  • Example: @ExceptionHandler(Exception.class)

Add your answer

Q24. What is join in sql?

Ans.

Join in SQL is used to combine rows from two or more tables based on a related column between them.

  • Join is used to retrieve data from multiple tables in a single query

  • Types of join include inner join, left join, right join, and full outer join

  • Join condition is specified using ON keyword

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

  • Join can also be used with subqueries

Add your answer

Q25. What is polymorphism?

Ans.

Polymorphism is the ability of an object to take on many forms.

  • Polymorphism allows objects of different classes to be treated as if they are of the same class.

  • It is achieved through method overriding and method overloading.

  • Example: A parent class Animal can have child classes like Dog, Cat, and Bird. All these child classes can have their own implementation of the method 'makeSound', which is overridden from the parent class.

  • Polymorphism helps in achieving code reusability an...read more

View 1 answer

Q26. What is inheritence?

Ans.

Inheritance is a mechanism in which one class acquires the properties and behaviors of another class.

  • It allows code reusability and saves time

  • The class that is inherited is called the superclass or parent class

  • The class that inherits from the superclass is called the subclass or child class

  • The subclass can access all the public and protected methods and fields of the superclass

  • Example: A Car class can inherit properties and behaviors from a Vehicle class

View 1 answer

Q27. How to implement multithread in java

Ans.

Multithreading in Java allows multiple threads to execute concurrently, improving performance and responsiveness.

  • Create a class that extends Thread or implements Runnable interface

  • Override the run() method with the code to be executed concurrently

  • Instantiate the class and call start() method to begin execution

  • Use synchronized keyword to handle thread synchronization and prevent race conditions

Add your answer

Q28. What is java?

Ans.

Java is a high-level, object-oriented programming language used to develop applications for various platforms.

  • Java is platform-independent and can run on any device with a Java Virtual Machine (JVM)

  • It is known for its security features and is commonly used for developing web and mobile applications

  • Java is also used for developing enterprise-level applications and software tools

  • Examples of Java-based applications include Android apps, Minecraft, and Apache Hadoop

View 1 answer

Q29. Why String immutable

Ans.

String is immutable in Java to ensure security, thread safety, and optimization.

  • Immutable strings prevent modification, ensuring data integrity and security.

  • Immutable strings can be safely shared across multiple threads without synchronization issues.

  • Immutable strings allow for efficient memory allocation and string pooling.

  • Example: String s = "Hello"; s.concat(" World"); // returns a new string without modifying the original

View 1 answer

Q30. Can hashmap contain null key?

Ans.

Yes, hashmap can contain null key.

  • HashMap allows null key and null values.

  • If a null key is added, it will replace the existing null key if present.

  • Example: HashMap map = new HashMap<>(); map.put(null, 1);

Add your answer

Q31. What is the javascript

Ans.

JavaScript is a programming language commonly used for creating interactive effects within web browsers.

  • JavaScript is a high-level, interpreted programming language.

  • It is used to make web pages interactive and dynamic.

  • JavaScript code can be embedded directly into HTML pages.

  • Commonly used for client-side web development.

  • Examples include form validation, interactive maps, and dynamic content updates.

Add your answer

Q32. What is front developer j

Ans.

Front-end developers are responsible for creating the user interface and user experience of a website or application.

  • Front-end developers use languages like HTML, CSS, and JavaScript to build the visual elements of a website.

  • They work closely with designers to implement the visual aspects of a website or application.

  • Front-end developers focus on creating a responsive and user-friendly interface for users to interact with.

  • Examples of front-end frameworks include React, Angular...read more

Add your answer

Q33. How to prevent hash coliseum

Ans.

Preventing hash collisions in Java

  • Use a good hash function that distributes keys evenly

  • Implement a resizing strategy for hash tables

  • Use open addressing or separate chaining to handle collisions

  • Consider using a hash table library like Guava or Apache Commons

  • Avoid using mutable objects as keys in hash tables

Add your answer

Q34. What is functional interface

Ans.

Functional interface is an interface with only one abstract method, used for lambda expressions.

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

  • It is used for lambda expressions and functional programming in Java.

  • Examples of functional interfaces in Java are Runnable, Callable, and Comparator.

Add your answer

Q35. How to using java programming

Ans.

Java programming can be used to develop various applications such as web, desktop, mobile, and enterprise applications.

  • Java can be used to create dynamic web applications using frameworks like Spring, Struts, and Hibernate.

  • Java can be used to develop desktop applications using JavaFX and Swing.

  • Java can be used to create mobile applications using Android Studio and Java ME.

  • Java can be used to develop enterprise applications using Java EE and EJB.

  • Java can also be used for scien...read more

Add your answer

Q36. What is synchronisation?

Ans.

Synchronization is the process of controlling access to shared resources in a multi-threaded environment.

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

  • It prevents race conditions and data inconsistencies.

  • It can be achieved using synchronized keyword, locks, and semaphores.

  • Example: Synchronizing a method or a block of code that accesses a shared variable.

  • Example: Using locks to ensure mutual exclusion between threads.

Add your answer

Q37. Explain diamond problem in java

Ans.

Diamond problem occurs in multiple inheritance when a class inherits from two classes that have a common ancestor.

  • Occurs in Java when a class inherits from two interfaces that have a common method signature

  • Results in ambiguity as to which method implementation should be used

  • Can be resolved using default methods in interfaces introduced in Java 8

Add your answer

Q38. What is javascript

Ans.

JavaScript is a high-level, interpreted programming language used for creating interactive websites.

  • JavaScript is commonly used for client-side web development.

  • It can be used to create dynamic and interactive web pages.

  • JavaScript can also be used for server-side development with Node.js.

  • Examples include form validation, interactive maps, and dynamic content updates.

Add your answer

Q39. What is Hasting?

Ans.

Hasting is not a known term in the context of Java development.

    Add your answer

    Q40. What is cloning?

    Ans.

    Cloning is creating an exact copy of an object.

    • Cloning is done using the clone() method.

    • The cloned object is a separate instance with the same state as the original.

    • Changes made to the cloned object do not affect the original object.

    • Cloning can be shallow or deep depending on the implementation.

    • Example: cloning an ArrayList to create a backup copy.

    Add your answer

    Q41. spring beans how works

    Ans.

    Spring beans are Java objects managed by the Spring IoC container. They are defined in the Spring configuration file and are instantiated, assembled, and managed by the container.

    • Spring beans are defined in the Spring configuration file using XML or annotations.

    • The Spring IoC container is responsible for instantiating, assembling, and managing the beans.

    • Beans are singleton by default, but can be configured as prototype or other scopes.

    • Dependencies between beans are managed by...read more

    Add your answer

    Q42. What are Java basic

    Ans.

    Java basics include syntax, data types, control structures, and object-oriented programming concepts.

    • Syntax: Java code is written in classes and methods.

    • Data types: Java has primitive and reference data types.

    • Control structures: Java has if-else, switch, for, while, and do-while loops.

    • Object-oriented programming: Java supports encapsulation, inheritance, and polymorphism.

    • Examples: int x = 5; String name = "John"; if (x > 0) { System.out.println("Positive"); } class Car { Stri...read more

    Add your answer

    Q43. Explain features of java 8

    Ans.

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

    • Lambda expressions allow for more concise code and easier parallel programming.

    • Streams provide a new way to work with collections and perform operations in a functional style.

    • Functional interfaces enable the use of lambda expressions.

    • Default methods allow interfaces to have method implementations.

    • Optional class helps to avoid null pointer exceptions.

    Add your answer

    Q44. Short map value using Java 8

    Ans.

    Use Java 8 to shorten map values

    • Use map() and collect() methods

    • Use lambda expressions to modify values

    • Example: map.replaceAll((k, v) -> v.substring(0, 5))

    • Example: map.values().stream().map(s -> s.substring(0, 5)).collect(Collectors.toList())

    Add your answer

    Q45. Internal workings of HashMap

    Ans.

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

    • HashMap uses an array of linked lists to store key-value pairs.

    • The key is hashed to determine the index in the array where the value will be stored.

    • If multiple keys hash to the same index, a linked list is used to handle collisions.

    • HashMap allows one null key and multiple null values.

    • Example: HashMap map = new HashMap<>();

    Add your answer

    Q46. Linked list vs array list

    Ans.

    Linked list is dynamic in size, allows for efficient insertion/deletion. Array list is fixed in size, allows for random access.

    • Linked list is efficient for insertion/deletion due to dynamic size.

    • Array list is efficient for random access due to fixed size.

    • Linked list uses pointers to connect elements, while array list uses indexes.

    • Example: Linked list is used in applications where frequent insertions/deletions are required. Array list is used when random access is needed.

    Add your answer

    Q47. Overriding vs Overloading

    Ans.

    Overriding is when a subclass provides a specific implementation of a method in its superclass, while overloading is when multiple methods have the same name but different parameters.

    • Overriding involves changing the behavior of a method in a subclass, while overloading involves creating multiple methods with the same name but different parameters.

    • Overriding is used for runtime polymorphism, while overloading is used for compile-time polymorphism.

    • Example of overriding: supercl...read more

    Add your answer

    Q48. Explain the html

    Ans.

    HTML is a markup language used for creating web pages.

    • HTML stands for HyperText Markup Language.

    • It uses tags to structure content on a web page.

    • Common tags include , , , <body>, <p>, <div>, <a>, <img>.</p></li><li><p>Attributes can be added to tags to provide additional information.</p></li><li><p>HTML can be styled using CSS and made interactive with JavaScript.</p></li></ul>

    Add your answer

    Q49. What java

    Ans.

    Java is a high-level, object-oriented programming language used to develop applications for various platforms.

    • Java is platform-independent and can run on any platform with a JVM.

    • It is used for developing web, mobile, desktop, and enterprise applications.

    • Java has a vast library of pre-built classes and APIs.

    • It supports multithreading, exception handling, and garbage collection.

    • Java is widely used in the industry for its security, scalability, and performance.

    • Examples of Java-b...read more

    Add your answer

    Q50. Why java

    Ans.

    Java is a popular, versatile, and reliable programming language used for developing a wide range of applications.

    • Java is platform-independent, making it easy to write code once and run it on multiple platforms.

    • It has a vast library of pre-built classes and APIs, making development faster and easier.

    • Java is highly secure and provides built-in features for encryption and authentication.

    • It is widely used in enterprise applications, web development, mobile app development, and mo...read more

    Add your answer

    Q51. acid properties

    Ans.

    ACID properties are a set of properties that guarantee database transactions are processed reliably.

    • ACID stands for Atomicity, Consistency, Isolation, Durability

    • Atomicity ensures that all operations in a transaction are completed successfully or none at all

    • Consistency ensures that the database remains in a consistent state before and after the transaction

    • Isolation ensures that transactions are executed independently of each other

    • Durability ensures that once a transaction is c...read more

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

    Interview Process at null

    based on 17 interviews in the last 1 year
    1 Interview rounds
    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.8
     • 20 Interview Questions
    4.0
     • 18 Interview Questions
    3.5
     • 16 Interview Questions
    3.7
     • 10 Interview Questions
    3.6
     • 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