Java & JavaBeans My name: Gratian Schiopu

1 Java & JavaBeans My name: Gratian SchiopuPresentation a...
Author: Coleen Heath
0 downloads 3 Views

1 Java & JavaBeans My name: Gratian SchiopuPresentation about: Java en JavaBeans

2 Contents of the presentation1. Introduction 2. Java 3. JavaBeans

3 1. Introduction Java -> by SUN in 1990s-> new programming language Applet -> small application that runs in a Webpage Java component models -> JavaBeans -> Servlets -> Enterprise Java Beans in 4 flavours -> J2EE Application Components Java Services

4 1. Introduction Applet -> small application that runs in a Webpage-> they run on client side -> safety problem !! -> compiled code be extra checked at load time. -> for efficincy -> the JIT compilers (just in time compilers) -> authentication techniques for applets -> signatures -> signed applets -> JVM (Java Virtual Machine) Java progr. -- Java compiler --> Java byte code ---> -- runned by JVM --> on different platforms.

5 Java vs Java 2 - Java2 new ideas: 1. Platform editionPlatform edition:= Java specifications that address the concerns of a specific class of Java users. - J2EE (Java2 enterprise edition) - J2SE (Java2 standard edition) - J2ME (Java2 micro edition) 2. Runtime environment RE := implementations of the JVM 3. Software dev. Kit SDK := for each environment the SDK + J2SE API 4. Reference implementation .

6 Java vs Java 2 - Java2 new ideas:1. Platform edition := Java specifications that address the concerns of a specific class of Java users. - J2EE (Java2 enterprise edition) - J2SE (Java2 standard edition) - J2ME (Java2 micro edition) 2. Runtime environment RE := implementations of the JVM 3. Software dev. Kit SDK := for each environment the SDK + J2SE API the pair of RE + SDK 4. Reference implementation.

7 Organization of Java 2 spaceCDC= connected devices config J2EE optional packages CLDC= connected for limited devices config MIDP = mobile information device profile J2EE platform CVM = light weight JVM KVM = kilobyte JVM J2ME platform J2SE optional packages Personal profile J2SE platform and SDK Foundation profile MID profile JRE HotSpot JVM CDC CLDC CVM KVM

8 Java 2 Runtime Environment, Standard Edition v.1.4(JRE) -- is included in --> (J2SE) -- is included in --> (J2EE) JRE includes: - runtime - core libraries - browser pugin. JRE v.14 builds:- on HotSpot runtime and HotSpot JIT compiler - they perform online reoptimization of the JIT-compiled code - HotSpot compilers: for client and for server apart versions. (Q: how they differ? A: by optimisation functions in memory, startup time, throughput, latency)

9 SDK JRE Organisation of the Java 2 platform, Standard Edition v1.4develpment tools & API Java compiler Java Debugger Javadoc JPDA JRE deployment technologies Java Web Start Java Plug-in Swing AWT User Interface toolkits Sound Inputs Java 2D Accessibility Integration APIs RMI JDBC JNDI CORBA XML Logging Beans Locale support Core APIs Preferences Collections JNI Security Lang Util New I/O Networking Java HotSpot client compiler Java HotSpot server compiler Java virtual machine Java HotSpot VM runtime

10 Java 2 Runtime Environment, Enterprise Edition v.1.4- J2EE containst the same RE and SDK as the J2SE. - J2EE is ment to be a specification implemented by many vendors - SUN provides the “refference implementation” (in source code) with its standard semantics. *- the ref. imp. is given by SUN as an example *- and for 3rd parties as a check to see if they are compliant to SUN technology *- useful as a complete environment to enforce a Java standard. (the use of compatibilty test suites --validate--> new Java implementations) *- Java BluePrints := collection of design guidelines and patterns to help map certain classes of enterprise applications to the space of J2EE technologies.

11 Java 2: three editions Micro, Standard, Enterprise (1999)- micro -> specified for small and embedded devices. - standard -> targets the client-only solution space - enterprise -> targets the multitier solution space - JavaCard -> targets the smartcard (no formal tier of Java2 classification)

