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
- 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.
- 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.
- What is JVM?
JVM stands for Java Virtual Machine. JVM is an interpreter which accepts and executes the ‘Bytecode’
- List any five features of Java?
Main features of the Java include Robust, Object Oriented, Multi-threaded, Platform Independent and Interpreted.
- 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.
- 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.
- 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.
- 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.
- 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.
- List any 5 IDE’s of Java?
The 5 Java IDE’s are listed below:
- List some keywords of Java:
Some keywords of Java are listed below:
- 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
- Write the default value of byte datatype in Java?
0 is the default value of byte datatype in Java programming language.
- 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.
- 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.
- 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.
- When can we used the parseInt() method?
We apply parseInt() method For getting the primitive data type of a particular String.
- 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
- 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.
- List two subclasses under the Exception class:
Exception class consists of two major subclasses which are as follow:
• IOException class
• RuntimeException Class
- 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.
- Define JDK?
The full form of JDK is Java Development Kit. JDK is a tool essential to package, document and compile Java programs.
- 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.
- Explain JVM
The full form of JVM is stands for Java Virtual Machine. Three notations are followed by JVM: Runtime Instance Specification and Implementation
- 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.
- Write down the types of modifiers supported by Java
Basically 4 types of access modifiers are supported by java:
- How many types of constructors are there in Java?
There ae two types of constructors:
• Default Constructor
• Parameterized Constructor
- 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.
- 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.
- 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.
- 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
- What is an object in Java?
An object has 3 characteristics which are listed below:
- How an object is created in Java?
We create an object by using the ‘new’ keyword. For instance:
ClassName obj = new ClassName();
- What are the main concepts of OOPs in Java?
The main concepts of OOPs in Java are:
- 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
- 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()
- 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.
- How many built-in classloaders provided by Java?
Three built-in classloaders are provided by java
• Extension ClassLoader
• Bootstrap ClassLoader
• System/Application ClassLoader
- 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.
- What does Java include in its collection framework?
- 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.
- Define Single Inheritance
When one class gets the features of another class then this is known as single inheritance.
- 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.
- What do you mean by Hierarchical Inheritance?
Hierarchical Inheritance means a class having more than one subclasses (child classes)
- What is Hybrid Inheritance?
A mixture of two or more types of inheritance is known as Hybrid inheritance
- 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.
- 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
- Write the common ways of session management in servlets
• Session Management API
• User Authentication
• URL Rewriting
• HTML Hidden Field
- 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)
- 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
- What are the types of statements supported by JDBC?
Three types of statements are supported by JDBC
- 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
- Mention some of the significant annotations in annotation-based Spring configuration
- List the 5 types of Scopes defined in Spring beans
5 Types of Scopes defined in Spring beans are as follows:
- Write some of the important Spring annotations
Important Spring annotations are:
- 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
- How can you handle Java exceptions?
By using these 5 keywords we can handle the Java exceptions
- 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()
- 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
- What are the two ways for creating a thread?
The two ways to create a thread are:
• Implement the Runnable interface.
• Extend the Thread
- 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.
- How many types of memory areas are allocated by JVM?
• Native Method Stack
• Program Counter Register
• Class(Method) Area
- Can you make a constructor final?
No, we cannot make a constructor final
- 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
- 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
- Which class is the superclass for all the classes?
The superclass for all the classes is the Object class.
- 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.
- 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
- Is it possible to override the private methods?
No, as it is limited to the class so we can not override the private method.
- Does java have virtual functions?
Yes, all the functions are virtual by default in java
- What is Typecasting?
Typecasting is of two types:
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.