Press "Enter" to skip to content

Java Interview Questions and Answers for 2021

Robert Wagner (Information Technology) 0

The Tech Learn is sharing basics & Advanced Java Interview Questions and Answers for 2021 which will help you in clearing your java interview at the first try!

Read Also – Learn Java online Free

top 71 Java Interview Questions and Answers

  1. Why Java is platform independent?

    Java is also called platform independent due to the byte codes that can be easily run on any operating system.

  2. Why Java is not 100% Object-oriented?

    Java makes the use of 8 primitive data types which include char, Boolean, int, float, byte and short which do not come in object category that is why java is not 100% object-oriented programming language.

  3. What is JVM?

    JVM stands for Java Virtual Machine. JVM is an interpreter which accepts and executes the ‘Bytecode’

  4. List any five features of Java?

    Main features of the Java include Robust, Object Oriented, Multi-threaded, Platform Independent and Interpreted.

  5. Why Java is considered dynamic?

    Java is designed for adopting to a changing environment. Its programs carry large amount of information which can be very useful in resolving and verifying entrees to an object on the run-time.

  6. Define class?

    In the java, a class consists methods and fields for defining the nature of an object. It is a blue print which is responsible to create the objects.

  7. What do you know about Java?

    Java was released and developed by Sun Microsystems in 1995. It ia high level and object-oriented programming languages which can run on numerous platforms, which include Mac OS, Windows, and many more.

  8. Define Java Architectural Neutral?

    Java Architectural Neutral is a compiler which is used for generating an architecture-neutral object file format. With the java runtime system presence, its covert compiled code to executable form.

  9. Which platforms are supported by Java?

    Java runs of Mac OS, Windows and also on many versions of UNIX/Linux such as CentOS, Redhat Linux, Sun Solaris, HP-Unix, Ubuntu, etc.

  10. List any 5 IDE’s of Java?

    The 5 Java IDE’s are listed below:
    • Netbeans
    • Eclipse
    • BlueJ
    • JCreator
    • jEdit

  11. List some keywords of Java:

    Some keywords of Java are listed below:
    • Abstract
    • Boolean
    • Break
    • byte
    • class
    • switch
    • catch

  12. What are the three steps to create an Object for a Class?

    If you want to create an object for a class then you need to follow these steps:
    • Declare the object
    • Instantiated
    • Initialized

  13. Write the default value of byte datatype in Java?

    0 is the default value of byte datatype in Java programming language.

  14. Write the default value of double and float datatype in Java?

    The default value of float datatype in Java programming language is 0.0f.
    The default value of double datatype in java programming language is 0.0d.

  15. How does Java allow high performance?

    For enabling high performance, time compiler is used by Java which is used for converting the instructions into bytecodes.

  16. What is a class in Java?

    A class is knowns as user defined prototype and blueprint by which objects are formed. It signifies the set of methods or properties that are same for all the objects.

  17. When can we used the parseInt() method?

    We apply parseInt() method For getting the primitive data type of a particular String.

  18. java.util.regex contains of which classes?

    java.util.regex have three classes which are listed below:
    1. Pattern class
    2. Matcher class
    3. PatternSyntaxException class

  19. What is an Exception?

    An issue which occurs at the time of exacting a program is known as Execution. These are caught by supervisors placed with the thread’s technique.

  20. List two subclasses under the Exception class:

    Exception class consists of two major subclasses which are as follow:
    • IOException class
    • RuntimeException Class

  21. What is Singleton class?

    Singleton class regulates the creation of the object, limits the number to 1 but permits the flexibility for creating objects if any condition changes.

  22. Define JDK?

    The full form of JDK is Java Development Kit. JDK is a tool essential to package, document and compile Java programs.

  23. What do you mean by JRI?

    JRI is the short for Java Runtime Environment. It refers to a runtime environment which is responsible for executing Java bytecode.

  24. Explain JVM

    The full form of JVM is stands for Java Virtual Machine. Three notations are followed by JVM: Runtime Instance Specification and Implementation

  25. Write the advantages of Packages.

    The advantages of Packages are listed below:
    • Assist to avoid the name clashes.
    • Deliver simpler access control on the code
    • Have hidden classes which only used in the packages and not observable to outer classes
    • Helps in creating a suitable hierarchical structure.

  26. Write down the types of modifiers supported by Java

    Basically 4 types of access modifiers are supported by java:
    • Default
    • Public
    • Private
    • Protected

  27. How many types of constructors are there in Java?

    There ae two types of constructors:
    • Default Constructor
    • Parameterized Constructor

  28. Define Default Constructor

    Default constructors are also known as the no argument constructors that can be made by default and does not take any participations.

  29. Define Parameterized Constructor

    In java, Parameterized Constructor is the one that takes the argument and they are able to initialize the instance variables with the provided value.

  30. Write some points about Array list

    • Array List is not coordinated.
    • It is fast
    • It does not describe the increment size.
    • Iterator is used by array list to traverse an Array List.

  31. What is vector in Java?

    • Vector is coordinated.
    • Vector is a thread safe so it is slow.
    • It defaults to maximizing the size of its array.
    • Increment size is defined by vector

  32. What is an object in Java?

    An object has 3 characteristics which are listed below:
    • State
    • Behavior
    • Identity

  33. How an object is created in Java?

    We create an object by using the ‘new’ keyword. For instance:
    ClassName obj = new ClassName();

  34. What are the main concepts of OOPs in Java?

    The main concepts of OOPs in Java are:
    • Inheritance
    • Encapsulation
    • Abstraction
    • Polymorphism

  35. What is final keyword in Java?

    Final is a special keyword in Java which is basically act as a non-access modifier. We can use this variable in various contexts which includes:
    • final variable
    • final method
    • final class

  36. What are the ways to achieve Constructor chaining?

    We can achieve Constructor chaining by two ways:
    • From base class using super()
    • Within the same class using this()

  37. What is a classloader in Java?

    A subset of Java Virtual Machine (JVM) which is used to load the class files is known as Java ClassLoader.

  38. How many built-in classloaders provided by Java?

    Three built-in classloaders are provided by java
    • Extension ClassLoader
    • Bootstrap ClassLoader
    • System/Application ClassLoader

  39. Write characteristics of Map interface

    The characteristics of Map interface are:
    • Map doesn’t comprise duplicate keys.
    • Each and every single key can map at maximum one value.

  40. What does Java include in its collection framework?

    • Interfaces
    • Classes
    • Methods

  41. Name the type of classes performed by Inheritance

    • Parent class which is a Super or Base class.
    • Child class which is a Subclass or Derived class.

  42. Define Single Inheritance

    When one class gets the features of another class then this is known as single inheritance.

  43. Define Multilevel Inheritance

    In Multilevel Inheritance, when one class is derived from other class and that other class has also been derived from another class.

  44. What do you mean by Hierarchical Inheritance?

    Hierarchical Inheritance means a class having more than one subclasses (child classes)

  45. What is Hybrid Inheritance?

    A mixture of two or more types of inheritance is known as Hybrid inheritance

  46. How to achieve encapsulation in Java?

    We can achieve encapsulation by two simple ways:
    • Stating the variables of a class as a private.
    • Offering getter methods and public setter for changing and viewing variables values.

  47. What is the life-cycle of a servlet?

    Listed below are the five stages in the servlet lifecycle:
    • Servlet is destroyed
    • Servlet is initialized
    • Servlet is loaded
    • Service the request
    • Servlet is instantiated

  48. Write the common ways of session management in servlets

    • Session Management API
    • Cookies
    • User Authentication
    • URL Rewriting
    • HTML Hidden Field

  49. Write the types of JDBC drivers

    The types of JDBC drivers are:
    • Thin driver (fully java driver)
    • JDBC-ODBC bridge driver
    • Native-API driver (partially java driver)
    • Network Protocol driver (fully java driver)

  50. Write the steps to connect to a database in java?

    The methods for connecting to a database in java are:
    • Creating statement
    • Executing queries
    • Registering the driver class
    • Creating connection
    • Closing connection

  51. What are the types of statements supported by JDBC?

    Three types of statements are supported by JDBC
    • Statement
    • CallableStatement
    • PreparedStatement

  52. Write the different modules of the Spring framework

    The different modules of the spring framework are:
    • Spring DAO
    • Spring JDBC
    • Spring ORM
    • Spring Context
    • Spring Web Module
    • Spring AOP
    • Spring MVC

  53. Mention some of the significant annotations in annotation-based Spring configuration

    • @Autowired
    • @Resource
    • @PreDestroy
    • @Qualifier
    • @Required
    • @PostConstruct

  54. List the 5 types of Scopes defined in Spring beans

    5 Types of Scopes defined in Spring beans are as follows:
    • Singleton:
    • Prototype
    • Request
    • Session
    • Global-session

  55. Write some of the important Spring annotations

    Important Spring annotations are:
    • @Controller
    • @RequestMapping
    • @ResponseBody
    • @PathVariable
    • @Autowired
    • @Qualifier
    • @Service
    • @Scope
    • @Configuration
    • @ComponentScan
    • @Bean

  56. What are the types of transaction management supported by Spring?

    There are 2 types of transaction management which spring support:
    • Programmatic transaction management
    • Declarative transaction management

  57. How can you handle Java exceptions?

    By using these 5 keywords we can handle the Java exceptions
    • catch
    • finally
    • try
    • throws
    • throw

  58. What are the important methods of Java Exception Class?

    The important methods of Java Exception Class are as follows:
    • Synchronized Throwable getCause()
    • String getMessage()
    • void printStackTrace()
    • String getLocalizedMessage()
    • String toString()

  59. How many types of Garbage provided by Java?

    Java provides 4 types of garbage:
    • CMS Garbage Collector
    • Serial Garbage Collector
    • Parallel Garbage Collector
    • G1 Garbage Collector

  60. What are the two ways for creating a thread?

    The two ways to create a thread are:
    • Implement the Runnable interface.
    • Extend the Thread

  61. What is OutOfMemoryError in Java?

    Subclass of java.lang.Error which usually happens when our Java Virtual Machine runs out of memory is known as OutOfMemoryError in Java.

  62. How many types of memory areas are allocated by JVM?

    • Heap
    • Stack
    • Native Method Stack
    • Program Counter Register
    • Class(Method) Area

  63. Can you make a constructor final?

    No, we cannot make a constructor final

  64. What are the ways to copy the values of one object into another in java?

    • By using the constructor
    • Assign the values of one object into the another object
    • By using the clone() method of Object class

  65. How many types of Inheritance are there in Java?

    There are five types of Inheritance in Java:
    • Multiple Inheritance
    • Hybrid Inheritance
    • Single-level inheritance
    • Hierarchical Inheritance
    • Multi-level inheritance

  66. Which class is the superclass for all the classes?

    The superclass for all the classes is the Object class.

  67. Write are the key uses of the super keyword?

    The main uses of the super keyword are:
    • Invoking the immediate parent class method.
    • Invoking immediate parent class constructor.

  68. How can we achieve the method overloading?

    Method overloading can be achieved by two ways:
    • By modifying the number of arguments
    • By modifying the return type

  69. Is it possible to override the private methods?

    No, as it is limited to the class so we can not override the private method.

  70. Does java have virtual functions?

    Yes, all the functions are virtual by default in java

  71. What is Typecasting?

    Typecasting is of two types:
    • Implicit
    • Explicit

The Tech Learn keep sharing basics & advance interview questions and answers of java as per the industry demands so keep visiting us for regular update on java Interview questions.

Reference Link:

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *