Assignment 2
Advanced Java Technologies
Content Page 1
Submited in fulfillment of the curriculum requirements
Content Page 2
Table of Contents
1. Chapter 1: Overview of Java Input/Output ............................ Page 1
2. Chapter 2: Buffered Reader Class ............................ Page 2
3. Chapter 3: Buffered Writer Class ............................ Page 3
4. Chapter 4: PrintWriter for Formatted Output ............................ Page 4
5. Chapter 5: Object Serialization in Java ............................ Page 5
6. Chapter 6: Transient Keyword and Security ............................ Page 6
7. Chapter 7: Intro to JDBC Architecture ............................ Page 7
8. Chapter 8: The JDBC-ODBC Bridge Driver ............................ Page 8
9. Chapter 9: The JDBC Connectivity Model ............................ Page 9
10. Chapter 10: The DriverManager Class ............................ Page 10
11. Chapter 11: Navigating the ResultSet Object ............................ Page
11
12. Chapter 12: Data Retrieval from ResultSets ............................ Page
12
13. Chapter 13: The [Link] Package Interface ............................ Page 13
Content Page 3
14. Chapter 14: PreparedStatement vs Statement ............................ Page
14
15. Chapter 15: JDBC Exception Classes ............................ Page 15
16. Chapter 16: Connecting to a Remote Database ............................ Page
16
17. Chapter 17: The Java Collections Framework ............................ Page
17
18. Chapter 18: Core Collection Interfaces ............................ Page 18
19. Chapter 19: ArrayList and Dynamic Arrays ............................ Page 19
20. Chapter 20: LinkedList and Node-Based Data ............................ Page
20
21. Chapter 21: HashSet and Hashing Performance ............................
Page 21
22. Chapter 22: TreeSet and Sorted Data ............................ Page 22
23. Chapter 23: The Map Hierarchy and HashMaps ............................
Page 23
24. Chapter 24: Iterators and Collection Traversal ............................ Page
24
Content Page 4
25. Chapter 25: Conclusion and Practical Applications ............................
Page 25
Content Page 5
Content Page 6
Chapter 1: Overview of Java Input/
Output
The Java I/O (Input and Output) is used to process the input and produce
the output based on the input. Java uses the concept of a stream to make
I/O operations fast. The [Link] package contains all the classes required
for input and output operations.
A stream is a sequence of data. In Java, a stream is composed of bytes.
It's called a stream because it is like a stream of water that continues to
flow. The stream concept is fundamental in Java for reading data from a
source and writing data to a destination.
Content Page 7
Chapter 2: Buffered Reader Class
Efficiency is a key concern when performing file I/O. Without buffering,
each read or write request is handled directly by the operating system,
which can be computationally expensive. The BufferedReader class reads
text from a character-input stream, buffering characters so as to provide
for the efficient reading of characters, arrays, and lines.
Content Page 8
Chapter 3: Buffered Writer Class
The BufferedWriter class provides a buffer for Writer instances, making
the writing process significantly faster. It provides a newLine() method
which allows developers to insert a platform-dependent newline
character easily.
try (BufferedWriter bw = new BufferedWriter(new FileWriter('[Link]')))
[Link]('Efficient writing patterns.');
[Link]();
} catch (IOException e) { [Link](); }
Content Page 9
Chapter 4: PrintWriter for
Formatted Output
The PrintWriter class is an implementation of the Writer class that allows
you to print formatted representations of objects to a text-output stream.
It includes methods like printf(), println(), and print() which are identical
to those found in [Link]. It is highly preferred for text-based logging
and reporting.
Content Page 10
Chapter 5: Object Serialization in
Java
Serialization is a mechanism of converting the state of an object into a
byte stream. This stream can then be saved to a file or sent over a
network. Deserialization is the reverse process where the byte stream is
used to recreate the actual Java object in memory.
Content Page 11
Chapter 6: Transient Keyword and
Security
If a field in a class is marked as transient, that field will not be part of the
serialization process. This is useful for sensitive data like passwords or
non-persistent state like thread objects, ensuring that sensitive
information is not stored in plain byte formats.
Content Page 12
Chapter 7: Intro to JDBC
Architecture
Java Database Connectivity (JDBC) is a standard API provided by Java
to interact with relational databases. JDBC provides a uniform bridge
between the Java application and the database drivers provided by
various vendors (Oracle, MySQL, PostgreSQL, etc.).
Content Page 13
Chapter 8: The JDBC-ODBC Bridge
Driver
The JDBC-ODBC Bridge (Type 1 driver) was used extensively in the
early days of Java to allow access to any database that supports ODBC. It
acted as an intermediary, converting JDBC calls into ODBC calls, but
required local installation of drivers.
Content Page 14
Chapter 9: The JDBC Connectivity
Model
JDBC supports various models of connectivity, including Two-Tier
(Client-Server) where the Java app talks directly to the database, and
Three-Tier models where requests are routed through a middle-tier
application server for scalability.
Content Page 15
Chapter 10: The DriverManager
Class
The DriverManager serves as the basic service for managing a set of
JDBC drivers. Its principal function is to establish a connection with a
database specified by a URL by matching the subprotocol of the URL
with registered drivers.
Content Page 16
Chapter 11: Navigating the ResultSet
Object
When a query is executed, results are returned as a ResultSet object. It
maintains a cursor that points to the current row of data. Methods like
next(), previous(), and first() allow for versatile navigation across the
retrieved data set.
Content Page 17
Chapter 12: Data Retrieval from
ResultSets
Data is extracted using getter methods like getString(), getInt(), or
getDate(). These methods can take either the column name or the 1-based
column index. Using column names makes the source code much more
resilient to database schema changes.
Content Page 18
Chapter 13: The [Link] Package
Interface
The [Link] package contains core components for database interaction.
It includes interfaces like Connection, Statement, and DatabaseMetaData
which provide the contract for vendor-specific drivers to implement.
Content Page 19
Chapter 14: PreparedStatement vs
Statement
PreparedStatement is used for parameterized queries. It is pre-compiled
by the database, improving performance for repetitive queries and
preventing SQL Injection attacks by safely escaping user input strings
automatically.
Content Page 20
Chapter 15: JDBC Exception Classes
Working with databases involves failure points handled via
SQLException. It provides error codes, SQLState strings, and allows for
chaining multiple errors together, which is vital for debugging complex
enterprise database interactions.
Content Page 21
Chapter 16: Connecting to a Remote
Database
Connecting to a remote database requires a JDBC URL that specifies the
network address and port. Proper configuration involves opening firewall
ports and setting up appropriate user permissions on the remote database
server.
Content Page 22
Chapter 17: The Java Collections
Framework
The Java Collections Framework (JCF) is a unified architecture for
representing and manipulating collections across the entire Java platform,
reducing programming effort while increasing system performance and
quality.
Content Page 23
Chapter 18: Core Collection
Interfaces
The primary interfaces of the JCF include Collection, List (ordered
duplicates), Set (unordered unique), and Map (key-value pairs).
Understanding these interfaces is the first step in choosing the right data
structure for a task.
Content Page 24
Chapter 19: ArrayList and Dynamic
Arrays
ArrayList is implemented as a dynamic array. It is highly efficient for
random access with O(1) performance. It scales its internal container
automatically as more elements are added to accommodate dynamic
growth.
Content Page 25
Chapter 20: LinkedList and Node-
Based Data
LinkedList implemented as a doubly-linked list. It provides constant-time
performance for insertions and deletions but linear time for element
retrieval, making it ideal for stacks or queues that grow frequently at the
ends.
Content Page 26
Chapter 21: HashSet and Hashing
Performance
HashSet uses a internal hash table for storage. It offers constant-time
Performance for basic operations like add, remove, and contains,
assuming the hash function disperses elements properly across the
internal buckets.
Content Page 27
Chapter 22: TreeSet and Sorted Data
TreeSet is a NavigableSet implementation based on a TreeMap. The
elements are ordered using their natural ordering or by a Comparator
provided at creation time, offering log(n) time cost for basic operations.
Content Page 28
Chapter 23: The Map Hierarchy and
HashMaps
HashMap is the standard implementation of the Map interface. It
provides a high-speed data structure for looking up associated data based
on a key (e.g., looking up a Student object based on a Roll Number).
Content Page 29
Chapter 24: Iterators and Collection
Traversal
The Iterator interface provides a standard way to traverse any collection.
It allows for safe modification of the collection (like removal) during
iteration, avoiding the ConcurrentModificationException that occurs with
basic loops.
Content Page 30
Chapter 25: Conclusion and
Practical Applications
Collectively, Java I/O, JDBC, and the Collections Framework form the
basis of professional Java development. Mastery of these ensures the
build of robust applications capable of handling complex data and
persistence requirements.
Content Page 31