12 Java 2: the Micro edition- micro -> specified for small and embedded devices. - CVM (lightweight implementation of full JVM) - KVM (trimmed down implementation) - on top of VM , API as configurations and profiles := cut down classes+interfaces - CDC connected device config. - CDLC configuration for limited devices - device specific profiles i.e. MIDP := mobile information device profile - no upwards compatibility supported. - standard -> targets the client-only solution space -> is a proper subset of the enterprise ed. - enterprise -> targets the multitier solution space

13 Java 2: the Standard edition- standard -> targets the client-only solution space -> is a proper subset of the enterprise ed. -> comprises: 2606 classes and 789 interfaces java.lang, java.lang.ref, java.lang.reflect - basic types of java language, - foundation classes for class loading & runtime reflection, - support of various types for garbage collection, - extended reflection support. java.applet - applet base class. java.awt, java.awt.color, java.awt.datatransfer etc. - abstract window toolkit, - Java UI construction framework java.beans, java.beans.beancontext - JavaBeans base class & support types java.io , java.nio - char bytestream read & write, files, channels

14 Java 2: the Standard editionjava.math, basic lib. for math foundation class java.net, network support lib. java.rmi, remote method invocation, late binding, remote garb.collection, distributed service registry, server support, RMI over CORBA. java.security security manager, ACLs, certificates, authentication, login, X500 directory java.sql support for SQL databases java.text, text manipulation java.util, various utilities (ZIP file access, JAR,...) java.crypto, cryptography (MD5, SHA-1, DES) javax.imageio, Image I/O support java.naming, naming and directory access, LDAP java.printing, printing support java.sound, sound support

15 Java 2: the Standard editionjava.swing, Swing UI construction framework, HTML support java.transaction, transaction support java.xml, XML parsing java.security security manager, ACLs, certificates, authentication, login, X500 directory org.omg.CORBA, standard CORBA interfaces & ORB binding Service provider interfaces (SPI) - implements a particular service - Java std. Framework mediates between clients and SPIs - ex. of SPIs for I/O channels, character sets, authentication, naming.

16 Java 2: the Enterprise edition- enterprise -> targets the multitier solution space -> 3801 classes, 1261 interfaces, 5062 types -> adds to SE classes, 189 interfaces -> adds to SE classes, 189 interfaces - the heart of J2EE architecture: a family of component models (3 groups of components with 9 variations of component theme) A - client tier: 1. application componets, 2. JavaBeans, 3. applets B - Web server tier: 1. servlets, 2. JSPs C - application server tier: EJB in 4 variations: 1. Stateless session 2. Stateful session 3. Entity beans 4. Message-driven beans - J2EE supports specialized components model - J2EE uses different types of components not just different components.

17 Java 2: the Enterprise edition- what about the boundaries between components? - overlap. - will the number of J2EE component models grow further? - unclear the development of future softw. architecture - JavaBeans components not shown in the next fig. they transgress the boundaries between the diffrent tires - JavaBeans can beused in any tire - the arrows show the control flow but are not absolete (dataflow in both ways) - 2 extra integrating layers services : - JNDI (Java naming and directory services) - JMS (jave message service) - more: (transactional coordination, security services, etc)

18 Naming and directories (JNDI)Architectural overview of J2EE Client tier Web server tier App server tier Backend tier Web browser + applets JSP container + JSPs Servlets EJB container + Empty Beans Statefull & stateless session beans Messagedriven Databases Rich clients + application client components Legacy apps etc. Web service clients Naming and directories (JNDI) Messaging (JMS)

19 Architectural overview of J2EE

20 Java: the language - almost pure OO language: all code resides in methods & classes. - all classes except Object inherit interface and implementation from 1 class only . - not everything is an object: - non-object types are: - primitives (like: boolean, byte, char, short, int, long, float, double) and - interface types. - objects are either instances of classes or array - objects can be created but not deallocated (garbage collection) - a class can implement any number of interfaces - interfaces can be in a multiple interface inheritance relationship. - all Java classes & interfaces belong to packages (encapsulation & protection). - packages can form hierarchies. - inside a package the classes inside that package can be accessed freely. - ouside packages merely handle namespaces.

21 Java: the language - ex. Of the naming in Java: package.Type.feature- package = name of package - type = name of class or interface - feature = name of method or attribute - by explicit importing of a package we can use Type.feature in the new package (classes, interfaces, methods and attrib. of imported package are available). - Final class = a non extendible class (further ‘inheritance from’ not possible) - Java methods can be: - final (non overridable) - static (class instead of instance methods). - Java attributes can be: - final (cannot change value after initialisation) - static (class instead of instance attribute). - a class extend only one class (except for java.lang.Object ) which has no base class.

22 Java structuring constructsAbstractions from imported package Package Package Package Abstract class <> Interface Concrete class Final class <> Interface Class Constants Attributes Methods Constants Methods I C Class implements or interface extends I Class extends C

23 Part of the java.awt.image packagejava.lang Object <> Clonable java.awt.image DirectColorModel ColorModel IndexColorModel FilteredImageSource <> ImageProducer CropImageFilter ImageFilter RGBImageFilter <> ImageConsumer MemoryImageSource <> ImageObserver PixelGrabber Means extends

24 Java: the language - java.lang , java.util , java.io = form the specification of Java - only java.lang alone implements 82 classes. - the intertwining between java.lang and different packages is heavy. Ex.: classes: Object , String, Throwable are entangled with null refference, array type constructors, string literals, throw statement - Java supports arbitrarly (possibly circular) dependencies across packages - access level for top-level interfaces and classes: - package-wide (default) -> access in the package (not outside) - public -> outside - class protections for meth. & attrib. in a a class: - private -> (only in the class) - package-wide (default) -> all classes in the package - protected -> access of all subclasses of the defining class - public > globally accessible - final attrib. and methods cannot be overridden

25 Interfaces vs classes - separation between interface and classes:-> single inheritance + multiple interface inheritence -> eliminates the diamond inheritance pb. (interfaces introduce niether state nor behavior) -> while preserving the possibility of a class to be compatible with multiple independent interfaces

26 << Interface >>Model view contruction using Observable and Observer Object Observable << Interface >> Observer * 1 Model View

27 Exceptions & exceptions handling- exceptions and runtime errors -> in Java as exception or errors objects - these exceptions can be trown expicitly or at runtime - exception & error objects = intances of classes derived from Throwable

28 Threads and synchronisation- Java = concurrent oo-language - the unit = the thread (lightweight -> they execute in the same addr. space) - threads are orthogonal on objects (passive) - communication through side-efects & synchronisation - a Java program ends when last thread has terminated - priority can be given to threads (1-10) - 2 types user or demon threads - a thread is associated with an owning object at thread creation time - through this obj. A thread can be suspended, resumed or terminated. - Java supports threaded synch. 1. On entrance to a synchronized method or 2. At a synchronized statement

29 Threads and synchronisation- synchronization forces a thread to lock on an object before proceeding - 1T-1O … one lock per object. - if a thread tries to lock and the thread has already a lock on the same object, it can continue. (deadlock avoidence)

30 States & transitions in Java threadsnew start runnable synchronized Wait for lock resume suspended suspend pre-empt synchronize notified schedule running wait Wait for notify suspend stop, destroy terminated

31 Garbage Collection - recover memory space after an object is unreachable - mechanism 1: object finalization -> override of the method Object.finalize *JVM detects that an object is unrechable and recovers the mem. space * garbage collection can be called with: System.gc * finalization can be called with: System.runFinalization( ) - how about resources after such calls? - mechanism2: streeing the garb. collection by using references: - soft - weak - phantom vs - strong ref. Strong vs soft vs weak vs phantom reachable objects: S S S … S (strong); s S s S…. S (soft); S s s S w … S (weak); S s w p … s (phantom)

32 JavaBeans - What’s a JavaBean? -> a component := a set of classes+resources but a JavaBean is also the instance of such a component (customized and connected) - the distinction: class vs object is not carried through in JavaBeans - dual usage model: -> beans assembled by an assembly tool (i.e. an application builder) at ‘design-time’ -> beans are used at ‘runtime’

