Showing posts with label Interview Questions. Show all posts
Showing posts with label Interview Questions. Show all posts

Monday, September 7, 2026

Birla Soft Interview Question and Answers for Java 2- 4 year experience

The below questions asked by Birla Soft for Java/J2EE. I tried to give the best answer , hope it will help you out to crack the interview.

Q. Tell me about your self?
 Ans:  Give your brief introduction.

Q. Is Java Pass by Reference or Pass by Value?
Ans : Its always pass by value .

Q. What is the difference between an Interface and an Abstract class?
Ans : Both are looks similar. But, the basic difference is abstract class can contain abstract and non abstract methods, where interface only contains abstract method (without method body). You can declare fields that are not static and final, and define public, protected, and private concrete methods in abstract class. But, in Interface all members are public, static and final , all methods are public.

Q. What is the purpose of garbage collection in Java, and when is it used?
Ans : Garbage collection is a special feature in java language. It helps developer to save time and extra mental tension for handling object allocation in memory. It automatically clean the unused object from memory which helps to allocate space at runtime. When there is no reference to an object found, it will clean that object from memory . You can run the garbage collection explicitly by using System.gc() .

Q. What is Marker interface? How is it used in Java?
Ans : Marker interface is an interface which help us to notify few information to JVM/Compiler. The marker interface does not have any body, it’s a empty interface. Ex. Cloneable, Serialization, etc.            

Q. Can you give few examples of final classes defined in Java API?
Ans: String, Integer ,Float ,etc. Basically all wrapper classed are final.

Q. What is the importance of init() method in Servlet?
Ans:  init() method is one of the life cycle method of servlet. This method runs once in total life. After servlet instance created and before it handles request the init() method will work. Its basically used for initializing values at the time of application startup.

Q. How to improve Servlet Performance ?
Ans: You need to do few tuning for this achievement. Few points below :-

1.     Use init() method for all expensive operation during initialization (may be static data or cached data ).
2.     Always avoid auto loading of servlet.
3.     Avoid SingleThreadModel.
4.     Use and control HttpSession properly.

Q. How can a Servlet refresh automatically if some new data has entered the database?
Ans :  Basically it depends on the scenario , how you can handle. You need  handle this in DAO layer, when doing insert operation you can call an utility method which will load the context ServletContextListener. Because, servlets are basically used for handling request and give the response.

Q. How does JSP handle run-time exceptions?
Ans: You can use isErrorPage=”true” in page attribute.

Q. What is an EJB Context?
Ans: The EJBContext interface provides an instance with access to the container-provided runtime context of an enterprise bean instance.

Accenture Java Interview Questions and Answers

Accenture interview question for Java 3-8 year experience.

Q1. Why do you want to work in this industry / company?

Ans: First you should try to convince that this company gives huge opportunity in many aspect i.e. new technologies implementation, the policy of company suits you like professionalism.   Also you can mention that you are big fan of this company and its your dream company. Basically show your all positive attitude towards company.

Q2. Which location do you want to work in and why?

Ans : Give your own choice. Also mention a valid reason for why you are interested for that location. The reason should be always positive and clear. Example :- you can support your family from this location,

Q3. Describe a problem you faced and how you deal with it ?

Ans : You can describe any issue you faced during your project work in the organization. And what the solution you have implemented for that issue.

Q4. What are the types of class loaders in Java?

Ans  :  As per my knowledge there are basically 3 types of class loader like bootstrap class-loader,extension class loader and system class loader.
  • Bootstrap Class Loader
    Bootstrap class loader loads java’s core classes like java.lang, java.util etc. These are classes that are part of java runtime environment. Bootstrap class loader is native implementation and so they may differ across different JVMs.
  •  Extensions Class Loader
    JAVA_HOME/jre/lib/ext contains jar packages that are extensions of standard core java classes. Extensions class loader loads classes from this ext folder. Using the system environment property java.ext.dirs you can add ‘ext’ folders and jar files to be loaded using extensions class loader
  • System Class Loader
                  Java classes that are available in the java class-path are loaded using System class loader

