The Sun way: Java, JavaBeans and EJB

squawkpsychoticΛογισμικό & κατασκευή λογ/κού

2 Δεκ 2013 (πριν από 3 χρόνια και 8 μήνες)

102 εμφανίσεις

1
1
The Sun way: Java, JavaBeans and EJB
Chapter 14
Key concepts of Java programming language
Key concepts of JavaBeans and EJB, the Java component model
Other Java services like Reflection, Object Serialization, RMI and
JNI
2
Java, the language
• Java is an almost pure object-oriented language
+ Class: attributes and methods
+ Object - Instance of Class
+ Single class inheritance and multiple interface inheritance
+ Non-object types: primitive types and interface types
• Java packages
+ Introduce a level of encapsulation on top of that of classes
+ Default access level: in the same package
2
3
Java, the language (cont.)
• Interface versus classes
+ Separation of interfaces and classes
+ Eliminates the diamond import problem
while preserving compatibility of class with
multiple independent interfaces.
+ Example: Observer pattern
• Exception and Exception handling
+ Exceptions and runtime errors are reflected
in Java as exception or error objects.
+ In either explicitly thrown or thrown by the
runtime system
• Threads and synchronization
+ Java supports concurrency and
synchronization
+ Unit of concurrency – Thread
+ Synchronization
• Synchronized methods
• Synchronized statements
4
Java 2
• Java 2 consists of multiple platforms established on JRE 1.4
• Without doubt, the J2EE, coming along with the support from
various vendors, is the most successful platform
3
5
Java 2 Features
• Java 2 comes bundled with software development kits (SDK)
• Moreover Java 2 is distributed in packages with IDE’s such as
SunOne
• JRE 1.4 provides more support to
+ Deployment technologies (Java web start, java plug-in)
+ Components (EJB)
+ XML
6
JavaBeans
• JavaBean is the Java component model
+ A reusable software component that can be visually manipulated in builder tools.
+ ‘Beyond OOP’
• Component Lifecycle
+ Compile time -> Assembly and design time -> Runtime
• Kinds of beans
+ GUI controls, Database viewers, Customizable mini-app., Word processors,
Invisible server beans
• Kinds of builders
+ GUI layout managers, Web page builders, Full-scale app.
+ Environments, Builder for invisible server apps.
4
7
Bean Model
• Main aspects of the bean model
+ Event: Connections between methods of beans
+ Properties: Chunks of bean’s state
+ Introspection: The way that assembly tools to learn about beans
+ Customization: Customize bean instances using assembly tools
+ Persistence: Bean instances need to be saved for reloading at runtime.
• Events and connections
+ Event sources and event listeners
+ Registration of listeners in event sources
+ A listener implements a given event listener interface
+ A bean fires an event
• Invokes a named, typed method on a named, typed interface
+ Event adapter
• performing event-filtering functions
• Solves multiple registration problem
8
Bean Model (cont.)
• Properties
+ Represent bean’s state: color, font, numerical value, ...
+ Accessible via getter/setter methods
+ Add/remove property change listeners
+ Bound properties: change notification
+ Vetoable properties: changes can be rejected
+ Customize properties: property editor and customizer classes
• Introspection
+ Using standard design patterns to deduce properties/events/methods
from beans
• the Introspector class provides a standard way
+ Developers can specify them manually by providing BeanInfo of target
beans
5
9
Beans - Packaging and Enhancements
• JAR files - packaging of beans: a ZIP-format archive file
includes:
+ A set of class files;
+ A set of serialized objects;
+ Optional help files in HTML;
+ Optional localization information;
+ Optional icons;
+ Other resource files needed by the bean.
• Java AWT enhancements
+ Delegation-based event model
+ Data transfer and clipboard support
+ Lightweight user interface framework
+ Printing
10
EJB - Enterprise JavaBeans
• Even though Enterprise JavaBeans recall JavaBeans due to its name, EJB is
constructed on different fundamentals
+ EJB approach is not wiring - connection oriented programming
+ EJB implements contextual composition, rather than having the Beans have a
peer-to-peer connection
+ It implements InfoBus, which allows a flexible decoupling of event sources and
event listeners.
• The diagram demonstrates the isolation of EJB beans in containers and EJB
object interfaces
6
11
Other Java Services
• Reflection
+ Inspection of classes and interfaces for their fields and methods;
+ Construction of new class instances and new arrays;
+ Access to and modification of fields of objects and classes;
+ Access to and modification of elements of arrays;
+ Invocation of methods on objects and classes.
• Object serialization
+ Serialization of objects into byte streams
+ Serializable, Externalizable and transient
+ Current drawback: Missing support for degradation
• RMI (Java distributed object model)
+ Distributed computing
+ Remote interface and object
• JNI (Java native interface)
+ Specifies the native calling conventions of native code outside Java
12
JXTA and Jini
• Both JXTA and Jini is developed for solving the interoperability
problems in loosely coupled distributed systems.
• Jini focuses on Java everywhere
+ It is a specification that describes how federations of Java services and
clients of such services can be formed over loosely coupled systems
+ Implements lease method for garbage collection
• JXTA is a virtual Internet over the Internet
+ Addresses the problems of peer-to-peer computing
+ Creates a new layer over existing Internet protocols
7
13
Summary
• As a OO programming language, Java provides developer a way of
presentation close to the real life, which is composed of many
objects.
• Two winning aspects of Java: applets and JVM
• JavaBeans provides a way of development with binary components
instead of Java code.
• Java provides powerful distributed (remote) computing by
applet/serverlet, JDBC, RMI, EJB and etc.
14
Reference
• Clemens Szyperski
Component Software: Beyond Object-Oriented Programming
• Bruce Eckel
Thinking in Java, 2nd Edition
• Ken Arnold and James Gosling
The Java Programming Language, 2nd Edition