Java Interview Questions

Java Interview Questions

If you are preparing for a Java-based interview, it’s a good idea to go through Java Interview Questions. I have written a lot of interview questions articles in Core Java, Java EE to popular frameworks.

Java Interview Questions FAQs

Let’s go through some common questions before you read articles that focus on specific areas.

1. Which is the best site for Java Interview Questions?

There are tons of websites where you will find java interview questions. So how do you know which ones you should read?

The answer is simple – read the ones that cover the latest features. Also, read the articles where you can post comments. Most of the times, the author makes some mistakes or confusing statements. Then corrects them through user feedback coming through comments.

2. What are the popular topics for Java Interview?

Some of the popular topics for Java interview are:

  • OOPS Concepts
  • Java String
  • Collections Framework
  • Multithreading
  • Generics
  • Exception Handling
  • Stream API
  • Lambda Expressions
  • Latest Release Features
  • Java EE Frameworks – Spring, Hibernate etc.

3. What is Java used for?

We use Java programming everywhere. We use Java to create standalone programs, web applications, and web services. We can create distributed enterprise applications using Java EE frameworks.

4. What is Core Java?

Java SE is also called Core Java. It is the set of libraries that are part of standard java installation. For example, the Collections framework is part of Core Java. But, Servlet/JSP is part of Java Enterprise Edition.

5. What are the advanced Java Topics?

Some of the advanced java concepts are:

  • Heap and Stack Memory
  • Garbage Collection
  • Reflection API
  • Thread Deadlock
  • Java ClassLoader
  • Java Logging API
  • Internationalization in Java
  • Java Module System

6. Is Java a dying language?

Java is still one of the most popular programming languages. It’s still the first choice for enterprise applications. There are tons of free open source resources available to help you in Java programming. So I am not worried that Java is Dying at all.

7. What is difference between JavaScript and Java?

Some of the key differences between JavaScript and Java are:

  • Java is Object Oriented Programming Language. But, JavaScript is an Object Oriented Scripting language.
  • Java code runs in a virtual machine or browser (Applets) where JavaScript code runs on browser.
  • We have to compile Java source code to byte code before JVM can understand and execute it. JavaScript code is text based and we don’t need to compile it.
  • We use JavaScript to perform browser specific tasks. We use Java to create standalone utility apps, web applications, and web services.
  • JavaScript is lightweight whereas we have to install Java and configure it to run.

8. Which is better – Java or Python?

It’s like comparing Apples to Oranges. Both Java and Python are very popular programming languages. It depends on the project whether you want to use Java or Python or sometimes both together.

Here are some inputs based on my personal experience working with both Java and Python for a long time.

  • We prefer Java over Python to create web services or web applications. Java EE APIs and frameworks are robust and secure. Python frameworks such as Flask and Django are still evolving.
  • We prefer Python over Java to create a utility script because it’s more lightweight than Java.
  • We prefer Python for Data Science, Machine Learning, and Artificial Intelligence applications. It’s because most of the popular APIs in these areas are Python-based.

9. Who Created Java?

Java was first created by James Gosling at Sun Microsystems. The first public version was released in 1996.

10. What is the latest version of Java?

Java 12 is the latest version, released on March 19, 2019. Now, Oracle releases a new java version every 6 months. So you can expect Java 13 release in September 2019.

Java Interview Questions

1. Core Java Interview Questions and Answers

Core Java is the starting point of any Java interview. A strong grip on Core Java is a must to clear the Java interview for experienced as well as beginners. This article lists the most important core java interview questions with answers.

2. Java 8 Interview Questions

Java 8 was a major release with many new features. Some of them are Lambdas, Functional interfaces, Streams, and Date Time API. This article will help you in preparing for the interview related to these APIs.

I recently wrote another article as part-2 of java 8 interview questions.

3. Java Collections Interview Questions and Answers

Collections are core components of Java programming language. They are widely used in interview questions. The post contains 40+ questions on java collections to make sure all the topics are covered.

I also recommend you to read java collections tutorial.

4. Java String Interview Questions and Answers

The String is the most used Java class. Java interview usually starts with tricky questions related to String. This post contains 21 questions with detailed answers for String in Java.

5. Java Multi-Threading and Concurrency Interview Questions

Multithreading and Concurrency is a hot topic in Java interviews. It’s good to have good knowledge of Threads in Java. This post covers 30+ interview questions for Java Threads.

I also recommend you to read Java Thread Tutorial to gain good knowledge on Threads.

6. Java Exception Handling Interview Questions

Exception Handling is one of the tricky areas. Java provides a robust and object-oriented approach for exception handling. There are Exception, Error, and Throwable at the root of Exception Handling. I have seen so many guys who are confused in checked, unchecked, and runtime exceptions. Here you will go through a list of 15 questions related to Exception Handling in Java.

7. Difference between JDK, JRE and JVM

You should know about the Java virtual machine, runtime environment, and Java compiler. A post dedicated to explain these and list out their differences.

8. Java Classloaders

Java ClassLoader comes under advanced java concepts. This article provides a detailed explanation of different types of Java classloaders. You will learn how and when we should write our own classloaders with example programs.