Q5. Write your own ArrayList in Java ?

      Your own code here .

Q6. How to read and write image from a file ?

Ans : You can use ImageIo.read() and ImageIO.write()  method of javax.imageio package.

Q7. What is difference between static and init block in java.

Q8. How ConcurrentHashMap works?

Ans : The basic design of ConcurrentHashMap is to handling threading. Basically it locks each of the box (by default 16) which can be locked independently and thread safe for operation. And it does not expose the internal lock process.

Q9. Can a static block throw exception?

Ans : Yes. We can throw checked exception.

Q10. What is difference between iterator access and index access?

Ans : Basically iterator access process the traverse operation through each element, where index access process access direct the element by using the index.

Q11. Why character array is better than string for storing password in java?

Ans : Because, character array stores data in encrypted format which is not readable by human. But,the string stores the data in human readable format which is not secure.

Q12. what is daemon thread in java ?

Ans : A daemon thread is normally runs on background. And it does not prevent the JVM from exiting when the program finishes but the thread is still running.

Q13. What is Java Reflection API?

Ans  : Reflection is one of the most powerful API which help to work with classes, methods and variables  dynamically. Basically it inspect the class attributes at runtime. Also we can say it provides a metadata about the class. 

Q14. What is the difference between Serializable and Externalizable interfaces? 

Ans : Both interfaces are used for implement serialization. But, the basic difference is Serializable interface does not have any method (it’s a marker interface ) and Externalizable interface having 2 methods such as readExternal() and writeExternal(). Serializable interface is the super interface for Externalizable interface. 

Experienced Java/J2EE interview questions by MNC

Experienced Java/J2ee Interview questions asked by MNC.

1. Why main() in java is declared as public static void main? What if the main method is declared as
private?


Ans : Because, every program start execution from main function.The static method can directly call without creating the object of the class.So, before creating object the main function runs and then it creates object.

And, public in main method due to access by JVM. If the method is private then JVM cannot call that function.The program will compile but never run.It show the message  "Main method not public."


2.What is Externalization?

Ans : This interface is used for serialization.To save the state of an object in file. It provides two method
readExternal() and writeExternal().

3.What modifiers are allowed for methods in an Interface?
Ans : abstract and public

4.What are the different identifier states of a Thread?

Ans :
R- Running or Runnable
S- Suspended
MS- Thread Suspended on Monitor lock
MW- Thread waiting on monitor
CW- Thread waiting on condition variable


5.What are some alternatives to inheritance?

Ans : Delegation is an alternative to inheritance. Delegation means that you include an instance of another class as an instance variable, and forward messages to the instance. It is often safer than inheritance because it forces you to think about each message you forward, because the instance is of a known class, rather than a new class, and because it doesn’t force you to accept all the methods of the super class: you can provide only the methods that really make sense. On the other hand, it makes you write more code, and it is harder to re-use (because it is not a subclass).

6.Why isn’t there operator overloading?

Ans : Because C++ has proven by example that operator overloading makes code almost impossible to maintain.

7.What does it mean that a method or field is “static”?

Ans : Static method or field are member of class.They do not need any object for call or access . We can directly call the static method and fields without using the object.

Tavant Technologies Java Interview Questions - Experienced

Tavant Technologies
Round 1:F2F
1) Tell about your technical skills
2) How to work with Ajax applications?
4) Asked about page factory design concepts.
5) What are the collections u used in your project?
6) Framework explanation
7) How to find no of rows or columns in a table?
8) Diff b/w interface and abstract class?
9) Various oops concepts used in the project?
10) Roles and responsibilities.
11) SQL queries a) how to find duplicate records in a table b) Display the name of the employee who is getting         10th maximum salary
12) Logical questions:
i) A 2l bottle and a 4l bottle, By this u have to give me 3l of water? Is it possible? If yes tell me how
ii) 8 balls, having same color and weight, out of that 1 is defective, a physical balance is given, using this how to find the defective one.

Round 2
1. What is run-time polymorphism? Explain with program? Where is it achieved?
2. SQL queriesemp table fieldsename,eid,age
a) Find the name of the employee who has 3rd max age
b) Having clause and where clause
3. Logical questions
a) Cake in round shape, u have to cut the cake by 3 times only, and u have to divide into 8 equal pieces
b) Using 5 zeros, how to make it as 120
c) He gave me a paper, asked me to tore the paper once, to make 3 equal pieces


Round 3- HR+ Managerial round

1. Tell about your self
2. Why u r looking for the job?
3. What are the difficulties you faced in your previous job?
4. He is asking the same questions in different ways for 15 min
5. Framework
6. Difference b/w abstract class and interface.
7. Scenario-an abstract class implements an interface, can the abstract class implement the methods of interface?
8. From that he asked that do u perform auto it scripts in parallel execution?
9. Difference B/w primary key and unique key
10. Can unique key column hold null values? If yes how many null values?
11. Use of super keyword, order of execution
12. Collections u used in the project
13. When array will be used ? and when array list will be used?



Friday, September 4, 2026

Top 10 Spring Boot Interview Questions and Answers

In this post, we will discuss some top 10 interview questions in spring boot. These questions are tricky and trending now-a-days job market. These interview questions might suitable for 0 to 8 years of experience.

1)  What is @SpringBootApplication does internally ?

Ans :- As per spring boot doc,  @SpringBootApplication annotation is equivalent to using @Configuration, @EnableAutoConfiguration, and @ComponentScan with their default attributes. Spring boot enable the developer to use single annotation instead of using multiple. But, as we know spring provided loosely coupled features we can use each individual annotation as per our project needs.


2)  How to exclude any package without using the basePackages filter?

Ans:- Spring Boot allows you to exclude specific auto-configuration classes using the exclude attribute of @SpringBootApplication.

For example:

@SpringBootApplication(
    exclude = {DataSourceAutoConfiguration.class}
)
public class FooApplication {
}

You can also use excludeName when specifying the fully qualified class name:

@SpringBootApplication(
    excludeName = {
        "org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration"
    }
)
public class FooApplication {
}

The important point is that these options are used to exclude auto-configuration classes, not arbitrary application packages.



3)  How to disable a specific auto-configuration class?

Ans :-  You can use "exclude" attribute of @EnableAutoConfiguration. If you find that specific auto-configuration classes that you do not want 
are being applied. 

//By using "exclude"
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

On the other way , if the class is not on the class path, you can use the "excludeName" attribute of the annotation and specify the fully qualified name instead.

//By using "excludeName"
@EnableAutoConfiguration(excludeName={Foo.class})

Also spring boot provides the facility to control the list of auto-configuration classes to exclude by using the spring.autoconfigure.exclude property. You can add into the application.properties. You can add multiple classes with comma separated.

//By using property 
filespring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

 
4)  What is Spring Actuator? What are its advantages?

Ans :-  This is one of the most common interview question in spring boot. As per spring doc definition, "an actuator is a manufacturing term that refers to a mechanical device for moving or controlling something. Actuators can generate a large amount of motion from a small change". 

As we know spring boot provides lots of auto-configuration features which helps the developer to develop ready for production components quickly.But, if you think what about the debugging , how to debug if something goes wrong. As a developer we always need analyze the logs and dig the data flow of our application to check whats going on. So, spring actuator provides a easy access to all those kind of features. It provides many features i.e. what are the beans created, what are the mapping in controller, what is the CPU usage, etc.Automatically auditing, health, and metrics gathering can be applied to your application.

It provides very easy way to access with few production ready REST endpoints to fetch all these kind of information from web. By, using these endpoints you do many things see here the endpoint docs. Nothing to worry about security, if Spring Security is present then these endpoints are secured by default using Spring Security’s content-negotiation strategy. Else , we can configure custom security by the help of RequestMatcher.

5)  How to enable/disable the Actuator ? 

Ans :-  Enabling/Disabling the actuator is easy, the simplest way to enable the features is to add  the dependency to the spring-boot-starter-actuator i.e. Starter. If you don't want the actuator to be enable, then don't add the dependency.

Maven dependency - 
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>

Gradle dependency-

dependencies {
compile("org.springframework.boot:spring-boot-starter-actuator")
}

6)  What is Spring Initializer?

Ans :-  This may not be a difficult question , but the interviewer always checks the subject knowledge of the candidate. Its quite often that you can't expect questions that you have prepared :). However, this is very common question asked frequently in near time.

Spring initializer is a web application , which generates spring boot project with just what you need to start quickly.As always we need a good skeleton of the project, it help you to create a project structure/skeleton properly. Initializer here.

7)  What is shutdown in actuator? 

Ans :-  Shutdown is an endpoint which allows the application to be gracefully shutdown. This feature is not enabled by default.You can enable this by using management.endpoint.shutdown.enabled=true in your application.properties file. But, be careful about this if you are using this.

8)  Is this possible to change the port of Embedded Tomcat server in Spring boot?

Ans :-  Yes, its possible to change the port. You can use the application.properties file to change the port. you need to mention "server.port" (i.e. server.port=8081). Make sure you have application.properties in your project class path, rest spring framework will take care. If you mention server.port=0 , then it will automatically assign any available port.

9)  Can we override or replace the Embedded Tomcat server in spring boot ?

Ans :-  Yes, we can replace the embedded tomcat with any other servers by using the Starter dependencies.

You can use spring-boot-starter-jetty or spring-boot-starter-undertow as dependency as per your project need.

10)  Can we disable the default web server in the spring boot application?

Ans :-  The major strong point in spring is to provide flexibility to build your application loosely coupled. Spring provides features to disable the web server in a quick configuration. 

Yes, we can use the application.properties to configure the web application type i.e. spring.main.web-application-type=none

Saturday, July 13, 2019

Find All Palindrome Numbers from an Array in Java

In this article, we will see how to find all palindrome from an array. This is a very basic questions in interview, the interviewer will ask the same questions in different way. So, its good to know all possible questions from palindrome. Also there is a question to find all palindrome number from a list.  Find few more collection interview question.  Today we will see how to check a number is palindrome or not. 

FindAllPalindrome.java

package com.techbyteslearn.lab.basic;

public class FindAllPalindrome {
public static void main(String[] args) {
int numberArray[] = { 120, 990, 121, 777, 808, 1280 };
for (int i = 0; i < numberArray.length; i++) {
printOnlyPalindrom(numberArray[i]);
}
}
private static void printOnlyPalindrom(int number) {
int finalNumber = 0;
int oldNumber = number;
// Repeat the loop until the number became zero.
while (number != 0) {
// Get the First Digit (i.e. 1)
int firstDigit = number % 10;
// Get the Result number.
finalNumber = (finalNumber * 10) + firstDigit;
// Now get the remaining digits , after finding the first digit
number = number / 10;
}
// Now compare the finalNumber and oldNumber both are same or not.
if (finalNumber == oldNumber)
System.out.println(finalNumber + " is a Palindrome.");
}
}

Output -

121 is a Palindrome.
777 is a Palindrome.
808 is a Palindrome.

Tuesday, July 9, 2019

Java Comparator Example for custom sorting by employee age and department

This program illustrates , how to sort custom object using Comparator<T>. We have used Employee list to sort by age and department. As per the default ordering it will follow the natural ordering.

The below Employee class is our POJO , we will use this class to sort the employee list by age and department.

Employee.java

package com.javadevelopersguide.lab.basic;
/**
 * @author manoj.bardhan
 *
 */
public class Employee {
private String name;
private int age;
private String department;
public Employee(String name, int age, String department) {
super();
this.name = name;
this.age = age;
this.department = department;
}
@Override
public String toString() {
return "\n Employee [name=" + name + ", age=" + age + ", department=" + department + "]";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
}

Now, we need to create a comparator to compare two same objects. We can create as many comparators by implementing each field/attributes of the POJO. Its purely business requirement, how you need your sorting functionality. Here we need the sorting based on the employee  age and employee department.

EmployeeAgeComparator.java

package com.javadevelopersguide.lab.basic;
import java.util.Comparator;
/**
 * EmployeeAgeComparator is a comparator by Age.
 *
 * @author manoj.bardhan
 *
 */
public class EmployeeAgeComparator implements Comparator<Employee> {
@Override
public int compare(Employee emp1, Employee emp2) {
return emp1.getAge() - emp2.getAge();
}
}


EmployeeDeptComparator.java

package com.javadevelopersguide.lab.basic;
import java.util.Comparator;
/**
 * EmployeeDeptComparator is comparator by department.
 *
 * @author manoj.bardhan
 *
 */
public class EmployeeDeptComparator implements Comparator<Employee> {
@Override
public int compare(Employee emp1, Employee emp2) {
// Internally for comparing String we need to use compareTo()
return emp1.getDepartment().compareTo(emp2.getDepartment());
}
}

In the above we created two comparator for age and department. Now, we need to action on our comparators. We will call our newly created comparator from main() and see the result. Below EmployeeComparatorExample class show the comparator in action.


EmployeeComparatorExample.java

package com.javadevelopersguide.lab.basic;
import java.util.ArrayList;
import java.util.Collections;
/**
 * This program illustrates the simple use of Comparator<t> interface.
 *
 * @author manoj.bardhan
 *
 */
public class EmployeeComparatorExample {
public static void main(String[] args) {
Employee e1 = new Employee("Matt Kuban", 32, "IT");
Employee e2 = new Employee("Andrew Smith", 42, "HR");
Employee e3 = new Employee("Butler Jason", 52, "HR");
Employee e4 = new Employee("Miss Linda", 35, "HR");
Employee e5 = new Employee("Bradley Head", 23, "IT");
Employee e6 = new Employee("Peter Parker", 34, "ADMIN");
// Create an arraylist and add all the employee object into that list.
ArrayList<Employee> employeeList = new ArrayList<Employee>();
employeeList.add(e1);
employeeList.add(e2);
employeeList.add(e3);
employeeList.add(e4);
employeeList.add(e5);
employeeList.add(e6);
System.out.println("Employee Before Sort ::" + employeeList);
// Using EmployeeAgeComparator - to sort the employee by Age
EmployeeAgeComparator ageComparator = new EmployeeAgeComparator();
Collections.sort(employeeList, ageComparator);
// Using EmployeeDeptComparator - to sort the employee by Department
EmployeeDeptComparator deptComparator = new EmployeeDeptComparator();
Collections.sort(employeeList, deptComparator);
System.out.println("Employee After Sort ::" + employeeList);
}
}

Output :- 

Employee Before Sort ::[
 Employee [name=Matt Kuban, age=32, department=IT],
 Employee [name=Andrew Smith, age=42, department=HR],
 Employee [name=Butler Jason, age=52, department=HR],
 Employee [name=Miss Linda, age=35, department=HR],
 Employee [name=Bradley Head, age=23, department=IT],
 Employee [name=Peter Parker, age=34, department=ADMIN]]

Employee After Sort ::[
 Employee [name=Peter Parker, age=34, department=ADMIN],
 Employee [name=Miss Linda, age=35, department=HR],
 Employee [name=Andrew Smith, age=42, department=HR],
 Employee [name=Butler Jason, age=52, department=HR],
 Employee [name=Bradley Head, age=23, department=IT],
 Employee [name=Matt Kuban, age=32, department=IT]]

Happy Learning.