Java Developer Trainee
20+ Java Developer Trainee Interview Questions and Answers
Q1. What are 4 pillors of oops concept? And explain them with example.
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
Q2. What is difference between array and collection?
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
Q3. Find the lowest number from an arraylist using streams
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
Q4. Is string mutable or immutable? And why?
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.
Q5. Wap using control flow Statment to create two object according to input.
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
Q6. What is map? Explain about collection hierarchy
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
Share interview questions and help millions of jobseekers 🌟
Q7. What is multi threading?
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
Q8. Demonstrate inheritance in java with code
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
Java Developer Trainee Jobs
0Q9. Steps for jdbc to connect database.
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
Q10. Configuring server port in a spring boot app
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
Q11. Difference between collection and map.
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.
Q12. Why java is objected programming language
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
Q13. Abstract and anonymous classes in java
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
Q14. Find duplicate alphabets in a string
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
Q15. How to compare objects in java
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.
Q16. Life cycle of thread.
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
Q17. Reverse a given string
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
Q18. Find vowels from a string
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.
Q19. Why java is independent platform
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
Q20. How Hashmap works internally
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
Q21. Explain controller in spring
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
Q22. What is collection framework
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
Q23. Wap to merge two array.
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.
Q24. What is functional interface
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
Q25. Use of refresh scope
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(); }
Q26. Annotations in Hibernate
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.
Q27. Oops concept in Java program
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 Questions of Similar Designations
Top Interview Questions for Java Developer Trainee 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