Top 80+ Java Interview Questions and Answers for Fresher

Top 80+ Java Interview Questions and Answers for Fresher

Top 80+ Java  Interview Questions and Answers for Fresher

Core Java Interview Questions and Answers

 1.) What is Java?

Ans). Java is a high-level, robust, object-oriented, and secure, and stable programming language. Java was developed by James Ghosling, Patrick Naughton, Mike Sheridan at Sun Microsystems Inc. in 1991. To develop the first version it takes 18 months.
The first name of this new language is Oak but in 1995 it's renamed called java.

 The Main Uses of Java Applications are:

• Java is used to develop Mobile applications (mostly Android apps)
• To create Desktop applications
• Web applications
• Web servers and application servers
• Games
• Database connection
• Enterprises systems

2) Writes the features of Java?

Ans. The main features of java are- 

1) Simple
2) Object-Oriented
3) Platform Independent
4) Secure & Portable
5) Multi-Threading
6) High Performance
7) Architectural Neutral

3.) Why Java is called platform-independent language?

Ans- Java programs can run on any OS(operating system) or processor. This bytecode is sent to Java virtual machine (JVM) which resides in the RAM of any operating system. JVM recognizes the platform it is on and converts the bytecodes into native machine code. Hence java is called platform-independent language

4.) Define the platform?

Ans - A platform is the hardware or software environment in which a piece of software is executed. There are two types of platforms, software-based and hardware-based. Java provides a software-based platform.

5.) Why Java is not 100% Object-oriented?

Ans. Java is not 100% Object-oriented because it makes use of eight primitive data types such as boolean, byte, char, int, float, double, long, short which are not objects.

6. ) What Is Object-Oriented Programming?

Ans. Object-oriented programming is a way of organizing programs as a collection of objects, each of which represents an instance of a class.

 The 4 main concepts of Object-Oriented programming are:
a. Abstraction
b. Encapsulation
c. Inheritance
d. Polymorphism

7.) What is an object?

Ans. The Object is the real-time entity having some state and behaviour. In Java, an object is an instance of the class having the instance variables like the state of the object and the methods as the behaviour of the object. The object of a class can be created by using the new keyword.

8.) What is a package in Java? List down various advantages of packages.

Ans. Packages in Java, are the collection of related classes and interfaces which are bundled together. By using packages, developers can easily modularize the code and optimize its reuse. Also, the code within the packages can be imported by other classes and reused.

 Below I have listed down a few of its advantages:
• Packages help in avoiding name clashes
• They provide easier access control on the code
• Packages can also contain hidden classes which are not visible to the outer classes and only used within the package
• Creates a proper hierarchical structure which makes it easier to locate the related classes

9.) What is the JIT compiler in Java?

Ans. JIT stands for Just-In-Time compiler in Java. It is a program that helps in converting the Java bytecode into instructions that are sent directly to the processor. By default, the JIT compiler is enabled in Java and is activated whenever a Java method is invoked. The JIT compiler then compiles the bytecode of the invoked method into native machine code, compiling it “just in time” to execute. Once the method has been compiled, the JVM summons the compiled code of that method directly rather than interpreting it. This is why it is often responsible for the performance optimization of Java applications at the run time.

10.) What is an object in Java and how is it created?

Ans. An object is a real-world entity that has a state and behavior. 

the object has three characteristics:
1. State
2. Behavior
3. Identity
An object is created using the ‘new’ keyword. For example:
ClassName obj = new ClassName();

11.) Define a Java Class?

Ans. A class in Java is a blueprint that includes all your data. A class contains fields (variables) and methods to describe the behaviour of an object.

12). Why is Java both Interpreted and Compiled Language?

Ans. A compiler is a program that converts a program from one level of language to another. Example conversion of the C++ program into machine code. The java compiler converts high-level java code into bytecode (which is also a type of machine code). An interpreter is a program that converts a program at one level to another programming language at the same level. Example conversion of Java program into C++
In Java, the Just In Time Code generator converts the bytecode into the native machine code which is at the same programming levels. Hence, Java is both compiled as well as an interpreted language.

13). Explain JDK, JRE, and JVM?

Ans. JDK – Java Development Kit (in short JDK) is Kit which provides the environment to develop and execute(run) the Java program. JDK is a kit(or package) which includes two things
1. Development Tools(to provide an environment to develop your java programs)
2. JRE (to execute your java program).

Note: JDK is only used by Java Developers

JRE – Java Runtime Environment is an installation package that provides the environment to only run(not develop) the java program(or application)onto your machine. JRE is only used by them who only want to run the Java Programs i.e. end-users of your system.

JVM-Java Virtual Machine(JVM) is a virtual machine that provides a runtime environment to execute java byte code. The JVM doesn't understand Java typo, that's why you compile your *.java files to obtain *.class files that contain the bytecodes understandable by the JVM. JVM control the execution of every Java program. It enables features such as automated exception handling, Garbage-collected heap.

14.) What is a classloader in Java?

Ans. The Java ClassLoader is a subset of JVM (Java Virtual Machine) that is responsible for loading the class files. Whenever a Java program is executed it is first loaded by the classloader. 

Java provides three built-in classloaders:

1. Bootstrap ClassLoader
2. Extension ClassLoader
3. System/Application ClassLoader

15.) Explain Byte Code Verifier?

Ans. The JVM puts the code through the Byte Code Verifier that checks the format and checks for an illegal code. Illegal code, for example, is code that violates access rights on objects or violates the implementation of pointers.

16.) What are wrapper classes in Java?

Ans. Wrapper classes convert the Java primitives into the reference types (objects). Every primitive data type has a class dedicated to it. These are known as wrapper classes because they “wrap” the primitive data type into an object of that class. Refer to the below image which displays the different primitive types, wrapper class, and constructor argument.

17.) What are access modifiers in Java?

Ans. In Java, access modifiers are special keywords that are used to restrict the access of a class, constructor, data member, and method in another class.

 Java supports four types of access modifiers:
1. Default
2. Private
3. Protected
4. Public

18.) What is Java Type Casting?

Ans. Casting is a process of changing one type of value to another type. In Java, we can cast one type of value to another type. It is known as typecasting.

In Java, there are two types of casting:
• Widening Casting (automatically) or Implicit - converting a smaller type to a larger type size byte -> short -> char -> int -> long -> float -> double

• Narrowing Casting (manually) or Explicitly - converting a larger type to a smaller size type double -> float -> long -> int -> char -> short -> byte

19.) Define Java Array and Features of Array?4

Ans. An array is a collection of similar data types. An array is a container object that holds values of a homogeneous type. It is also known as a static data structure because the size of an array must be specified at the time of its declaration. Array starts from zero index and goes to n-1 where n is the length of the array. Array can be single dimensional or multidimensional in Java.

Features of Array
• It is always indexed. Index begins from 0.
• It is a collection of similar data types.
• It occupies a contiguous memory location.
• It allows accessing elements randomly.

20.) Define a Jagged Array?

Ans. A jagged array is an array that has different numbers of columns elements. In java, a jagged array means to have a multi-dimensional array with an uneven size of columns in it.

OOPS Interview Questions and Answers

21) Define Object-Oriented Programming and also write the benefits of Object-Oriented Programming?

Ans. Object-Oriented Programming is a concept which is based on "object".This Object contains data and methods. The main purpose of object-Oriented Programming is to improve flexibility and reduce the code.

Benefits of Object-Oriented Programming:-

1. The main uses of Object-Oriented concept is to increase the productivity for software development.
2. Improved software maintainability
3.With the help of OOPS, we can create Low cost of software development
4. Object-oriented programming helps we can create good quality-wise. software
5. Code can be reused through inheritance thereby reducing redundancy
6. OOPs provide the function like data hiding, that reason private data is kept confidential.

22) Write the limitations of OOPs?

Ans. It takes longer to solve the problem. Proper planning is required. Programmers should think about solving a problem in the context of objects that are generally not suitable for small problems.

23) Write the difference between Procedural Programming and Object-Oriented Programming?

Ans.The main difference between Procedural Programming and Object-Oriented Programming are-


Procedural Programming

Object-Oriented Programming


In procedural programming, the program is divided into small parts called functions.

In object-oriented programming, the program is divided into small parts called objects


procedural programming follows top-down approach

object-oriented programming follows a bottom-up approach.


In procedural programming there is no access specifier.

Object-oriented programming has different types of access specifier like public, private, protected, etc.


In Procedural programming adding new data and functions is not easy.

In Object-oriented programming adding new data and functions is easy.


Procedural programming is less secure because it's does not have any proper way of data hiding

Object-oriented programming is more secure because it provides data hiding


Overloading is not possible in Procedural programming.

Overloading is possible in object-oriented programming.


The function is more important than data in the procedural programming language.

The data is more important than function in an object-oriented programming language.


The working principle of Procedural programming is based on the unreal world.

The working principle of Procedural programming is based on the real world.


Examples: FORTRAN, Pascal, C, FORTRAN etc.

Examples: C++, Java, C#, Python, etc


24) Write the OOPs concepts in Java and also write the Pillars of Object-Oriented Programming?

Ans. OOps, Concept in Java are-
a) Object
b) Class 
c) Polymorphism 
d) Inheritance
e) Encapsulation
f) Message Passing
g) Abstraction 
h) Method 

Pillars of Oops:
The main 4 Pillars of oops are-
1) Inheritance
2) Encapsulation
3) Polymorphism
4) Abstraction.


25) Write the difference between a class and an object?

Ans. The main difference between class and an object is-





class is a blueprint from which object is created

an object is the instance of a class.


Class is declared with the help of class keyword e.g. class Student{}

object is created using a new keyword e.g. Student s1=new Student();


A class is a logical entity.

An object is a physical entity


A class does not take memory space when created.

Objects take memory space when they are created

Some real-life examples of class and object in java

if Class: Mobile phone        Object: iPhone, Samsung, Moto
Class: Fruit                       Object: Apple, Banana, Mango, Guava


26)Define inheritance in Java?

Ans. The process by which one class acquires the properties and functionalities of another class is called inheritance. In simple words, one class drive from another class called inheritance.
The main uses of inheritance in programming are code reusability.

27) What are the different types of inheritance in java?

Ans. There are mainly 4 types of inheritance in java are-
1)Single inheritance
2) Multilevel inheritance 
3) Hierarchical Inheritance
4) Hybrid Inheritance 

28) Why Java doesn't support multiple inheritances?

Ans.Java doesn’t allow multiple inheritance to avoid the ambiguity caused( confusion ) by it. If we use multiple inheritance in java it raises the diamond shape problem, to prevent such type of problem java doesn't support multiple inheritance.

29) Define constructor and also writes the different types of constructors?

Ans. A constructor is a special type of method that has the same name as the class and is used to initialize objects of that class.

Types of Constructors:

 There are mainly 5 types of Constructors they are-
1) Parameterized constructor
2) Default, constructor 
3) Copy constructor 
4) Static constructor
5) Private constructor 

30) Define a destructor?

Ans. A destructor is a special method that is automatically invoked when an object is destroyed.

31) Define polymorphism?

Ans. Polymorphism in Java is a concept by which we can perform a single action in different ways. Polymorphism has come from 2 greek words: poly and morphs. The word "poly" means many and "morphs" means forms. So polymorphism means many forms. In simple words "The word polymorphism means having many forms". 

Example:- Real-life example of polymorphism: 
A person at the same time can have different characteristic. As women at the same time is a mother, a wife, an employee. So the same person posses different behaviour in different situations. This is called polymorphism.

32) What are the different types of polymorphism?

Ans. There are mainly 2 types of polymorphism they are-
a) Static Polymorphism is also known as compile-time Polymorphism
b) Dynamic Polymorphism is also known as Runtime Polymorphism 

33) Define Compile time Polymorphism and Runtime Polymorphism in java?

Ans. Compile-time Polymorphism:- Polymorphism which is resolved during compiler time is known as static polymorphism or Compile time polymorphism. Method overloading is an example of compile-time polymorphism.

Runtime Polymorphism:- Runtime polymorphism is a process in which a call to an overridden method is resolved at runtime, that's why it is called runtime polymorphism. An example of runtime polymorphism is method overriding. 

34) Write the difference between Method overloading and Method overridden in Java?

Ans. The main difference between Method overloading and Method overridden are-


Method overloading

Method overridden


Two or more methods having the same name but different parameters or signature is called method overloading.

Child class redefining methods present in the base class with the same parameters/ signature called method overriding


Method overloading is Resolved during compile-time

Method overridden Resolved during runtime


Method overloading gives better performance

Method overridden Performance-wise Overriden is not good


Method overloading is the example of compile-time polymorphism.

Method overriding is the example of run time polymorphism.

35) Define Encapsulation in java?

Ans. The process of binding the data and property into a single unit is called encapsulation. Encapsulation helps us can achieve data hiding and prevent the data from outside. The encapsulate class is easy to test, so it is also better for unit testing.

36) Write the advantages of Encapsulation in java?

Ans. The main advantages of Encapsulation are-
1) Encapsulation provide better control of class attributes and methods.
2) Encapsulation provide flexibility for a programmer it means the programmer can change one part of the code without affecting other parts.
3) Encapsulation helps data hiding achieve so, it's improved security of data.

37) Define Abstraction in java?

Ans. Abstraction is a process where shows only “relevant” data and “hide” unnecessary details of an object from the user. The main purpose of abstraction is to hide the unnecessary details from the users.

38) Write some real-time example of Abstraction?

Ans.First Example: The ATM machine as a real-time example. We all use an ATM machine for cash withdrawal, money transfer, retrieve min-statement, etc in our daily life. But we don’t know internally what things are happening inside the ATM machine when you insert an ATM card for performing any kind of operation.

Second Example: When you need to send SMS from your mobile, you only type the text and send the message. But you don’t know the internal processing about the message delivery.

39) How to achieve Abstraction in Java?

Ans. There are 2 ways which help we can achieve Abstraction in java-
a. Abstract class (0 to 100%) 
b. Interface (100%) 

40) Define Abstract Class in Java?

Ans. A class that is declared using an “abstract” keyword is known as abstract class. It can have abstract methods(methods without body) as well as concrete methods (regular methods with the body). 
" An abstract class can not be instantiated, which means you are not allowed to create an object of it."

41) Define Abstract Methods in Java?

Ans. A method without a body is known as an Abstract Method. It must be declared in an abstract class. The abstract method will never be final because the abstract class must implement all the abstract methods. 

42) Write the advantage of Abstract class in Java?

Ans. The main advantages of the Abstract class are- 1. The abstract class makes programming better and more flexible by giving the scope of implementing abstract methods. 2. The programmer can implement an abstract method to perform different tasks depending on the need. 3. With the help of abstract class we can easily manage code.

43) Write the difference between Abstraction and Encapsulation?

Ans. The main difference between Abstraction and Encapsulation are-





Abstraction solves the issues at the design level.

Encapsulation solves its implementation level.


Abstraction is about hiding unwanted details while showing the most essential information.

Encapsulation means binding the code and data into a single unit.


Abstraction allows focussing on what the information object must contain 

Encapsulation means hiding the internal details or mechanics of how an object does something for security reasons

 Exception Handling  Interview Questions and Answers