33 Aspects of the JavaBeansModel:1- Events Beans instance beans is a source or listener of some events. (sources <- assembly tool connects -> listeners) 2- Properties Beans - set of instance properties. Properties used to customize or programmatically. Changes in properties -> events -> limitation in furter changes of properties (constraint) 3- Introspection - an assembly tool can inspect a bean for properties, events, methods that it supports. 4- Customization - using an assembly tool a bean -> customized (properties set) 5- Persistence - bean instances = customized+connected, need to be saved for reloading (app. use)

34 Events & connections: - events (JDK 1.1) := objects created by an event source and propagated to all registered event listeners - communication by MULTICAST semantics (UNICAST sem. also possible) - similar to COM connectable Objects - event object -> has no public fields and -> is considered immutable (no changes) - a listener implements a given event listener only once. For more source events there is an event adapter to find out what source triggered the event. - event adaptor -> is and a source and a listener -> filters the events and calls a specific method of the listener. - multicast evnvironment -> the set of listeners can change -> copy the set of registered listeners before Multicasting - Event ordering -> a multi-threaded environment like Java can cause deadlocks (event source locks resources needed by the event listener)

35 Events & connections: Solution:- don’t let the event source hold internal locks when they call event listeners - subtle deadlocks can arise between multithreading and event-based communication !!

36 Properties: - a bean can define properties of arbitrary types- property := discrete attribute that can affect the bean’s instance appearance or bean’s behavior - change of a property -> by get or set (in program) -> using property sheets (at assembly or runtime) (changes of properties at assembly time used to costomize the bean) - properties can constrained (by use of exception: PpopertyVetoException) - properties can be edited by property editors. - customization of some complex beans can be complex.

37 Introspection: - event and properties are supported by new interfaces and classes: ex.: EventListener, EventObject, EventSetDescriptor, PropertyDescriptor - introduction of method patterns as new notion (called design patterns) method pattern := combination of rules for the formation of a bean signature, return type and name. (Looks like templates in C++) - assembler tool needed to query a bean for the names of the get and set methods

38 JAR files: - a Java class file a single compiled class or interface- resources cannot be included in a class file -> the use of Java Archive (JAR) to package a JavaBean. - a JAR file is a ZIP-format file that include a manifest file - manifest file contain info about an archive file - an archive file may contain: - a set of class files - a set of serialized objects - help files - localization information used by the bean - icons used by the bean - other resources

39 Reflection: - Java reflection service makes possible:- inspection of classes & interfaces for their fileds and methods - construction of new class instances + new arrays - access to fields of objects and classes - access to fields of elements of arrays - invocation of methods on obj. and classes.

40 Java native interface: JNI- specifies for each platform a native calling convention : - allows native methods to: - create, inspect, update Java objects - call Java methods - catch and throw exceptions - load classes and obtain class information - perform runtime type checking

41 Java native interface: JNIInterface fct.1 Interface pointer Interface fct.2 . . . . Per-threaded JNI data structure

42 Java AWT JFC/Swing - Java abstract windowing toolkit and Java foundation classes - used for the graphical UI: - delegation based event model -> obj. connection and composition in favor of implementation inheritance - data transfer and clipboard support - drag and drop - Java 2 D - printing - accessibility -> assistive tech. (screen readers, screen magn. speech rec - internationalization -> specific for each country - swing compunents -> look and feel components across platforms

43 Enterprise JavaBeans EJB:- Java beans and EJB follow different paths - in EJB no provision for connection-oriented programming made: - EJB follow a conventional model for o.o.-composition by calling the methods of other e-bean

44 Isolation of EJB beans in containers via EJB home and EJB object interfacesEJB Server Client EJB Container Home Home EJB home stub EJB home EJB home EJB object EJB object stub Remote or local EJB bean Remote or local

45 services *File sharingJXTA architectural layering JXTA applications JXTA community applications SUN JXTA applications JXTA shell JXTA services Peer commands JXTA community services SUN *indexing JXTA *Searching services *File sharing JXTA core Peer groups Peer pipes Peer monitoring Security Peer on extended web

46 Connections

47 The End