Frequently Asked Interview Questions And Answers For Java Freshers

50,000+ Students Trained, 19+ Our Offices, 18+ Courses Offered,

Job Guarantee + Job Satisfaction, 2000+ Company Tie Ups For Placements

Java Interview Questions

Core Java Interview Question  

  1. What is the Difference between ArrayList and LinkedList ?
AnsArrayList : Array list uses Dynamically array to represent . Its implements list interface only because it contain object only… Its have good performance for searching and accessing data from object.   LinkedList : LinkedList uses Doubly link list array to represent. Its implements list and queue only because it contain object. Its have good performance for data manipulation data.
  1. How can we create immutable class in java?
Ans: We can create immutable class as the String class by defining final class and Final Instance Variable.
    1. Why String is immutable or final in Java ?
Ans: String Pool is possible because String is immutable in java. Since String is immutable, it’s safe to use in multi-threading and we don’t need any synchronization. Strings are used in java classloader and immutability provides security that correct class is getting loaded by Classloader
      1. What is the Difference between String Builder And String Buffer in Java ?
Ans: String Builder : Is  non synchronized. Is not thread safe. Is  fast output given better than string buffer. String Buffer: Is a synchronized. Is a thread safe. Is not fast output given better than string builder
      1. Can We Declare A Constructor As A Private in java ?
Ans: Yes, Private constructors are used in singleton design pattern, factory method design pattern.  
      1. What is polymorphism?
Ans: Poly means many and morphism means forms. Polymorphism is a Greek word one named has a different different forms.  
      1. Should a main() method be compulsorily declared in all java classes?
Ans :No not required. main() method should be defined only if the source class is a java application.
      • When you want to run the code so at that time main() is required.
      1. Can we extend one interface to another Interface in java?
Ans: Yes
      1. How to prevent a method from being overridden in java?
Ans: We can prevent method By specifying final keyword to the method you can avoid overriding in a subcalss. Similarllyone can use final at class level toprevent creating subclasses.   10.  What is transient variable in java? Ans: Transient variables cannot be serialized. During serialization process, transient variable states will not be serialized. State of the value willbe always defaulted after deserialization.   16.Can we overload a main() method in java ? Ans:  Yes. You can have any number of main() methods with different method signatureand implementation in the class.  
      1. What is a native method in java?
Ans: A native method is a method that is implemented in a language other than Java.  
      1. What is Singleton class in java?
Ans: Singleton class control object creation, limiting the number to one but allowing the flexibility to create more objects if the situation changes
      1. Why Packages are used in java ?
Ans:Packages are used in Java in-order to prevent naming conflicts, to control access, to make searching/locating and usage of classes, interfaces, enumerations and annotations, etc., easier.
      1. Define immutable object in java?
Ans:An immutable object can’t be changed once it is created.
      1. How does multi-threading take place on a computer with a single CPU?
Ans:The operating system’s task scheduler allocates execution time to multiple tasks. By quickly switching between executing tasks, it creates the impression that tasks execute sequentially. 22. What is the benefit of Generics in Collections Framework? Ans:Java 1.5 came with Generics and all collection interfaces and implementations use it heavily. This avoids ClassCastException at Runtime because you will get the error at compilation. Also Generics make code clean since we don’t need to use casting and instanceof operator. I would highly recommend to go through Java Generic  to understand generics in a better way.   Advance Java Interview Question  
      1. Explain the Life Cycle Of JSP pages in java ?
Ans: here is the step by step process of JSP lifecycle –
      • Translation of JSP page
      • Compilation of JSP page
      • Classloading
      • Instantiation
      • Initialization
      • Request Processing
      • Destroy
      1. What is the ServletContext in java?
Ans: A servlet context object contains the information about the Web application of which the servlet is a part. It also provides access to the resources common to all the servlets in the application. Each Web application in a container has a single servlet context associated with it.
      1. What is a deployment descriptor in java ?
Ans:  A deployment descriptor is an XML document with an .xml extension. It defines a component’s deployment settings. It declares transaction attributes and security authorization for an enterprise bean. The information provided by a deployment descriptor is declarative and therefore it can be modified without changing the source code of a bean.
      1. What is session?
Ans:A session refers to all the requests that a single client might make to a server in the course of viewing any pages associated with a given application. Sessions are specific to both the individual user and the application.
      1. How can we destroyed session in servlet?
Ans:  we can destroy the session using – Using session.invalidate() method.
      1. What is the difference between the ServletConfig and ServletContext interface?
Ans: The ServletConfig interface is implemented by the servlet container in order to pass configuration information to a servlet. The server passes an object that implements the ServletConfig interface to the servlet’s init () method. A ServletContext defines a set of methods that a servlet uses to communicate with its servlet container.
      1. How do I use cookies to store session state on client?
