Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

501.

What is servlet? Explain

Answer»

This is a Java programming class that runs on Java-enabled SERVER or application server and EXTENDS the capabilities of servers that host applications.

A servlet POSSESSES all the features of Java such as PLATFORM independence, portability, security and database connectivity.

502.

Explain the difference between abstract classes and interfaces in Java?

Answer»
 InterfaceABSTRACT class
1.Can only have abstract methodsCan have abstract, non-abstract methods
2.Variables are by DEFAULT final.May CONTAIN non-final variables.
3.Only has STATIC and final variablesCan have non-final, final, non-static and static variables
503.

What is the differences between Heap and Stack Memory in Java? Explain

Answer»
 HEAP spaceStack Memory
1.Used to allocate memoryUsed for EXECUTION of the thread
2.Instance variables are createdLOCAL variables are created
3.Contains Objects and REFERENCE variablesContains methods and local variables
504.

Why Java is a platform independent? Explain

Answer»

By being platform independent, we mean that the java source code can be run on all OS. The PRESENCE of a machine independent code CALLED Byte Code, which once compiled, can be run on any platform, makes Java platform independent.

The compiler feature in Java CONVERTS or translates the high-level language into a common format understood by all the machines. The only REQUIREMENT is the AVAILABILITY of JVM.

505.

What is Collections in Java?

Answer»

A Collection in Java is a group of individual OBJECTS that are REPRESENTED as a single unit. The Collection Framework in Java defines CLASSES and interfaces that represent a group of objects as a single unit.

The TWO MAIN root interfaces are Collection interface and Map interface.

506.

What is the difference between HashSet and TreeSet in Java?

Answer»
 HashSetTreeSet
1.Offers constant time costOffers log time cost
2.Does not MAINTAIN the order of elementsBy default SORTS elements in ascending order.
3.Implemented USING a hash tableImplemented using BINARY Search Tree
507.

What is the difference between HashMap and HashTable in Java?

Answer»
 HashmapHashtable
1.NonsynchronizedSynchronized
2.Not thread safeThread-safe
3.Cannot be shared between THREADS WITHOUT SYNCHRONIZATION codeCan be shared with many threads
4.Allows null key and multiple null valuesDoes not ALLOW null key or value
508.

What is Abstract class? Explain

Answer»

It is a class that is declared with an ABSTRACT keyword. An abstract class can have both abstract and non-abstract METHODS and needs to be EXTENDED. In this class, the METHOD must be implemented and cannot be instantiated.

509.

What is Interface in Java? Explain

Answer»

Similar to CLASS, an interface in Java is a reference type. An interface contains ABSTRACT methods, CONSTANTS, STATIC methods, default methods and nested types.

A class implements an interface and INHERITS the abstract methods of the same interface. Writing an interface is like writing a class.

510.

What is Method Overloading?

Answer»

Method Overloading allows a class to have more than one methods of having the same NAME, but only if the argument LISTS are VARYING. This feature is similar to CONSTRUCTOR overloading feature that allows more than one constructor to a class only if their argument lists are DIFFERENT.

511.

What is Polymorphism in Java?

Answer»

It is one of the features of OBJECT-oriented programming that allows the developers to perform one action in different WAYS. Developers OFTEN USE POLYMORPHISM in referencing a parent class to a child class object.

512.

Explain the Inheritance?

Answer»

It is the process when one class acquires the properties or methods or fields of another class. This process is used to arrange and MANAGE INFORMATION in hierarchical ORDER. The class that inherits the properties is called SUBCLASS. The class whose properties get INHERITED is called superclass.

513.

What is "this" keyword in java? Explain

Answer»

It is a reference VARIABLE that REFERS to the CURRENT OBJECT. It can be used as follows:

  • To refer instance variable of class
  • To invoke class constructor
  • Passed as an argument in METHOD call
  • Passed as an argument in the constructor call
  • Used to return a class instance
514.

What is the constructor and how many types of constructors are used in Java?

Answer»

The constructor is a method USED to initialize an object. A normal java method has return type but the constructor does not have any explicit return type. It is called during the object creation time.

There is two type of Constructors - DEFAULT or no-arg Constructor, Parameterized Constructor.

515.

What is an Class?

Answer»

It is a PROTOTYPE or user-defined BLUEPRINT that is used to create objects or data types. A CLASS represents PROPERTIES or methods that are common to objects of ONE type. All class objects possess the class properties.

516.

What do you mean by Local variable and Instance variable?

Answer»
 Local VariablesInstance Variables
1.Declared in constructor, METHOD or block.Declared in a class
2.Not possible to USE access modifiersAccess modifiers can be given
3.Visible WITHIN the declared methodVisible for all methods
4.No default valueHave default VALUES
517.

What are the Java IDE's? Explain

Answer»
518.

Explain the difference between an object-oriented programming language and object-based programming language?

Answer»
 Object-Based LanguagesObject-Oriented Languages
1.Does not support INHERITANCE or POLYMORPHISM.Supports polymorphism and inheritance
2.Does not support built-in objects.Support built-in objects.
3.Examples - JAVASCRIPT and VBExamples - C# and Java
519.

Explain the advantages of Packages in Java?

Answer»

Following are the advantages:

  • Allow you to define packages for BUNDLING a group of CLASSES or interfaces.
  • No name conflicts with other package names.
  • Packages MAKE access CONTROL easier
  • Packages make access control easier
520.

What do you mean by classloader?

Answer»

CLASS LOADERS are responsible for dynamically loading the classes during the runtime to the JVM. They are a part of the JRE.

Three types of Class Loaders are built-in - BOOTSTRAP, Extensions and SYSTEM.

521.

Explain the difference between JDK, JRE, and JVM?

Answer»
 Java Development Kit (JDK)JVMJRE
1.Core component of Java EnvironmentConverts Byte code to machine-specific codeImplementation of JVM.
2.Provides TOOLS and executables required for a Java ProgramPlatform dependentProvides a platform for executing Java programs.
3.It is platform specificProvides core FUNCTIONS LIKE garbage collection, MEMORY management and security etc.Consists of java binaries and classes.
522.

What is Java virtual machine? Explain

Answer»

It is a virtual machine that ENABLES computers to run JAVA programs in addition to programs written in other languages but are compiled to Java bytecode. OpenJDK project has developed the Java virtual machine (JVM) REFERENCE as open source code. The reference includes a JIT compiler which is KNOWN as HotSpot.

523.

Who developed Java?

Answer»

JAVA Programming language was created by James GOSLING at SUN micro systems in 1991.

524.

What is the differences between C++ and Java? Explain

Answer»
 C++Java
1.Follows WOCA approach (Write once, compile anywhere).Follows WORA approach (Write once, run anywhere).
2.Runs as code on native machine.Runs on VIRTUAL machines.
3.Multiple binary compatibility standards are included.Has single binary compatibility standard.
4.All types of POINTERS and pass-by-value are supported.Primitive and reference types are only passed by value.
525.

What is Java and why do we need it? Explain

Answer»

Java is a computing PLATFORM as well as a programming language. An object-oriented language, Java is a fast, secure and easily extendible language. Java is a platform independent and Architecture-neutral language.

It is used to create COMPLETE & POWERFUL applications that may run on a single computer or be distributed among clients and servers in a network. I ALSO can be used on the intranet applications.

526.

What is the base class of all exception classes in Java?

Answer»

Java.lang.Throwable

527.

What is anonymous class in Java?

Answer»

An anonymous class is like a LOCAL class or an inner class, but WITHOUT a name. You can USE an anonymous class for declaring and INSTANTIATING a class simultaneously.

528.

Explain different states of a thread in Java?

Answer»

In Java, there are various STATES of a THREAD. But at any POINT of time, it can exist in any ONE of these states:

  • New
  • Runnable
  • Blocked
  • Waiting
  • Timed Waiting
  • Terminated
529.

What is the difference between Stack and Queue?

Answer»
 StackQueue
1.Objects accessed on Last In First Out (LIFO).Objects accessed on First In First Out (FIFO)
2.Object PUSHED on TOP of collectionObject INSERTED at the end
3.Object REMOVED from the topObject removed from the beginning.
4.Two operations are called push and popTwo operations are called enqueue and dequeue
530.

How we can make copy of a java object?

Answer»

For copying an OBJECT in Java, there are TWO WAYS- shallow COPY and deep copy.

 Shallow CopyDeep Copy
1.When you want to copy only field valuesAll the objects are deeply copied
2.Copy is dependant on ORIGINAL objectCopy is not dependent on earlier objects
531.

How we can skip Finally block of exception even if some exception occurs in the exception block in Java?

Answer»

System.exit(0);

532.

What is Network Programming in java?

Answer»

It refers to writing programs or applications that RUN across multiple devices when the devices are connected on a network.

The java.net package CONTAINS a collection of INTERFACES and classes that communicate and allow programmers to write programs that FOCUS on solving the current PROBLEM.

533.

What is Socket in Java?

Answer»

It is one endpoint of two-way COMMUNICATION between programs that are running on the same network.

A SOCKET is tied to a port number in such a manner that the TCP layer can recognize the application where the data needs to be SENT. If you USE Socket instead of native CODE, your programs will communicate platform-independently.

534.

What is the difference between the ">>" and " >>>" operators in Java?

Answer»
535.

What is the difference between Array and Array List in Java?

Answer»
 ArrayArrayList
1.Basic functionalityPart of collection framework.
2.Fixed sizedDynamic sized
3.Contain PRIMITIVE DATA types as well as objects of a classOnly SUPPORTS object ENTRIES
536.

How we can generate random numbers in Java?

Answer»

In Java, there are three ways to GENERATE random NUMBERS:

  • java.util.Random CLASS
  • Math.random method
  • ThreadLocalRandom class
Example

This is DONE USING java.util.Random class:
import java.util.Random;
Random rand = new Random();
int n = rand.nextInt(100) + 1; //100 is the maximum and the 1 is our minimum.

537.

Explain the features of Java?

Answer»
  • Simple and EASY to learn
  • Platform Independent
  • Supports is OBJECT ORIENTED PROGRAMMING language
  • Robust and multithreaded
  • Enables high performance
  • Java Interpreted
  • Secure and its interpreter
  • Follows WORA (write once, run anywhere) approach