0% found this document useful (0 votes)
8 views11 pages

Java Exception Handling and Concepts

The document provides definitions and explanations of various Java concepts including exception handling, multithreading, synchronization, wrapper and object classes, serialization, singleton classes, collections, and more. It also outlines the features that make Java secure, the use of cursors, and includes frequently asked interview questions categorized by experience level. Key topics include data structures like lists, sets, and queues, as well as programming principles such as polymorphism and dependency injection.

Uploaded by

Rajeswari R
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views11 pages

Java Exception Handling and Concepts

The document provides definitions and explanations of various Java concepts including exception handling, multithreading, synchronization, wrapper and object classes, serialization, singleton classes, collections, and more. It also outlines the features that make Java secure, the use of cursors, and includes frequently asked interview questions categorized by experience level. Key topics include data structures like lists, sets, and queues, as well as programming principles such as polymorphism and dependency injection.

Uploaded by

Rajeswari R
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Define exceptional handling in java ?

Exception handling is a programming technique used to manage and respond to runtime


errors or unusual conditions that occur during the execution of a program. Instead of letting
the program crash when an error occurs, exception handling provides a way to detect the
error, handle it gracefully, and continue or safely terminate the program.

Define Multithreading in Java ?

Multithreading is a programming concept where multiple threads run concurrently within a


single process. Each thread is a lightweight, independent unit of execution that shares the
same memory space. It helps improve the performance of programs by enabling parallel
execution of tasks, such as performing calculations while reading input or updating a user
interface.

Define Synchronization in Java ?

Synchronization in Java is a technique that ensures only one thread can access a shared
resource at a time, preventing data inconsistency in a multithreaded environment. It helps
maintain thread safety when multiple threads are reading and writing shared variables or
objects.

Define wrapper and object class in java ?

Wrapper Class in Java:

Wrapper classes in Java are used to convert primitive data types (like int, char, double, etc.)
into objects. This is essential for using primitives with Java's Collection Framework which
works with objects. Examples include Integer, Character, Double, etc.

Object Class in Java:


The Object class is the superclass of all classes in Java. Every class in Java implicitly inherits
from the Object class. It contains important methods like toString(), equals(), hashCode(),
and clone() which can be overridden for custom behavior.

✅ Comparable and Comparator in Java

os

Define Inner class in java ?

In Java, an inner class is a class that is defined within another class. It has access to the
members (including private members) of the outer class. Inner classes are mainly used to
logically group classes that are only used in one place, and to increase encapsulation.

Define Serialization and Deserialization in Java ?

Serialization in Java:

Serialization is the process of converting a Java object into a byte stream so that it can be
saved to a file or sent over a network. It helps in persisting the state of an object.

Deserialization in Java:

Deserialization is the reverse process of serialization. It converts a byte stream back into a
Java object, allowing the program to reconstruct the original object.

To perform serialization, a class must implement the Serializable interface.

Define Singleton Class in Java ?

A Singleton class in Java is a design pattern that ensures only one instance of the class exists
throughout the application lifecycle and provides a global point of access to that instance.

🧠 Why Use Singleton?

Control access to shared resources (e.g., database, logger, config).


Save memory and ensure consistency.

Useful in multithreaded or enterprise applications.

Define Collections in Java

Collections in Java are frameworks that provide an architecture to store and manipulate a
group of objects. They include interfaces (like List, Set, and Map), classes (like ArrayList,
HashSet, HashMap), and algorithms that help in data manipulation such as sorting and
searching. The Java Collections Framework (JCF) helps in managing data efficiently and
provides reusable data structures.

Define Collection Class in Java ?

In Java, the Collection class is a part of the Java Collection Framework and is used to
manipulate groups of objects. It provides static utility methods for operations such as
searching, sorting, reversing, and synchronizing collections like List, Set, and Map. The
[Link] class is commonly used to perform these operations efficiently, making it
easier to manage and process data structures in Java applications.

Define List in Java ?

In Java, a List is an ordered collection that allows duplicate elements. It is a part of the
[Link] package and is an interface that extends the Collection interface. Elements in a List
can be accessed using index positions, and the insertion order is preserved. Common
implementations of List include ArrayList, LinkedList, and Vector.

Define QUEUE INTERFACE in Java ?

Queue Interface in Java is a part of the Java Collections Framework that follows the First-In-
First-Out (FIFO) principle. It is used to hold elements prior to processing and is commonly
implemented by classes like LinkedList, PriorityQueue, and ArrayDeque. Key methods
include add(), remove(), and peek() for inserting, deleting, and accessing elements.

Define LINKED HASHSET & TREE SET in Java ?

🧩 LinkedHashSet in Java

LinkedHashSet is a class in Java that implements the Set interface and preserves the
insertion order of elements.

✅ No duplicate elements allowed

🔄 Maintains the order in which elements were inserted

⚡️Backed by a hash table + linked list

🌲 TreeSet in Java

TreeSet is a class that implements the NavigableSet interface and stores elements in sorted
(ascending) order.

🚫 No duplicates allowed

📶 Elements are automatically sorted

⚙️Backed by a Red-Black Tree

what is linked list?

LinkedList in Java is a doubly-linked list implementation of the List and Deque interfaces,
allowing for efficient insertion and deletion of elements from both ends (head and tail).

*What is Collection in Java ?*


In Java, a Collection is an object that groups multiple elements into a single unit. It is part of
the Java Collections Framework and is mainly used to store, retrieve, manipulate, and
communicate aggregate data.

✅ Official Definition:

A Collection in Java is an interface in the [Link] package that represents a group of objects,
known as elements. It is the root interface of the Java Collections Framework.

What is Arraylist in java ?

ArrayList in Java is a part of the Collections Framework that implements the List interface. It
uses a dynamic array to store elements and provides random access to elements using an
index.

Define Vector and Stack in Java ?

A Vector is a part of Java's Collection Framework and is found in the [Link] package. It is a
type of dynamic array that can grow or shrink in size as needed to accommodate elements.

A Stack is a linear data structure that follows the LIFO (Last In, First Out) principle. It is also
part of the [Link] package and is implemented as a subclass of Vector.

Define Set Interface (HashSet) in Java ?

The Set interface in Java is part of the Java Collections Framework and represents a
collection that does not allow duplicate elements. One of its popular implementations is
HashSet.

🔄 HashSet uses a hash table to store elements.

🔢 It stores elements in no particular order (unordered).

❌ Duplicates are not allowed.


✅ Allows null values and supports fast operations like add(), remove(), and contains().

Define Array in java ?

An array in Java is a data structure that stores multiple values of the same data type in a
single variable. It allows indexed access to elements, where indexing starts from 0.

🔢 Fixed in size and stored in contiguous memory locations

🧠 Each element can be accessed using its index number

💻 Supports both primitive types and objects

What is the Definition of User Defined Objects in Collection ?

In Java, User Defined Objects in Collection refer to custom class objects that are stored and
managed using collection frameworks like ArrayList, HashSet, HashMap, etc. These objects
are created based on user-defined classes, and collections can store multiple such objects.

To use these objects efficiently in collections (especially in sets or maps), it is often necessary
to override equals() and hashCode() methods for proper comparison and hashing behavior.

🔐 Top 10 Features That Make Java Secure 🔐

Java is renowned for its robust security, thanks to these features:

👉 1. JVM (Java Virtual Machine):

Isolates the code execution environment, protecting the host system from malicious code.

👉 2. Security APIs:
Built-in libraries for encryption, authentication, and secure communication (e.g., Java
Cryptography Architecture).

👉 3. Security Manager:

Controls application actions at runtime, like file and network access.

👉 4. Void of Pointers:

Eliminates direct access to memory, reducing vulnerability to memory corruption.

👉 5. Memory Management:

Automated garbage collection prevents memory leaks and other misuse.

👉 6. Compile-Time Checking:

Catches errors early, ensuring code integrity before execution.

👉 7. Cryptographic Security:

Advanced encryption and secure data transmission with tools like SSL and digital signatures.

👉 8. Java Sandbox:

Isolates code execution, restricting access to critical system resources.


👉 9. Exception Handling:

Helps prevent unexpected crashes by managing runtime errors effectively.

👉 10. Java Class Loader:

Dynamically loads classes securely, preventing unauthorized code execution.

💡 These features make Java a trusted choice for secure and reliable application
development.

Define Cursors in Java ?

In Java, cursors are objects used to traverse and access elements of a collection. The main
types are Enumeration, Iterator, and ListIterator, each allowing different levels of access and
modification during iteration.

*Frequently asked Java interview questions with answers, categorized by experience


level:* 👇

*Junior Level*

*1. What are the access modifiers you know? What does each one do?*

public: Accessible from any other class.

protected: Accessible within the same package and subclasses.

private: Accessible only within the same class.


default (no modifier): Accessible only within the same package.

*2. What’s the difference between using == and .equals() on a string?*

== compares object references (whether they point to the same memory location).

.equals() compares the actual contents of the objects (strings, in this case).

*3. What is Polymorphism?*

Polymorphism allows objects of different classes to be treated as objects of a common


superclass. It allows one interface to be used for a general class of actions, making it easier
to scale and extend.

*4. Can a static method be overridden in Java?*

No, static methods are resolved at compile time, so they are not eligible for overriding.
However, they can be redefined in subclasses.

*5. What is the difference between an Integer and int?*

int is a primitive data type, whereas Integer is a wrapper class that holds an int value as an
object. Integer provides utility methods like parseInt() and compareTo().

*Mid Level*
*1. What is Reflection in Java?*

Reflection is an API that allows Java programs to examine or modify the runtime behavior of
applications. It can be used to inspect classes, methods, fields, and annotations.

*2. What does the keyword synchronized mean?*

It ensures that a method or block of code is accessed by only one thread at a time, providing
thread safety in concurrent programming

*3. Can you have "memory leaks" in Java?*

Yes, memory leaks can occur in Java if objects are no longer used but still referenced,
preventing the garbage collector from reclaiming the memory.

*4. What does it mean when we say a String is immutable?*

A String is immutable, meaning once it is created, its value cannot be changed. Any
modification to a String results in the creation of a new String object.

*5. What is Dependency Injection?*

Dependency Injection (DI) is a design pattern where an object receives its dependencies
(other objects) at runtime rather than creating them internally. Libraries like Spring and
Google Guice support DI.

*Senior Level*

*1. How does [Link]() work?*


[Link]() converts a string into a primitive int. It throws a NumberFormatException if
the string is not a valid number.

*2. What is Autoboxing and Unboxing?*

Autoboxing is the automatic conversion between primitive types and their corresponding
wrapper classes (e.g., int to Integer).

Unboxing is the reverse operation, where a wrapper class object is automatically converted
to its corresponding primitive type.

*3. What is the difference between StringBuilder and StringBuffer?*

Both are used to create mutable strings, but StringBuffer is thread-safe, while StringBuilder
is not. StringBuilder is faster than StringBuffer for single-threaded applications.

*4. What is the difference between fail-fast and fail-safe in Java?*

Fail-fast iterators throw a ConcurrentModificationException if the collection is modified


while iterating.

Fail-safe iterators create a copy of the collection to iterate over, preventing exceptions during
modifications.

*5. What is a daemon thread?*

A daemon thread is a background thread that does not prevent the JVM from exiting. It is
usually used for tasks like garbage collection.

You might also like