In a servlet, the HttpServletResponse and HttpServletRequest objects passed to method HttpServlet. Service () can be used to create cookies on the client and use cookie information transmitted during client requests. JSPs can also use cookies, in scriptlet code or, preferably, from within custom tag code.
      • To set a cookie on the client, use the addCookie() method in class HttpServletResponse. Multiple cookies may be set for the same request, and a single cookie name may have multiple values.
      • To get all of the cookies associated with a single HTTP request, use the getCookies() method of class HttpServletRequest
8 . What is servlet lazy loading? Ans:  A container does not initialize the servlets as soon as it starts up; it initializes a servlet when it receives a request for that servlet first time. This is called lazy loading.  
      1. What Is Web Services?
  Web service Is a communication between two devices over network.
      • It’s a one kind of protocol and exchanging information between two devices or application.
      • And web services uses with client server application for communication.
      • Web service is a language independent.
      1. What is the Advantage of Hibernate in Java ?
      • Easy to maintain relationship between tables and persists classes.
      • It support criteria and query so we can easily define complex query.
      • It has a lot of api to create dynamic SQL Commands.
      • It will generate database tables automatic.
  11 .What is Dependency Injection? Ans:Inversion of Control (IoC) is a general concept, and it can be expressed in many different ways and Dependency Injection is merely one concrete example of Inversion of Control. This concept says that you do not create your objects but describe how they should be created. You don’t directly connect your components and services together in code but describe which services are needed by which components in a configuration file. A container (the IOC container) is then responsible for hooking it all up.  
      1. What Is Spring MVC Concept?
Ans:MVC pattern results in separating the different way of the application like (input logic, business logic, and UI logic..etc…).  
      • to use MVC in spring framework by the help of DispatcherServlet.
      • DispatcherServletclass represent as the front controller.
      • The @Controllerannotation is used to mark the class as the controller in Spring 3.
      • The @RequestMappingannotation is used to map the request url. It is applied on the method.
  Practical Interview Question:
      1. Swaping Program Without Using 3rd Variable
  publicclass MYCLASS {   publicstaticvoid main(String[] args) { inta,b; a=10; b=20;   System.out.println(“a = “+a); System.out.println(“b = “+b);   a=a+b; b=a-b; a=a-b; System.out.println(“After change : “); System.out.println(“\na = “+a); System.out.println(“b = “+b); } }  
      1. Fibonacci Program
    publicclass MYCLASS {   publicstaticvoid main(String[] args) { intf=0,s=1,next;   System.out.print(f+”\t”+s);   inti=1; while(i<=5) { next=f+s; System.out.print(“\t”+next); f=s; s=next; i++; } } }    
      1. Reverse The String Without Using String Handling Functions.
  public class Reverse { static int i,c=0,res; static void stringreverse(String s) { char ch[]=new char[s.length()]; for(i=0;i < s.length();i++) ch[i]=s.charAt(i); for(i=s.length()-1;i>=0;i–) System.out.print(ch[i]); } public static void main (String args[]) { System.out.println(“Original String is : “); System.out.println(“my name is Rahul “); Reverse.stringreverse(” my name is Rahul “); } }
      1. Challenges You Are Facing In Your Current Project.
When too much high level coding create at that time so much problems occur so those challenges I facing in project. such as(like mailcoding,facebook integration, payment mechanism )so all kink of challenges will handle in project sometimes error did not remove from coding at same days but with in 2 3 days those error should be removed from the current project.

Tips & Tricks

Latest Blog

Which country is better for Indian Students for Study Abroad?17th November, 2018

Canada is one amongst the most effective places to pursue your higher studies and therefore the coun

How to migrate to Canada?17th November, 2018

Have you more experienced necessary facts and options regarding Canada? If no, then you are here at

Study Abroad with Minimum finance17th November, 2018

Some students might wonder how they can study abroad with less money. When they can’t find a spons

How to Become a Good Designer?8th October, 2018

Graphic, Web, Animation, VFX, UI, UX There are plethora of options for a designer to make an amaz

Is Digital Marketing a Right Career For You?2nd October, 2018

Digital Marketing is an industry in itself that is growing rapidly since its inception. And since th

Our Events

Gyanmanjari Institute Of Technology Industrial Visits on 30th June 2018

Gyanmanjari Institute Of Technology Industrial Visits on 30th June at TOPS Technologies TOPS Techno

Android, Laravel, Python, Java and iOS Workshop at TOPS Technology

Android, Laravel, Python, Java and iOS Workshop at TOPS Technology We are happy to share that once

Project Documentation Workshop at TOPS Technologies

Project Documentation Workshop TOPS Technologies have organized “Project documentation” worksho

Final Year Project Documentation Workshop

Final Year Project Documentation Workshop Project Documentation, Project Definition, project Submis

Industrial Visit in the month of March and April at TOPS Technologies

Industrial Visits in the month of March and April at TOPS Technologies TOPS Technologies always bel