Java Developer Trainee

20+ Java Developer Trainee Interview Questions and Answers

Updated 12 Jul 2025
search-icon
2d ago

Q. What are 4 pillors of oops concept? And explain them with example.

Ans.

The 4 pillars of OOP are Abstraction, Encapsulation, Inheritance, and Polymorphism.

  • Abstraction: Hiding implementation details and showing only necessary information. Example: A car dashboard only shows necessary information like speed, fuel level, etc.

  • Encapsulation: Binding data and methods that manipulate the data together. Example: A bank account class with methods to deposit, withdraw, and check balance.

  • Inheritance: Creating new classes from existing ones, inheriting their...read more

4d ago

Q. What is the difference between an array and a collection?

Ans.

Arrays are fixed in size and can store elements of the same type, while collections are dynamic and can store elements of different types.

  • Arrays have a fixed length, while collections can grow or shrink dynamically.

  • Arrays can only store elements of the same type, while collections can store elements of different types.

  • Arrays use indexed access for retrieval and modification, while collections provide various methods for manipulation.

  • Arrays are part of the core Java language, ...read more

Java Developer Trainee Interview Questions and Answers for Freshers

illustration image

Q. How can you find the lowest number from an ArrayList using streams?

Ans.

Find the lowest number from an arraylist using streams

  • Use stream.min() method to find the lowest number

  • Pass Comparator.naturalOrder() to get the lowest number

  • Handle empty list scenario using OptionalInt

5d ago

Q. Is string mutable or immutable? And why?

Ans.

String is immutable because its value cannot be changed once it is created.

  • String objects are stored in the String pool, which is a part of the heap memory.

  • When a string is modified, a new string object is created with the modified value.

  • Immutable strings are thread-safe and can be safely shared among multiple threads.

  • String immutability allows for efficient memory utilization and optimization.

Are these interview questions helpful?

Q. Write a program using control flow statements to create two objects based on user input.

Ans.

Create two objects based on user input using control flow statements in Java.

  • Use Scanner class to take user input

  • Use if-else or switch statements to create objects based on input

  • Instantiate objects with appropriate constructors

Q. What is map? Explain about collection hierarchy

Ans.

Map is an interface in Java that maps unique keys to values.

  • Map is a part of the Java Collections Framework

  • It is used to store key-value pairs

  • Some common implementations of Map are HashMap, TreeMap, and LinkedHashMap

Asked in Infosys

3d ago

Q. What is multi threading?

Ans.

Multi threading is the concurrent execution of multiple threads in a single program.

  • Allows multiple tasks to run concurrently

  • Improves performance and responsiveness

  • Enables efficient utilization of CPU resources

  • Can be used for parallel processing

  • Examples: running multiple calculations simultaneously, handling multiple client requests

Q. What is for each loop and write the syntax. What is jdcb .

Ans.

The for-each loop simplifies iteration over arrays and collections in Java, enhancing code readability and reducing errors.

  • Syntax: for (Type element : collection) { // code }

  • Example with array: String[] fruits = {"Apple", "Banana", "Cherry"}; for (String fruit : fruits) { System.out.println(fruit); }

  • Example with List: List<String> colors = Arrays.asList("Red", "Green", "Blue"); for (String color : colors) { System.out.println(color); }

  • The for-each loop cannot modify the under...read more

Share interview questions and help millions of jobseekers 🌟

man-with-laptop
5d ago

Q. What are the steps for JDBC to connect to a database?

Ans.

JDBC steps to connect to a database

  • Load the JDBC driver class

  • Establish a connection to the database using the DriverManager class

  • Create a statement object to execute SQL queries

  • Execute the SQL queries and retrieve the results

  • Close the statement and connection objects

Q. Demonstrate inheritance in Java with code.

Ans.

Inheritance in Java allows a class to inherit properties and methods from another class.

  • Use the 'extends' keyword to create a subclass that inherits from a superclass

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

  • Example: class Dog extends Animal { ... }

  • The 'super' keyword is used to call the superclass constructor or method

Q. How do you configure the server port in a Spring Boot application?

Ans.

To configure server port in a Spring Boot app, modify the application.properties file.

  • Open the application.properties file

  • Add the following line: server.port=8080 (or any desired port number)

  • Save the file and restart the application

Q. Why is Java an object-oriented programming language?

Ans.

Java is an object-oriented programming language because it allows for the creation of objects, which can contain data and methods.

  • Java supports the four pillars of object-oriented programming: encapsulation, inheritance, polymorphism, and abstraction.

  • Objects in Java can be easily reused and extended through inheritance.

  • Java classes and objects help in organizing code and making it easier to maintain and understand.

  • Example: In Java, you can create a class 'Car' with properties...read more

4d ago

Q. What is the difference between a collection and a map?

Ans.

Collection is a group of objects while Map is a key-value pair data structure.

  • Collection is used to store and manipulate a group of objects.

  • Map is used to store and retrieve data based on key-value pairs.

  • Collection classes include List, Set, and Queue.

  • Map classes include HashMap, TreeMap, and LinkedHashMap.

  • Collections allow duplicate elements while Maps do not.

  • Example: Collection - List of names, Map - Student ID and corresponding name.

Q. Abstract and anonymous classes in java

Ans.

Abstract classes are incomplete classes that cannot be instantiated. Anonymous classes are unnamed classes that can be created on the fly.

  • Abstract classes are declared with the 'abstract' keyword and can have abstract and non-abstract methods.

  • Anonymous classes are created using the 'new' keyword and can extend a class or implement an interface.

  • Anonymous classes are often used for event handling and callbacks.

  • Example of abstract class: abstract class Shape { abstract void draw...read more

Q. Write a function to find duplicate characters in a string.

Ans.

Program to find duplicate alphabets in a string

  • Create a HashMap to store the frequency of each alphabet

  • Iterate through the string and update the frequency in the HashMap

  • Iterate through the HashMap and print the alphabets with frequency greater than 1

Q. How do you connect JDBC and Java?

Ans.

JDBC (Java Database Connectivity) is an API that enables Java applications to interact with databases using SQL.

  • DriverManager: Use DriverManager to establish a connection to the database. Example: Connection conn = DriverManager.getConnection(url, user, password);

  • JDBC URL: Specify the database URL in the connection string. Example: String url = 'jdbc:mysql://localhost:3306/mydb';

  • PreparedStatement: Use PreparedStatement for executing parameterized queries, which helps prevent ...read more

5d ago

Q. How do you compare objects in Java?

Ans.

Objects in Java can be compared using the equals() method or by implementing the Comparable interface.

  • Use the equals() method to compare objects for equality.

  • Implement the Comparable interface and override the compareTo() method to define custom comparison logic.

  • For comparing custom objects, override the equals() and hashCode() methods for proper comparison.

Asked in Cognizant

3d ago

Q. What is the life cycle of a thread?

Ans.

The life cycle of a thread refers to its various states and transitions during its execution.

  • A thread starts in the new state when it is created.

  • It moves to the runnable state when it is ready to run but waiting for the CPU.

  • When the CPU starts executing the thread, it enters the running state.

  • A thread can temporarily move to the blocked or waiting state when it is waiting for a resource or signal.

  • A thread can be terminated and move to the dead state when it completes its exec...read more

Asked in BMC Software

1d ago

Q. Given a string, reverse the order of its characters and return the reversed string.

Ans.

Reverse a given string

  • Iterate through the string from end to start and append each character to a new string

  • Use StringBuilder or StringBuffer for better performance

  • Convert the string to a character array and swap the first and last characters, then move towards the middle until the entire string is reversed

Asked in Cognizant

5d ago

Q. Why is Java platform independent?

Ans.

Java is independent platform due to its ability to run on any hardware or operating system.

  • Java programs are compiled into bytecode which can be run on any Java Virtual Machine (JVM)

  • JVM acts as an abstraction layer between the Java program and the underlying hardware/OS

  • Write once, run anywhere principle allows Java programs to be platform-independent

Q. Write a function to find all vowels in a given string.

Ans.

A Java program to find vowels from a given string.

  • Create a string variable and initialize it with the given string.

  • Use a for loop to iterate through each character of the string.

  • Check if the character is a vowel using if statement and add it to a new string variable.

  • Print the new string variable containing all the vowels.

Asked in Cognizant

5d ago

Q. How does HashMap work internally?

Ans.

HashMap in Java uses hashing to store key-value pairs and provides constant-time performance for basic operations.

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

  • When a key-value pair is added, the key is hashed to determine the index in the array where the pair will be stored.

  • If multiple keys hash to the same index (collision), a linked list or balanced tree is used to store multiple entries at that index.

  • HashMap provides constant-time performance for basic operati...read more

Q. Explain the role of a controller in Spring.

Ans.

Controller in Spring is responsible for handling user requests and returning appropriate responses.

  • Controller receives requests from the client and delegates them to appropriate handlers

  • It maps the incoming requests to the corresponding handler methods

  • It returns the response to the client after processing the request

  • It can also handle exceptions and errors that occur during request processing

Asked in Coforge

2d ago

Q. What is the Collection Framework?

Ans.

Collection framework is a set of classes and interfaces that provide a way to store and manipulate groups of objects.

  • It provides interfaces like List, Set, Queue, etc. for storing collections of objects

  • It also provides classes like HashMap, TreeMap, etc. for storing key-value pairs

  • It simplifies the task of storing, sorting, searching, and manipulating collections of objects

  • It is a part of the Java API and is widely used in Java programming

Asked in HCLTech

2d ago

Q. What is a functional interface?

Ans.

Functional interface is an interface with only one abstract method.

  • Functional interface can have any number of default or static methods

  • It is used for lambda expressions and method references

  • Examples include Runnable, Comparator, and Function interfaces

Asked in Mindteck

3d ago

Q. Write a program to merge two arrays.

Ans.

Merging two arrays of strings in Java.

  • Create a new array with size equal to the sum of sizes of both arrays.

  • Copy elements of first array to the new array.

  • Copy elements of second array to the new array starting from the end of first array.

  • Return the new array.

6d ago

Q. Annotations in Hibernate

Ans.

Annotations in Hibernate are used to provide metadata about the entity class and its properties.

  • Annotations are used to map Java classes to database tables and properties to columns.

  • Annotations reduce the need for XML configuration files in Hibernate.

  • Examples of annotations in Hibernate include @Entity, @Table, @Column, @Id, @GeneratedValue, etc.

Q. What is the use of refresh scope?

Ans.

Refresh scope is used in Spring framework to control the lifecycle of beans.

  • Refresh scope is used to create a new instance of a bean every time it is requested.

  • It is useful when the state of a bean needs to be reset on every request.

  • To use refresh scope, add @RefreshScope annotation to the bean definition.

  • Example: @Bean @RefreshScope public MyBean myBean() { return new MyBean(); }

Asked in TCS

6d ago

Q. Explain the OOPS concepts in Java.

Ans.

Oops concept in Java program refers to Object-Oriented Programming principles like inheritance, encapsulation, polymorphism, and abstraction.

  • Inheritance allows a class to inherit properties and behavior from another class.

  • Encapsulation hides the internal state of an object and only exposes necessary methods to interact with it.

  • Polymorphism allows objects of different classes to be treated as objects of a common superclass.

  • Abstraction focuses on the essential characteristics o...read more

Interview Experiences of Popular Companies

TCS Logo
3.6
 • 11.1k Interviews
Infosys Logo
3.6
 • 7.9k Interviews
Capgemini Logo
3.7
 • 5.1k Interviews
LTIMindtree Logo
3.7
 • 3k Interviews
Zoho Logo
4.2
 • 540 Interviews
View all

Top Interview Questions for Java Developer Trainee Related Skills

interview tips and stories logo
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories
Java Developer Trainee Interview Questions
Share an Interview
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits