Java Developer
200+ Java Developer Interview Questions and Answers for Freshers
Q51. 1. What are four pillars of OOPS ?
The four pillars of OOPS are Abstraction, Encapsulation, Inheritance, and Polymorphism.
Abstraction: Hiding implementation details and showing only necessary information.
Encapsulation: Binding data and methods together to protect data from outside interference.
Inheritance: Creating new classes from existing ones, inheriting properties and methods.
Polymorphism: Ability of objects to take on multiple forms or behaviors.
Q52. How can a Spring Boot project be created to develop an API that returns specified data?
A Spring Boot project can be created to develop an API by setting up a new Spring Boot project, defining API endpoints, and implementing the necessary logic.
Create a new Spring Boot project using Spring Initializr
Define API endpoints using @RestController annotation
Implement the logic to return specified data in the API endpoints
Use @GetMapping, @PostMapping, @PutMapping, @DeleteMapping annotations to map HTTP methods to controller methods
Q53. What is the code to print a right-angled triangle of numbers based on a given input number?
Use nested loops to print a right-angled triangle of numbers based on input.
Use two nested loops to control the rows and columns of the triangle.
Increment the number to be printed in each row.
Example: If input is 5, the output would be: 1, 12, 123, 1234, 12345
Q54. Explain Security management, how to enable security for APIs.
Security management involves implementing measures to protect APIs from unauthorized access and ensure data integrity.
Implement authentication mechanisms such as OAuth or API keys to control access to APIs
Use encryption to secure data transmission between clients and APIs
Implement rate limiting to prevent abuse and protect against denial of service attacks
Regularly update and patch API security vulnerabilities to stay protected
Monitor API traffic and logs for suspicious activ...read more
Q55. Write a functional interface. Refer it to a Lamda Expression. Show it practically while explaining each step
A functional interface is a single abstract method interface. It can be referred to using a lambda expression.
Functional interfaces have only one abstract method
Lambda expressions can be used to implement functional interfaces
Lambda expressions provide a concise way to write anonymous functions
Functional interfaces can be used as method parameters or return types
Q56. What is collection framework?
Collection framework in Java is a set of classes and interfaces that provide a way to store and manipulate groups of objects.
Collection framework provides interfaces like List, Set, and Map for storing and manipulating groups of objects.
It includes classes like ArrayList, LinkedList, HashSet, and HashMap that implement these interfaces.
Collections in Java provide methods for adding, removing, and accessing elements in a collection.
It allows for easy iteration over elements us...read more
Share interview questions and help millions of jobseekers 🌟
Q57. 21. Difference between array and heap?
Arrays are fixed in size and stored in stack memory, while heap is dynamic and stored in heap memory.
Arrays are declared with a fixed size, while heap can grow or shrink dynamically.
Arrays are stored in stack memory, while heap is stored in heap memory.
Arrays can only store elements of the same data type, while heap can store objects of different types.
Examples of arrays include int[], char[], and String[], while examples of heap objects include ArrayList, HashMap, and Linked...read more
Q58. 22. Can we add duplicates to Set?
No, Set does not allow duplicates.
Set is a collection that does not allow duplicates.
If you try to add a duplicate element to a Set, it will not be added.
You can use a List if you need to allow duplicates.
Java Developer Jobs
Q59. 23. Can we add duplicates to Array?
Yes, duplicates can be added to an array.
Arrays in Java can contain duplicate elements.
Duplicate elements can be added to an array using the add() method of ArrayList class.
For example, int[] arr = {1, 2, 3, 3, 4}; or ArrayList<Integer> list = new ArrayList<>(Arrays.asList(1, 2, 3, 3, 4));
Q60. What is HashMap? While Interating through it is it mutable?
HashMap is a data structure in Java that stores key-value pairs. It is mutable while iterating through it.
HashMap is part of the Java Collections Framework.
It allows null values and at most one null key.
It provides constant-time performance for basic operations like get and put.
While iterating through a HashMap, it is mutable and can throw ConcurrentModificationException if modified.
To avoid this, use an Iterator or ConcurrentHashMap.
Q61. If you perer this language to why?
I prefer Java because of its versatility, strong community support, and extensive libraries.
Java is a versatile language that can be used for a wide range of applications.
It has a strong community support with a large number of developers and resources available.
Java has extensive libraries that provide ready-made solutions for various tasks.
It offers platform independence, allowing the code to run on different operating systems.
Java's object-oriented nature promotes code reu...read more
Q62. How does OOPs in Java work explain it's benefits with real life examples?
OOP in Java organizes code into objects, enhancing modularity, reusability, and maintainability.
Encapsulation: Bundling data and methods. Example: A 'Car' class with attributes like 'speed' and methods like 'accelerate()'.
Inheritance: Reusing code through parent-child relationships. Example: 'ElectricCar' inherits from 'Car', adding features like 'chargeBattery()'.
Polymorphism: Methods can take many forms. Example: A method 'start()' can behave differently for 'Car' and 'Bike...read more
Q63. What are the benefits of using JAR (Java Archive) files in Java?
JAR files package Java classes and resources, enhancing distribution, versioning, and execution efficiency.
1. Packaging: JAR files bundle multiple Java classes and resources (like images and properties files) into a single archive, simplifying distribution.
2. Versioning: JAR files can include version information in their manifest, helping manage dependencies and ensuring compatibility.
3. Compression: JAR files use ZIP compression, reducing file size and improving download tim...read more
Q64. What are the methods for encrypting and decrypting data within the OSI model?
Encryption and decryption methods can be applied at various layers of the OSI model to secure data transmission.
Application Layer: Use of SSL/TLS for encrypting HTTP traffic (HTTPS).
Transport Layer: Implementation of secure protocols like DTLS for UDP traffic.
Network Layer: IPsec can encrypt data packets for secure communication over IP.
Data Link Layer: WPA2 encrypts data in wireless networks to protect against eavesdropping.
Q65. What are the uses of Data Structures and Algorithms (DSA) in programming?
Data Structures and Algorithms optimize data management and processing, enhancing performance and efficiency in programming tasks.
Efficient data storage: Arrays, linked lists, and trees help organize data for quick access.
Optimized searching: Algorithms like binary search reduce time complexity when finding elements in sorted data.
Improved performance: Using appropriate data structures can significantly speed up operations, e.g., hash tables for fast lookups.
Resource manageme...read more
Q66. What are the various annotations used in SpringBoot (explain)
Various annotations used in SpringBoot
1. @SpringBootApplication: Marks the main class of a Spring Boot application
2. @RestController: Marks a class as a RESTful controller
3. @RequestMapping: Maps HTTP requests to handler methods
4. @Autowired: Injects dependencies automatically
5. @Component: Marks a class as a Spring component
6. @Service: Marks a class as a service component
7. @Repository: Marks a class as a repository component
8. @Configuration: Marks a class as a source of b...read more
Q67. 15. What is protected ?
protected is a Java access modifier that allows access within the same package and subclasses.
Protected members can be accessed within the same package and subclasses.
It is used to provide encapsulation and prevent direct access from outside the class.
Protected members can be accessed using the dot operator.
Example: protected int num; can be accessed in a subclass using obj.num;
Q68. 19. What are collections?
Collections are objects that group multiple elements into a single unit.
Collections are used to store, retrieve, manipulate and communicate aggregate data.
Java provides a set of interfaces and classes that implement various types of collections.
Examples of collections include List, Set, Map, Queue, etc.
Collections can be used to improve code readability, reusability, and performance.
Q69. Write a program to find the numbers divisble by 3 in a string - and reverse its indexes eg : - input : String s = "123456789" output String s = "129456783"
Program to find numbers divisible by 3 in a string and reverse their indexes.
Iterate through the string and check if each character is a number divisible by 3.
Store the divisible numbers in an array and reverse their indexes.
Join the array back into a string and return the result.
Q70. Why you want to Change from mechanical to IT? Distinguish between JRE JVM JDK?
I transitioned from mechanical to IT because of my passion for technology and problem-solving.
Passion for technology and problem-solving led me to pursue a career in IT
Enjoyment of coding and creating software applications
Opportunities for growth and learning in the IT field
Mechanical background provides a unique perspective and problem-solving skills in IT
Example: I found coding more fulfilling and challenging than mechanical engineering tasks
Q71. What is threads. Different types of threads? What is interitance . types of inheritance?
Threads are lightweight processes that enable multitasking. Inheritance is a mechanism of creating a new class from an existing class.
Threads allow multiple tasks to run concurrently within a single program
Types of threads include user threads, daemon threads, and system threads
Inheritance allows a new class to inherit properties and methods from an existing class
Types of inheritance include single inheritance, multiple inheritance, and hierarchical inheritance
Q72. What is compile time polymorphism and runtime polymorphism?
Compile time polymorphism is achieved through method overloading, while runtime polymorphism is achieved through method overriding.
Compile time polymorphism is also known as static polymorphism.
It is achieved by having multiple methods in the same class with the same name but different parameters.
Example: method overloading in Java.
Runtime polymorphism is also known as dynamic polymorphism.
It is achieved by having a method in a superclass and a method with the same signature ...read more
Q73. Why we need Java ? What is Polymorphism Can we use return type in constructer
Java is a widely used programming language known for its platform independence and extensive libraries.
Java is platform independent, meaning it can run on any operating system
Java has a large standard library with pre-built classes and methods for common tasks
Java is object-oriented, allowing for modular and reusable code
Java supports multithreading, enabling concurrent execution of tasks
Java has automatic memory management through garbage collection
Java is widely used in ent...read more
Q74. Difference between error and exception ?
Error is a serious issue that cannot be handled at runtime, while exception is a runtime issue that can be handled.
Errors are caused by the environment in which the application is running, while exceptions are caused by the application code.
Errors cannot be caught or handled, while exceptions can be caught and handled using try-catch blocks.
Examples of errors include OutOfMemoryError and StackOverflowError, while examples of exceptions include NullPointerException and ArrayIn...read more
Q75. 8. Can we have multiple try block
Yes, we can have multiple try blocks in Java.
Multiple try blocks can be used to handle different exceptions separately.
Each try block must have at least one catch or finally block.
Nested try blocks can also be used.
Example: try { //code } catch (Exception e) { //code } try { //code } catch (IOException e) { //code }
Example of nested try blocks: try { try { //code } catch (Exception e) { //code } } catch (Exception e) { //code }
Q76. What is method overloading?
Method overloading is when multiple methods have the same name but different parameters.
Method overloading allows for more flexibility in method calls.
The methods must have different parameters, such as different data types or different numbers of parameters.
Example: public void print(int num) and public void print(String str)
Overloading constructors is also common in Java.
Q77. What are the differences between the TCP/IP suite and the OSI model?
Q78. What was the need for the User Datagram Protocol (UDP), and how does it affect streaming?
Q79. What programming language do you learn.
I have learned Java programming language.
Java is a widely used programming language for developing various applications.
It is an object-oriented language known for its platform independence.
Java is used for developing web, desktop, mobile, and enterprise applications.
It has a large standard library and supports multithreading, networking, and database connectivity.
Some examples of Java frameworks are Spring, Hibernate, and JavaFX.
Q80. Explain Sonarqube, different type of code smells, and how its implemented in CI CD
Sonarqube is a static code analysis tool used to detect code smells and bugs in code. It is integrated into CI/CD pipelines for continuous code quality checks.
Sonarqube is a static code analysis tool that identifies code smells, bugs, and security vulnerabilities in code.
Code smells are common programming issues that may indicate a deeper problem in the code. Examples include duplicated code, long methods, and complex conditionals.
Sonarqube can be integrated into CI/CD pipeli...read more
Q81. How many ways to create the object in java
There are multiple ways to create objects in Java.
Using the 'new' keyword
Using object cloning
Using object deserialization
Using reflection
Using factory methods
Using dependency injection frameworks
Q82. How do you do authentication and authorisation in your java spring boot app
Authentication and authorization in a Java Spring Boot app involves using Spring Security for managing user access.
Use Spring Security to handle authentication and authorization
Configure security settings in the application.properties file
Implement custom authentication providers if needed
Use annotations like @PreAuthorize and @Secured for method-level security
Q83. What is the difference between Call By value and call by reference
Call by value passes a copy of the value while call by reference passes the address of the value.
Call by value passes a copy of the value while call by reference passes the address of the value.
In call by value, any changes made to the parameter inside the function do not affect the original value outside the function.
In call by reference, any changes made to the parameter inside the function affect the original value outside the function.
Java uses call by value for primitive...read more
Q84. 6. What is exception handing
Exception handling is the process of handling errors and exceptions that occur during program execution.
Exceptions are objects that represent errors or exceptional situations that occur during program execution.
Exception handling involves catching and handling these exceptions to prevent program crashes.
Java provides try-catch-finally blocks for handling exceptions.
Examples of exceptions include NullPointerException, ArrayIndexOutOfBoundsException, and FileNotFoundException.
Q85. 7. Why we use throw and throws ?
throw is used to explicitly throw an exception while throws is used to declare the exception that a method may throw.
throw is used to handle exceptional situations in the code
throws is used to declare the exceptions that a method may throw
throw is followed by an instance of an exception class
throws is followed by the list of exceptions that a method may throw
throw is used inside a method
throws is used in the method signature
Q86. What is the use of final key word in java
The final keyword in Java is used to restrict the user from modifying the value of a variable, the definition of a method, or the inheritance of a class.
When applied to a variable, the final keyword makes it a constant that cannot be changed.
When applied to a method, the final keyword prevents it from being overridden by subclasses.
When applied to a class, the final keyword prevents it from being extended by other classes.
Final variables must be initialized and cannot be reas...read more
Q87. How to rollback a transaction in spring boot
To rollback a transaction in Spring Boot, use @Transactional annotation and throw an exception
Use @Transactional annotation on the method where the transaction needs to be rolled back
Throw an exception within the method to trigger the rollback process
Spring will automatically rollback the transaction when an exception is thrown
Q88. How to write a test case for a private method
Use reflection to access and test private methods
Use reflection to access the private method in the test case
Set the method accessible using setAccessible(true)
Invoke the method with the necessary parameters and assert the expected result
Q89. What are checked and unchecked exceptions
Checked exceptions are checked at compile time, while unchecked exceptions are not.
Checked exceptions must be either caught or declared in the method signature using 'throws' keyword
Unchecked exceptions do not need to be caught or declared
Examples of checked exceptions: IOException, SQLException
Examples of unchecked exceptions: NullPointerException, ArrayIndexOutOfBoundsException
Q90. What is inheritance in java?
Inheritance in Java allows a class to inherit properties and methods from another class.
Inheritance is achieved using the 'extends' keyword.
The class that is being inherited from is called the superclass or parent class.
The class that inherits from the superclass is called the subclass or child class.
Subclasses can access the public and protected members of the superclass.
Inheritance promotes code reusability and allows for the creation of hierarchical relationships.
Q91. Find the duplicate element in a given array using Java 8 features.
Find duplicate element in array using Java 8 features.
Convert array to stream using Arrays.stream()
Use Collectors.groupingBy() to group elements by their occurrence
Filter the grouped elements to find duplicates
Q92. Why use in java to Javascript
Java and JavaScript are two different programming languages with different use cases.
Java is used for building server-side applications, Android apps, and enterprise software.
JavaScript is used for building interactive web applications and front-end development.
Java is a compiled language while JavaScript is an interpreted language.
Java is statically typed while JavaScript is dynamically typed.
Java code runs on the Java Virtual Machine (JVM) while JavaScript code runs on web ...read more
Q93. What are the difference between array and list in java
Arrays are fixed in size, while lists can grow dynamically. Lists can hold objects of different types.
Arrays are of fixed size, while lists can grow dynamically.
Arrays can hold only elements of the same type, while lists can hold objects of different types.
Arrays are faster for accessing elements, while lists are faster for adding or removing elements.
Arrays are implemented as a simple object, while lists are implemented as a linked list.
Examples: int[] arr = new int[5]; List...read more
Q94. What are the different bean scopes in Spring
The different bean scopes in Spring are singleton, prototype, request, session, and application.
Singleton scope creates a single instance of a bean per Spring IoC container.
Prototype scope creates a new instance of a bean every time it is requested.
Request scope creates a new instance of a bean for each HTTP request.
Session scope creates a new instance of a bean for each HTTP session.
Application scope creates a single instance of a bean per ServletContext.
Q95. Create package and call tha class in anotherclassby using object on oops
Create a package in Java and call a class from that package in another class using object-oriented programming principles.
Create a package by using the 'package' keyword at the beginning of the Java file.
Define a class within the package and create an object of that class in another class.
Import the package in the class where you want to use the class from the package.
Access the class from the package using the object created in the other class.
Q96. explain opps concept, what is spring boot
OOPs concept is a programming paradigm based on the concept of objects, Spring Boot is a framework for building Java applications.
OOPs concept stands for Object-Oriented Programming, which focuses on creating objects that interact with each other to solve problems.
It involves concepts like inheritance, encapsulation, polymorphism, and abstraction.
Spring Boot is a framework that simplifies the development of Java applications by providing pre-configured settings and tools.
It a...read more
Q97. what are all the difficulties do have experianced
Difficulties faced as a Java Developer
Debugging complex code
Handling legacy code
Working with outdated technologies
Managing project timelines and expectations
Collaborating with non-technical stakeholders
Q98. which design pattern to use for complex design?
Use the Strategy design pattern for complex design.
Strategy pattern allows you to define a family of algorithms, encapsulate each one, and make them interchangeable.
It helps in separating the behavior of a class from the class itself, making it easier to switch between different algorithms at runtime.
Examples of using Strategy pattern include implementing different sorting algorithms in a class or defining various payment methods in an e-commerce application.
Q99. 1.First Non repetitive character using steam. 2. Sort array of string on the basis of first character using steam. 3. Find longest word in string array.
Q100. Number Plate Using Array MultiDimension Array
Creating a number plate using a multidimensional array of strings.
Create a 2D array of strings to represent the number plate
Use loops to populate the array with the required characters
Print the array to display the number plate
Interview Questions of Similar Designations
Top Interview Questions for Java Developer Related Skills
Interview experiences of popular companies
Calculate your in-hand salary
Confused about how your in-hand salary is calculated? Enter your annual salary (CTC) and get your in-hand salary
Reviews
Interviews
Salaries
Users/Month