Tutorial

Java Interview Questions

Published on August 3, 2022
    author

    Pankaj

    Java Interview Questions

    While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.

    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.

    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. https://www.youtube.com/watch?v=\_y7k\_0edvuY

    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.

    Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

    Learn more about us


    About the authors
    Default avatar
    Pankaj

    author

    Still looking for an answer?

    Ask a questionSearch for more help

    Was this helpful?
     
    JournalDev
    DigitalOcean Employee
    DigitalOcean Employee badge
    October 16, 2018

    For(;;) 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.

    - Ajinkya

      JournalDev
      DigitalOcean Employee
      DigitalOcean Employee badge
      October 7, 2017

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

      - Ketan

        JournalDev
        DigitalOcean Employee
        DigitalOcean Employee badge
        September 25, 2017

        Very useful in cracking the interview. Thanks for sharing.

        - Nitin

          JournalDev
          DigitalOcean Employee
          DigitalOcean Employee badge
          May 19, 2016

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

          - milindu

            JournalDev
            DigitalOcean Employee
            DigitalOcean Employee badge
            February 26, 2016

            Thank you for taking time in it and providing us.

            - jijo

              JournalDev
              DigitalOcean Employee
              DigitalOcean Employee badge
              February 18, 2016

              that makes life easy :) thanks for consolidating it.

              - rohit

                JournalDev
                DigitalOcean Employee
                DigitalOcean Employee badge
                January 18, 2016

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

                - ranjeet yadav

                  JournalDev
                  DigitalOcean Employee
                  DigitalOcean Employee badge
                  December 12, 2015

                  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.

                  - chandiprasad

                    JournalDev
                    DigitalOcean Employee
                    DigitalOcean Employee badge
                    November 2, 2015

                    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 wipro=“5” technologies=“12”

                    - Ritu Rh

                      JournalDev
                      DigitalOcean Employee
                      DigitalOcean Employee badge
                      September 23, 2015

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

                      - Jt

                        Try DigitalOcean for free

                        Click below to sign up and get $200 of credit to try our products over 60 days!

                        Sign up

                        Join the Tech Talk
                        Success! Thank you! Please check your email for further details.

                        Please complete your information!

                        Featured on Community

                        Get our biweekly newsletter

                        Sign up for Infrastructure as a Newsletter.

                        Hollie's Hub for Good

                        Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

                        Become a contributor

                        Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

                        Welcome to the developer cloud

                        DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

                        Learn more
                        DigitalOcean Cloud Control Panel