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

Java Programmin

The document provides an overview of key Java programming concepts including adapter classes, stored procedures, daemon threads, and the Java Collections Framework. It explains how adapter classes enhance code organization, stored procedures improve performance and security in database interactions, daemon threads support background tasks, and the Collections Framework offers efficient data structures for various applications. Each section includes definitions, advantages, and examples to illustrate their usage in Java development.

Uploaded by

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

Java Programmin

The document provides an overview of key Java programming concepts including adapter classes, stored procedures, daemon threads, and the Java Collections Framework. It explains how adapter classes enhance code organization, stored procedures improve performance and security in database interactions, daemon threads support background tasks, and the Collections Framework offers efficient data structures for various applications. Each section includes definitions, advantages, and examples to illustrate their usage in Java development.

Uploaded by

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

MezanTeppiuniversty

MezanTeppiuniversty

College of Computing $ Informatics


Department Of informetion techenology
assesgment of advance program

NUMBER NAME ID

01 Yohannesadane 4731/16
TableofContenrt
1. AdapterClassesandInnerClasses 3
WhatAreAdapterClasses? 3
CommonAdapterClasses 3
InnerClasses 4
TypesofInnerClasses 4
2. StoredProcedures 4
Introduction 4
OverviewofStoredProcedures 4
AdvantagesofStoredProcedures 5
CallingStoredProceduresfromJava 5
StoredProcedurevs. DynamicSQL 5
3. DaemonThreads 6
Introduction 6
WhatAreDaemonThreads? 6
CreatingDaemonThreads 6
[Link]-DaemonThreads 6
LifecycleofDaemonThreads 6
4. JavaCollections 17

OverviewofJavaCollections 7
CoreCollectionInterfaces 7
CollectionImplementations 7
CollectionComparison 8
Summary 8
References 8
1. AdapterClassesandInnerClasses
AdapterclassesandinnerclassesarepowerfulJavaconstructsthatenhance code
organization and event handling. Adapter classes provide abstract implementations of
listener interfaces, allowing developers to override only necessary methods. Inner
classes, defined within other classes, offer better encapsulation and scoping of related
functionality.

WhatAreAdapterClasses?
Adapter classes are abstract classes that implement listener interfaces with empty
[Link] rather
than implementing all methods from an interface. This reduces boilerplate code.

CommonAdapterClasses
AdapterClass ImplementsInterface Purpose
WindowAdapter WindowListener Windoweventshandling
MouseAdapter MouseListener Mouseclickandmotion
events
KeyAdapter KeyListener Keyboardinputevents
FocusAdapter FocusListener Focusgain/lossevents
ComponentAdapter ComponentListener Componentresize/move
events
InnerClasses
Inner classes are classes defined inside other classes. They have four types: member
innerclasses,localinnerclasses,anonymousinnerclasses,andstaticnestedclasses. Inner
classes can access the outer class's private variables and methods.

TypesofInnerClasses
Type Scope CanAccessOuter UseCase
MemberInner Instance-level Yes Closelyrelated
functionality
LocalInner Method-level Yes(finalonly) Eventhandling
AnonymousInner Block-level Yes(finalonly) One-time
implementations
StaticNested Class-level No Utilityclasses

2. StoredProcedures
Introduction
Stored procedures represent a critical intersection between Java applications and
relational databases. These precompiled SQL statements reside in the database and
[Link]
procedures through the JDBC CallableStatement interface, enabling sophisticated
database operations.

OverviewofStoredProcedures
Stored procedures are precompiled SQL statements stored in the database. They
accept input parameters and return results. Java applications call these procedures
throughJDBCusingCallableStatementinterfaceforbetterperformanceandsecurity.
AdvantagesofStoredProcedures
Advantage Description
Performance Pre-compiledandoptimizedonserver
Security PreventsSQLinjectionattacks
NetworkTraffic Reducesdatatransferbetweenclientand
server
Reusability Canbecalledfrommultipleapplications
Maintainability Businesslogiccentralizedindatabase

CallingStoredProceduresfromJava
// Example of calling a stored procedure with parametersString call = "{call
insertUser(?, ?)}";CallableStatement cstmt = [Link](call);
[Link](1, "John");[Link](2, 25);[Link](); The
CallableStatementinterfaceextendsPreparedStatementandprovidesmethodsto
register output parameters and retrieve their values.

[Link]
Feature StoredProcedure DynamicSQL
Compilation Pre-compiled Compiledatruntime
Performance Faster Slower
Security Moresecure Susceptibletoinjection
Maintenance Server-side Client-side
Flexibility Fixedstructure Moreflexible
3. DaemonThreads
Introduction
Daemonthreadsarespecializedbackgroundthreadsdesignedtosupportthemain
application without blocking JVM shutdown. They are essential for implementing
services like garbage collection, event dispatching, and monitoring. Understanding
daemon threads is crucial for building responsive, efficient Java applications.

WhatAreDaemonThreads?
Daemonthreadsarebackgroundthreadsthatserve [Link]
threads, the JVM terminates when all non-daemon threads complete, regardless of
daemon thread status. Daemon threads are useful for background tasks like garbage
collection and monitoring.

CreatingDaemonThreads
// Example of creating a daemon threadThread daemonThread = new Thread(new
MyRunnable());[Link](true);[Link](); The
setDaemon(true)[Link]
started, it cannot be changed to daemon status.

[Link]-DaemonThreads
Property DaemonThread Non-DaemonThread
BlocksJVMExit No Yes
Purpose Backgroundtasks Mainapplicationlogic
ResourceCleanup Maynotcomplete Alwayscompletes
Examples Garbagecollector Mainthread
UseCase Supportoperations Corefunctionality

LifecycleofDaemonThreads
Daemonthreads follow the standard thread lifecycle: New → Runnable → Running →
Blocked/Waiting → Terminated. However, the JVM may terminate them abruptly if all
non-daemonthreadscomplete,withoutwaitingforpropercleanuporresourcerelease.
4. JavaCollections
The Java Collections Framework is a comprehensive suite of data structures and
algorithms that forms the foundation of effective Java programming. It provides
standardizedinterfacesandimplementationsforstoring,retrieving,andmanipulating
groups of objects efficiently.

OverviewofJavaCollections
Java Collections Framework provides a unified architecture for representing and
[Link],implementations,andalgorithms for
storing and retrieving data efficiently. The framework is built on the Collection interface
hierarchy.

CoreCollectionInterfaces
Interface Methods Purpose
Collection add,remove,contains, Rootinterfaceforall
size collections
List get(index),add(index), Orderedcollectionwith
remove(index) duplicate support
Set add,remove,contains Unorderedcollectionwith
no duplicates
Map put,get,remove, containsKey Key-valuepairmapping

Queue offer,poll,peek FIFOdatastructure

CollectionImplementations
Implementation Interface Thread- Ordered UseCase
Safe
ArrayList List No Yes General-purpose
dynamic array
LinkedList List No Yes Frequent
insertions/deletions
HashSet Set No No Uniqueelements,
fast lookup
TreeSet Set No Yes Sortedunique
elements
HashMap Map No No Key-valuefast
lookup
TreeMap Map No Yes Sortedkey-value
pairs
ConcurrentHashMap Map Yes No Thread-safekey-
value storage

CollectionComparison
ArrayList: Fast random access O(1), slow insertion O(n)LinkedList: Slow random
accessO(n),fastinsertionO(1)HashSet:AverageO(1)lookup,noorderingTreeSet: O(log n)
operations, maintains sorted orderHashMap: Average O(1) lookups, unorderedTreeMap:
O(log n) operations, sorted by key

Summary
 AdapterclassesandinnerclassesarefundamentalJava conceptsthatpromote
code reusability and organization. Adapter classes reduce boilerplate in event
handling, while inner classes provide better encapsulation and organization of
related functionality.
 Stored procedures are powerful database tools that improve application
[Link]
developers use CallableStatement to invoke stored procedures, making themideal
for complex database operations.
 Daemon threads are essential for implementing background services in Java
applications. They run concurrently with the main application and terminate
automatically when all non-daemon threads finish execution. Understanding
daemonthreadsiscrucialforwritingresponsiveandefficientJavaapplications.

 Java Collections Framework is a cornerstone of Java programming, providing


efficient data structure implementations for various use cases. Understanding the
differentcollectiontypes,theirperformancecharacteristics,andwhentouseeachis
critical for writing performant Java applications.

References
• OracleCollectionsFrameworkDocumentation
• "EffectiveJava"byJoshuaBloch- CollectionsChapter
• [Link]
• OracleJavaThreadingDocumentation
• "JavaConcurrencyinPractice"byBrianGoetzetal.
• ThreadAPIDocumentation

You might also like