Java 5
Java 5
The Java Collection Framework organizes data structures into a hierarchy of interfaces and classes
to handle data effectively.
Collection: Root interface with basic methods like add, remove, size.
The hierarchy provides flexibility and reusability, enabling operations like sorting, searching, and
manipulation.
---
The ArrayList class in Java is a resizable array implementation of the List interface.
Key Features:
Dynamic Size: Automatically adjusts its size as elements are added or removed.
Limitations:
Inefficient for frequent insertions and deletions from the middle of the list.
---
The HashSet is a class in the Java Collection Framework implementing the Set interface, designed
to store unique elements.
Key Features:
Advantages:
Limitations:
Not thread-safe.
---
The HashMap is a class in the Java Collection Framework used to store key-value pairs.
Key Features:
Allows Nulls: Accepts one null key and multiple null values.
Advantages:
Limitations:
Unordered storage.
---
5. Explain Different Ways of Retrieving Elements from a Collection with an Example Program
Retrieving elements from a collection in Java can be done in multiple ways, depending on the
requirements.
Methods:
4. For Loop with Index: Useful for List where elements are indexed.
Each method offers specific advantages, such as better readability, flexibility, or parallelism in the
case of streams.
---
6. Write a Java Program to Sort Students Based on Roll Number Using ArrayList
Comparable: Natural ordering within the Student class by implementing the compareTo method.
Steps:
1. Create a Student class with fields like roll number, name, and age.
2. Use ArrayList to store Student objects.
---
7. List and Explain Basic Steps to Connect with a Database Using JDBC
JDBC (Java Database Connectivity) provides a standard API for connecting Java applications with
databases.
Steps to Connect:
---
JDBC provides several classes and interfaces to handle database operations effectively.
Core Interfaces:
Classes:
---
1. Type-1 Driver (JDBC-ODBC Bridge): Converts JDBC calls into ODBC calls.
3. Type-3 Driver (Network Protocol Driver): Converts JDBC calls into a database-independent
network protocol.
4. Type-4 Driver (Thin Driver): Directly converts JDBC calls to database-specific protocol.
Each driver type has its own advantages and use cases, with Type-4 being the most commonly
used.
---
10. Define Transaction. Describe Properties of a Transaction and Write a Sample Program to
Achieve Transaction
---
CRUD stands for Create, Read, Update, Delete, the basic database operations.
Steps: