Add office photos
Engaged Employer

Cognizant

3.8
based on 47k Reviews
Proud winner of ABECA 2024 - AmbitionBox Employee Choice Awards
Filter interviews by

20+ Interview Questions and Answers

Updated 23 Sep 2024
Popular Designations

Q1. What array list and linkedlist difference,how hashmap internally working,what is synchronised and it's type,what is difference between abstract and interface,class loading mechanism in Java, you hat is single t...

read more
Ans.

Java Developer interview questions covering array list, linkedlist, hashmap, synchronization, abstract vs interface, singleton class, Spring framework, database configuration, and Java 8 features.

  • ArrayList and LinkedList differ in terms of implementation, performance, and usage

  • HashMap uses hashing to store and retrieve key-value pairs

  • Synchronized is used to ensure thread safety and prevent race conditions

  • Abstract classes cannot be instantiated and can have both abstract and n...read more

Add your answer

Q2. write program fibonacci series, write program using boolean, write class cast exceptn, singleton design pattern(like you have to jvm one have jdk 1.7 and other have jdk 1.8 how many instance created if one then...

read more
Ans.

This interview question covers various topics including programming, design patterns, data structures, and exception handling in Java.

  • Write a program to generate the Fibonacci series

  • Write a program using boolean variables

  • Explain the ClassCastException and how to handle it

  • Discuss the Singleton design pattern and its implementation with different JDK versions

  • Explain abstract classes and interfaces in your current project

  • Explain hashing in HashMap and the number of buckets

  • Differ...read more

View 3 more answers

Q3. Difference between List and Set? which one to prefer in which requirements and why ?

Ans.

List allows duplicates and maintains insertion order, Set doesn't allow duplicates and doesn't maintain order.

  • Use List when duplicates are allowed and order is important

  • Use Set when duplicates are not allowed and order is not important

  • List examples: ArrayList, LinkedList

  • Set examples: HashSet, TreeSet

Add your answer

Q4. 1. What is jvm 2.Explain Oops 3.Sql queries 4. Rest Api 5. coding problem (Sort arraylist) 6. Known Sorting Algorithm

Ans.

Interview questions for Java Developer

  • JVM is a virtual machine that executes Java bytecode

  • OOPS is a programming paradigm based on objects and classes

  • SQL queries are used to retrieve data from a database

  • REST API is a web service that uses HTTP requests to access and manipulate data

  • Sorting an ArrayList can be done using Collections.sort() method

  • Known sorting algorithms include Bubble Sort, Quick Sort, and Merge Sort

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

Q5. how to create immutable classes?

Ans.

Immutable classes cannot be modified after creation. They ensure thread safety and prevent bugs.

  • Make the class final so it cannot be extended

  • Make all fields private and final

  • Do not provide any setters, only getters

  • If a field is mutable, return a copy of it in the getter

  • Consider using a builder pattern for complex objects

View 1 answer

Q6. How to implement Spring security with JWT token?

Ans.

Implementing Spring security with JWT token involves configuring security filters and authentication providers.

  • Add dependencies for Spring Security and JWT

  • Configure security filters to validate JWT tokens

  • Implement authentication provider to authenticate users

  • Generate and sign JWT tokens for successful authentication

  • Example: https://www.baeldung.com/spring-security-jwt

Add your answer
Are these interview questions helpful?

Q7. how to create singleton class ?

Ans.

Singleton class is a class that can only have one instance at a time.

  • Create a private constructor to prevent instantiation from outside the class.

  • Create a private static instance of the class.

  • Create a public static method to get the instance of the class.

  • Ensure thread safety by using synchronized keyword or static initializer.

  • Example: public class Singleton { private static Singleton instance = null; private Singleton() {} public static synchronized Singleton getInstance() { ...read more

Add your answer

Q8. Find second largest number using java 8 features Write a java program to reverse a string few questions about springboot and core java

Ans.

Use Java 8 features to find the second largest number and reverse a string.

  • Use streams and collectors to find the second largest number in an array.

  • Use StringBuilder to reverse a string in Java 8.

  • For Spring Boot questions, focus on dependency injection, auto-configuration, and RESTful services.

  • For core Java questions, focus on OOP concepts, collections, and exception handling.

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

Q9. What is idempotency? Solid ? Design patterns used in projects

Ans.

Idempotency is the property of an operation where multiple identical requests have the same effect as a single request.

  • Idempotency ensures that even if the same request is made multiple times, the result will be the same.

  • In RESTful APIs, using HTTP methods like GET and PUT can help achieve idempotency.

  • Design patterns like Command Pattern and State Pattern can be used to ensure idempotency in projects.

Add your answer

Q10. How to sort an array list

Ans.

To sort an array list, use the Collections.sort() method.

  • Import the java.util.Collections class

  • Call the sort() method and pass the array list as parameter

  • Ensure the objects in the array list implement the Comparable interface or pass a Comparator object as second parameter

View 1 answer

Q11. internal working of hashmap?

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

  • Each bucket contains a linked list of entries

  • Hashing is used to determine the index of the bucket where the entry should be stored

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

  • HashMap allows null keys and values

  • HashMap is not thread-safe and requires synchronization for concurrent...read more

Add your answer

Q12. Given a string , print the letter and the number of times it occurs

Ans.

Print each letter in a string along with the number of times it occurs

  • Iterate through the string and count the occurrences of each letter

  • Use a HashMap to store the letter as key and count as value

  • Print the letter and count for each unique letter

Add your answer

Q13. How HashMap works internally?

Ans.

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

  • HashMap uses hashing to store and retrieve values based on their keys.

  • It uses an array of buckets to store the key-value pairs.

  • The hash code of the key is used to determine the index of the bucket where the pair will be stored.

  • If two keys have the same hash code, they are stored in the same bucket as a linked list.

  • HashMap allows null keys and values, but only one null key.

  • The i...read more

Add your answer

Q14. How do you get data from database in spring boot?

Ans.

Data can be retrieved from a database in Spring Boot using JPA repositories or JDBC templates.

  • Use JPA repositories to create custom queries and retrieve data from the database.

  • Use JDBC templates to execute SQL queries and retrieve data from the database.

  • Configure the data source in the application.properties file.

  • Use annotations like @Repository, @Entity, @Table, etc. to map Java objects to database tables.

Add your answer

Q15. Explain runtime polymorphism and compile time polymorphism

Ans.

Runtime polymorphism occurs when a method is overridden in a subclass, while compile time polymorphism occurs when method overloading is used.

  • Runtime polymorphism is achieved through method overriding, where a subclass provides a specific implementation of a method that is already provided by its parent class.

  • Compile time polymorphism is achieved through method overloading, where multiple methods with the same name but different parameters are defined in the same class.

  • Runtim...read more

Add your answer

Q16. How to make class immutable?

Ans.

To make a class immutable in Java, you can follow certain guidelines to ensure that its state cannot be changed once it is created.

  • Make the class final so that it cannot be extended.

  • Make all fields private and final to prevent modification.

  • Do not provide setter methods for the fields.

  • If the fields are mutable objects, return copies of them instead of the original objects in getter methods.

View 1 answer

Q17. What is java and python

Ans.

Java and Python are programming languages used for developing software applications.

  • Java is an object-oriented language used for developing desktop, web, and mobile applications.

  • Python is a high-level language used for web development, data analysis, artificial intelligence, and scientific computing.

  • Java is compiled and runs on a virtual machine, while Python is interpreted.

  • Java is statically typed, while Python is dynamically typed.

  • Java has a strong emphasis on type safety a...read more

Add your answer

Q18. What is Static Method?

Ans.

Static method is a method that belongs to the class itself, not to any specific instance of the class.

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

  • They are commonly used for utility methods that do not require access to instance variables.

  • Static methods are declared using the 'static' keyword.

  • Example: Math.max() is a static method in the Math class that returns the maximum of two numbers.

Add your answer

Q19. Explain oops concepts

Ans.

OOPs concepts are the fundamental principles of object-oriented programming.

  • Encapsulation: Hiding the implementation details of an object and exposing only the necessary information.

  • Inheritance: Creating new classes from existing ones, inheriting their properties and methods.

  • Polymorphism: The ability of objects to take on many forms, allowing them to behave differently in different situations.

  • Abstraction: Focusing on the essential features of an object and ignoring the non-es...read more

Add your answer

Q20. Long term goal explain

Ans.

To become a technical lead and contribute to the development of innovative solutions.

  • I aim to continuously improve my technical skills and knowledge.

  • I want to gain experience in leading a team and managing projects.

  • I aspire to work on challenging projects that require creative problem-solving.

  • I hope to make a positive impact on the company and its customers through my work.

  • Example: I want to lead a team in developing a cutting-edge AI-powered application that revolutionizes t...read more

Add your answer

More about working at Cognizant

Top Rated Mega Company - 2024
Top Rated IT/ITES Company - 2024
HQ - Teaneck. New Jersey., United States (USA)
Contribute & help others!
Write a review
Share interview
Contribute salary
Add office photos

Interview Process at null

based on 4 interviews in the last 1 year
1 Interview rounds
Coding Test 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.7
 • 156 Interview Questions
3.9
 • 41 Interview Questions
3.9
 • 37 Interview Questions
3.6
 • 32 Interview Questions
4.0
 • 14 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