44) Define Exception in java?

Ans. An exception is an abnormal event of a program that disturbs the normal flow of the program and the program gets terminated.
In simple words"An unexpected behavior of an object that stops the normal the flow of program called Exception".


45) Define Exception Handling?

Ans. Exception handling is the process where we have to handle Exception during the runtime period which helps continue the normal flow of the program. Exception handling ensures the smooth execution of the program.


46) Write the Real-time example of Exception handling?

Ans. The Real-time example of Exception handling is-

    1)If we are traveling from Bangalore to Pune by car, after traveling mid-distance tire of the car is punctured this is called exception (an unwanted event which stops the Journey), but we keep Stepney(extra tire) which help our journey continues. The Stepney(extra tire) which helps our journey continues and completed called exception handling.

    2)If we are watching a movie on a mobile phone but suddenly the network problem occurs which helps we can't continue the movie(Exception), but we have dual sim phone so, the 2nd sim helps us continue the movie this is called exception handling.


47) Write the difference between Exception and Error?

Ans. The difference between Exception and Error are-






Exception are raised by programmer in a maximum of the time.

Error is generated if we don’t have proper system requirement such as memory leak, sufficient memory not available for application.


We can handle the exception, which means the exception is recoverable.

If can’t handle the error, that means the error is recoverable.


An Exception can be checked as well as unchecked type.

Error in unchecked type.


48) Write the types of exceptions in java?

Ans. There are 2 types of exception in java they are-
a)Checked exceptions
b)Unchecked exceptions.


49) Define Checked and Unchecked exceptions?

Ans. Checked exception: The exception which is checked by the compiler for the normal flow of the program is called a checked exception.

Example:  IOException, ClassNotFoundException, etc are checked exception.

Unchecked exception: The exception which occurs during runtime and this exception not checked by the compiler is called an Unchecked exception.

Example: ArrayIndexOutOfBoundsException ,Arithmetic Exception etc.


50) Write the all keyword names for which is used for Exception handling?

Ans. There are 5 keywords which help we can handle the exception they are-


51) Define a try-catch block in exception?

 Ans.Try-Catch: Try is a block where we can find exceptions. Try is a block that is always associated with a catch block or finally blocks.

 The catch block is used to control or handle the exception. We must use the catch block after the try block.

 try{ int x=50;    
int y=0;     
int z=x/y; //Exception occurs 
} catch(ArithmeticException e) 


52) Define throw keyword in Exception?

Ans. The throw keyword in java is used to throw an unwanted event (exception) explicitly. In custom exception, checked or unchecked exception we can use throw keyword for handling exception.


53) Write the distinction between throw and throws keyword?

Ans. The main difference between throw and throws are-





1) The main use of the throw keyword is  to throw an unwanted event (exception)   explicitly.


If we want to declare an exception during execution time so use the throws keyword.

2)throw the keyword can  throw only one exception at a time.


In throws keyword  we can declare multiple exception with the help of separated by a comma.

3)Inside the method body throw keyword is declared.

Throws keyword in java  is used with method s method declaration or signature.

4)In throw keyword syntax include the instance of the exception to be thrown

In throws keyword syntax includes the class names of the exception to be thrown.


54) What is the superclass or parent class of all exception types in java?

Ans. Throwable class is a superclass of all exception types in java.


55) Write the difference between Final, Finally, and Finalize?


difference between Final, Finally, and Finalize

56) How we can handle the exception?

Ans. There are 2 main ways which help we can handle the exception.
a) With the help of a try-catch block.
b) With the help of throws keyword.

57) How we handle the user define exception?

  Ans. Using Throws keywords helps us handle the user-defined exception. 

58) Define Arithmetic exception in java?

    Ans. Whenever an integer is divided by zero we get an exception this type of exception is called an Arithmetic exception.


                                             Multithreading Interview Questions and Answers

 59) Define thread in java?

Ans. A lightweight process is called a thread. The thread is a specific independent path of execution. Thread is commonly known as the user define the task.

60) How we can create a thread in java?

Ans. There are 2ways that helps we can create a thread in java they are-
a)By implementing the Runnable interface.
b)By extending the Thread class.


61) Define Multithreading in java?

Ans. Multithreading is the process where we have to execute more than one thread at a time. In multithreading, each and every thread is a separate individual process of the same application. Multithreading is useful in Animation, gaming applications like the NFS game.

62) Explain Multitasking and also write types of Multitasking?

Ans. Executing more than one task simultaneously(at the same time) is called multitasking.
There are mainly 2 types of Multitasking they are-
a)Process-based multitasking
b)Thread based multitasking.


63) Write the difference between Process and Thread?

Ans. The main difference between Process and Thread are-


64) Write the advantage of Multithreading?

Ans. The main advantages of Multithreading are maximum utilization of CPU that helps reduce the total response time and improve the performance. Multithreading helps we can perform multiple operations at the same time and save time.

65) Write the name of the Thread life cycle stage in java?

  Ans. There are 5 stages of the Thread life cycle they are-


66) Explain the Daemon thread?

Ans. A thread that is executing in the background and created by JVM is called a Daemon thread. isDaemon() method helps us check the thread is Daemon or not. The main uses of the Daemon thread are to provide the support for non-daemon threads. In Java Daemon is a low priority thread that is running automatically. Example: Garbage Collector.

67) Define  Synchronization in java?

Ans. Synchronization is a technique that provides control of the access of multiple threads to any shared resource. The main purpose of Synchronization is to prevent inconsistencies in the results and prevent thread interference. 

68) Writes the types of Synchronization?

Ans. There are mainly 2 types of Synchronization they are-
1) Process Synchronization
2) Thread Synchronization.

69) Define Deadlock in java?

Ans. A state where two threads or more than two threads are waiting for each other to release locks is called Deadlock condition.

70) It is possible to synchronize the constructor?

Ans.No, it's not possible to synchronize the constructor.

71) Which method helps thread can communicate with each other?

Ans. By using wait(), notify(), notifyAll() methods help thread can communicate with each other.

72) It is possible to make a user thread to the Daemon thread if yes so write the syntax.?

Ans. Yes, it is possible to make user thread to Daemon thread. By calling setDaemon() method helps we can make a user thread to the daemon thread.

73) It is possible to create a thread twice in java?

Ans. No, it's not possible to create a thread twice in java.


Collections Interview Questions and Answers

 74) Explain Collection in java?

Ans. A group of individual objects which represented as a single unit called Collection. In other words, an object that collects different elements into a single unit known as Collection. The collection helps we can store data and manipulate data. Java Collection involves classes and interfaces that help it perform insertion, deletion, manipulation, searching and sorting operation.


75) Write the advantages of the Collection Framework?

Ans. Advantages of Collection Framework:
A)Java Collection framework provides a Consistent API.
B)Collection Framework provides powerful data structures and algorithms which help it reduce the programming effort. 
C)It increase the program speed and improve performance and also increase Productivity.


76) Write the name of Key Interfaces of the Java Collection framework?

Ans. There are 9 Key Interfaces of the java Collection framework they are-
A) Collection
B) List 
C) Set 
D) SortedSet
E) NavigableSet 
F) Queue 
G) Map 
H) SortedMap 
I) NavigableMap.


77) Define Generic collections in java?

Ans. A collection which is allows the datatype to pass as parameters to the class known as Generic Collection. Generic Collection introduced by Java 5 so it provides some new features like:
1) It provides strong compile-time type checking
2) It is a type-safe and explicit casting of objects.

In the collection,
 ClassCastException is a very common exception, so Generic collection overcome the risk of  ClassCastException this is the greatest advantage of Generic Collection in java.


78) Write the difference between Arrays and Collection?

Ans. The difference between Arrays and Collection are-






 Arrays can hold only similar type        (homogeneous ) types of data.

 Collection can hold both similar types and different types of data.


 In Arrays  Size is fixed it means if we created an array we can’t change the size of the array.

 Collection size is not fixed it means size is growable, we can increase or decrease the size of the collection.


Performance point of view Array is good because it is faster than the collection.

 The performance point of view collection is not good because it is slower than an Array.


 Memory purpose array does not suggest because array consumes more memory.

The collection is suggested for memory purposes because collection consumes less memory.


79) Write the difference between Collection and Collections in java?

Ans. The main difference between Collection and Collections are-





The collection is an interface.

Collections are utility class.


If we want to represent an individual object as a single entity then we use  Collection.

Collections are defined as various utility methods for collections objects.such as Searching. Sorting etc.


80) Write the difference between ArrayList and Vector?

Ans. The main difference between ArrayList and Vector are-





ArrayList Introduced in JDK1.2, so it is not a legacy class.

Vector is introduced with old version  1.0  so it is a legacy class.


Every method present in ArrayList is not synchronized.

Most of the Method present in Vector is synchronized


Array List is not thread-safe.

Vector is by default thread-safe. 


Performance point of view ArrayList Works fast.

Performance point of view Vector Works slow.


In an array list increment size is not defined.

In Vector increment size is defined.


81) Write the difference between Array and ArrayList?

Ans. The main difference between Array and ArrayList are-





The size of the Array is fixed it, means we can not change the size.

The size of the ArrayList is not fixed it means we can change the size.


An Array store both primitives and Objects in Java.

Array List can store the only objects.


An array is a static type.

Array List is a dynamic type.


Array is not supported indexOf() ,remove() method.

Array List is supported indexOf(),remove() method.


82) Write the difference between List and Set?

Ans. The main difference between List and Set are-





In java Collection Framework an ordered collection of elements is called a List.

In java collection Framework an unordered collection of elements is called Set


In List duplicate values are allowed.

In Set duplicates values are not allowed.


83) Write the difference between List and Map?

Ans. The difference between List and Map are-





List is the Collection of the element which comes from java. util package.

Collection of key-value pairs is called Maps which is come from java. util package.


If we want to store multiple null values so we use List.

If we want to store only one null key so we use Map but multiple null values are also allowed in Map.


84) Write the name of the class which is available in Set?

Ans. The classes which are available in the set are-
     a) HashSet
     b) LinkedHashSet 
     c) TreeSet.


85) Write the name of the class which is available List?

Ans. The classes which are available in the List are-
   a) ArrayList
   b) LinkedList
   c) Vector
   d) Stack


86) Write the difference between Hashtable and HashMap?

Ans. The main difference between Hashtable and HashMap are-





HashTable is synchronized.

HashMap is not synchronized.  


Hash Table is a thread-safe.

HashMap is not thread-safe.


HashTable comes with an older version of java so it is a legacy class in java.

HashMap is introduced with jdk1.2 so it is not a legacy class.


Performance point of view HashTable is slow.

Performance point of view HashMap is faster than HashTable.


87) Define treemap in the collection?

Ans. To customize the sorting of the value we use TreeMap.  TreeMap's working principle is based on a red-black tree data structure.   To create a Treemap, we need to create an object of the TreeMap class.  The main uses of  TreeMap is always maintaining the sorting order.  


88) Explain List interface in java?

Ans. An ordered collection of elements is known as the List interface. List interface maintains the insertion order and also stores the duplicates values. It has come from java. util package.

The main purpose of this blog is to give knowledge about 'Top 80+ Java  Interview Questions and Answers for Fresher''.If you like the article share the feedback, and also, write comments if you find anything incorrect.


Best Non-Coding  IT  Jobs for Fresher 

Top 10 Foreign language to learn for job 

Best Abroad Country for IT jobSeeker

Post a Comment