9. Difference between Abstract Class and Interface

Abstract classes and interfaces are used in java for defining the contract. But, what is the difference between them? When should we use interface over the abstract class and vice versa?

It’s a great design question and asked a lot in java interviews. This post provides all the differences between abstract class and interface. When should we use interface over the abstract class and vice versa?

The post also explains how to use abstract class and interface to create a flexible design. I also recommend to read java abstract class and interface in java tutorials.

10. Why Java Doesn’t support multiple inheritance and Composition vs Inheritance

One of the most asked questions is why java doesn’t support multiple inheritances? Why should we prefer composition over inheritance? This article provides a detailed explanation of multiple inheritances. The issues with the inheritance that make composition a better approach.

11. Java Programming Interview Questions

Some tricky questions to test your programming skills. Also, check out java tricky code snippets.

12. Java 7 Catch Block

Java 7 has improved catch block to catch multiple exceptions in a single block. It’s a good improvement for making our catch block code small when we needed to catch a lot of exceptions.

13. Java Heap Memory vs Stack Memory

JVM runtime memory is divided into heap memory and stack memory. An important article explaining the difference between Heap and Stack memory through the program.

14. Java is Pass By Value or Pass by Reference

This is one of the most confusing questions about the Java programming language. Some say it’s pass by value and somewhere you will read that it’s pass by reference. Then again behavior changes for primitive types or Object parameters? Read this out to clear this confusion once and for all. This is one of the favorite questions asked by java interviewers.

Java EE Interview Questions

1. JDBC Interview Questions and Answers

If you are working on Enterprise applications, I am sure that JDBC API is a part of it. JDBC API provides database connectivity for relational databases, such as MySQL and Oracle.

This article has a collection of 40+ interview questions related to the JDBC API. They cover areas from basic Connection to DataSource to Connection Pooling. It will help you in interviews for questions related to JDBC API and how to use it.

If you are new to JDBC, I would suggest you go through JDBC Tutorial to make sure you have covered all the core parts of it.

2. Servlet Interview Questions with Answers

Servlets are one of the hot topics of Java Enterprise Edition interview questions. This post contains a list of 50 servlet interview questions with answers in detail. A must-have bookmarked post because I will keep on adding more questions in the future.

3. JSP Interview Questions and Answers

JSP is an integral part of Java EE. If you are giving an interview for a web developer, then having good knowledge of JSP is very important. This post contains a list of 35 JSP interview questions with answers. Please make sure to bookmark it because I will be kept on adding more to the list in the future.

4. Struts Interview Questions and Answers

Struts2 is one of the modern Java Web Application framework. This article contains a list of 30 questions with answers for Struts2 framework.

5. Spring Interview Questions and Answers

Spring Framework is the most widely used Java EE framework. It’s built on core principles of “Dependency Injection” and “Aspect-Oriented Programming”. This post contains more than 45 questions related to Spring Framework. They also cover Dependency Injection, Spring AOP, Spring JDBC, and Spring MVC.

6. Web Services Interview Questions

Web services are popular these days because they are language and platform independent. It’s easy to create SOAP and REST based web services. This post will help you learn about web services and related interview questions. Then there are questions with detailed answers for Java Web Services.

7. JSF Interview Questions

More than 50 questions on JSF-2 with detailed answers, go through them as a refresher on JSF framework.

8. Hibernate Interview Questions and Answers

Hibernate is the best Java-based ORM tool in the market. It’s used a lot in most of the enterprise applications to overcome the shortcomings of JDBC. Hibernate provides flexible configuration using XML, JPA annotations as well as through code. So it’s always a plus point to have Hibernate in your resume.

9. Scala Interview Questions

Scala is famous programming language that provides functional programming in Java. I have written three successive posts that you can go though for scala interview.

10. Common Job Interview Questions

For clearing an interview, only technical knowledge is not enough. You will have to go through common job interview questions. For example, your last company experience. Why you are looking for a change?. This article covers 40 common job interview questions.


  1. Ajinkya says:

    These is infinite loop
    All thing are optional but we put 1 or 0 or any negative value at condition like for (;1;)
    Then what will be output for any condition. It will be true or false.

    1. Rahul says:

      first of all this wont get compile

      Unresolved compilation problems:
      Syntax error on token “For”, for expected
      Type mismatch: cannot convert from int to boolean

  2. Ketan says:

    looks like link is broken / page not found for Restful Interview Questions link

    1. Pankaj says:

      Which URL you are pointing out? Everything seems working fine for me.

  3. Nitin says:

    Very useful in cracking the interview.

    Thanks for sharing.

  4. milindu says:

    very much appreciate you time spent on publishing this blog.!

  5. jijo says:

    Thank you for taking time in it and providing us.

  6. rohit says:

    that makes life easy 🙂
    thanks for consolidating it.

  7. ranjeet yadav says:

    very much thankful for impo.question of interviews plz provide all on my mail id as well,thanks in advance aswell.

  8. chandiprasad says:

    Thank you very much Pankaj for sharing such good collection of questions on wide variety of topics of java ,Your Book on Design patterns was really awesome.

    1. Pankaj says:

      Thanks Chandiprasad, you made my day. Please subscribe to our newsletter too where we share exclusive tips and free Books.

  9. Ritu Rh says:

    Please help me to get a java code to get number pin which is obtained by concatenating lengths of each word of the string .
    for example: number pin for “wipro Technologies” is 512

    1. Anjani Kumar Pathak says:

      String s=”Wipro Technologie”;

      String[] word=s.split(“\\s+”);
      String pincode=new String();
      for(String s1:word){


  10. Jt says:

    Can you please shade some light on the use/need of copy constructor.

    1. sandeep singh rawat says:

      the concept of copy constructor is supported in java. But unlike C++ java doesnot support the cocept of default copy constructor.
      Need of copy constructor:
      copy constructor is required when you want memory to be allocated for both the objects a and b belonging to the same class T.
      let us suppose a class T
      a and b are its objects
      a and b are then references created on stack.
      and there will be some memory allocated on heap
      Now, without copy constructor both will refer to same memory location.
      so to allocate the memory for both a and be seprately we have its solution as copy constructor.
      Thank u.

  11. Praveenkumar kodge says:


    A is a superclass it has subclass like B and C…..

    ur adding an superclass to an collection class, subclass of A will added into collation.

    u don’t want the subclass of A to add in collection then u please remove the inheritance between then….

  12. Paramesh says:

    Can any please tell me the solution for the below question:
    I have a super class named A,and few sub classes named B,C.The both sub classes B and C extends A.
    I want to add the super class object in the collection(like arraylist) not sub class objects.
    Which means the collection should allow only super class object not sub class object.

  13. Sonali says:

    Very good collection of question!!!

  14. PA says:

    Many Thanks. I’m not sure where to make a request to you. I can see you’ve covered tutorials for all latest technology, but I see one more important is missing which is JPA (Java Persistent API). May I request you to please create tutorials for same?

    1. Pankaj says:

      JPA is specification and Hibernate is the best implementation of that. I have covered Hibernate and if you read any of my Hibernate posts, you will notice that I am using JPA annotations only. I hope you got the point.

  15. test says:

    Could you please try to create a “Spring Security OAuth2” project with Twitter, Google and Facebook?

    Thank you.

  16. latha says:

    Nice info..very useful.plz post question on jax-ws webservices

  17. Pramod says:

    Very nice collection of interview questions….

    1. thrinadh says:

      quaisens r very nice it will be more usi full for java interviews wen they ask q r very tuff and q r very importent to reed

  18. Mayank Shrivasatava says:

    How to call Informatica workflow from Java

    1. mohan says:


  19. amit sen says:

    Thanks for helping …..

  20. Alexander says:

    You right simpe, short and very helpful articles.
    If you don’t mind please add questions about JMS.
    thank you

    1. Pankaj says:

      Thanks, I will post about it in near future.

      1. sampath kumar madala says:

        Hi pankaj,
        May i know your opinion on java certifications.

        1. Pankaj says:

          It’s good to have.

  21. venky says:

    interview questions class get locks to get top first 4 repeated words in file

  22. Hemanth kumar says:

    Thank q pankaj its very useful for my interview panel .And some more question on Hybernate and Struts,Servlets

  23. Rahul says:

    Please add hibernate interview questions also

  24. Lena says:

    Great thank you for the articles

  25. Vaibhav says:

    hi pankaj,

    plz upload tutorials for polymorphism too..

  26. Chandrshekar reddy says:

    please provide JSF and ADF question and documents

  27. Deepanshu says:

    This blog is very good. You have covered all the basic concept of java with proper explanation and example.
    And also you have provided the Interview questions on all topics which help the job seeker to get the job as well as his basic concepts also get build.

  28. manju says:

    thanks ton please add struts 1.x interview qstns

    1. Pankaj says:

      Struts 1.x is deprecated and EOL a long time ago, I would suggest you to not waste time on that.

      I believe it might be used in some legacy applications only now.

  29. Rajesh says:

    Good effort and easy understand each questions.Please post spring and hibernate tutorial and interview Q&A

  30. Mustafa says:

    Thanks a ton. Desperately waiting for similar posts for Hibernate and Springs 🙂

  31. Melwin Dmello says:

    Thanks a ton. This is very helpful.

  32. Ashok Dhulipalla says:

    This blog helps me a lot in interview preparations . Thanks

  33. Rahul Gupta says:

    Nice blog, please add some more question on spring, spring security & hibernate. This interview question really helpful for the interview preparation. Keep going on.

  34. vasanth says:

    Thank u sir,for providing this type of clear description to each concept.i am not seen like this in further.

  35. Kiran says:

    Thank you for sharing this….:)
    Helpful to us

  36. Mona says:

    What a great idea of posting potential questions!!! Thanks.

    1. supriya says:

      nice blog,,,,it’s very helpful for me tqz alot

  37. tasmiya mullani says:

    will you please tell me how to impliment breadcrumb using jquery or javascript.
    ( is a sample site where top categories shown i want structure like that)

  38. Snehal Masne says:

    Wonderful. Thanks for this! 🙂

  39. sidram says:

    How to call java methods in oracle methods?

Comments are closed.

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors