Download presentation
Presentation is loading. Please wait.
Published byGloria McLaughlin Modified over 9 years ago
1
Last update October 18, 2004 Advanced Programming 2004 Java Beans
2
Advanced Programming 2004 Slide 14. 2Agenda Software Component JavaBeans Component Writing a simple beans
3
Advanced Programming 2004 Slide 14. 3 Example: Car as a hierarchical component CAR Brakes Engine BatteryLightsTires Fuel Tank Cylind er Shaf t
4
Advanced Programming 2004 Slide 14. 4 Why Component? –Component-based development enables higher level of software reuse –Component Based Software Development is the d e facto paradigm for developing large Software systems – » enterprise-scale distributed applications » N-tier Web applications
5
Advanced Programming 2004 Slide 14. 5Component Software component a software building block “A software component is a unit of composition with contractually specified interfaces and explicit context dependencies only. A software component can be deployed independently and is subject to composition by third parties.” [Szyperski 97]
6
Advanced Programming 2004 Slide 14. 6 How Objects Differ from Components Components Can be written in any language More loosely coupled than objects Larger granularity than objects Support multiple interfaces, and interface- oriented design Support more forms of dynamic binding and dynamic discovery Have better mechanisms for third party composition More support for higher order services (security, transactions, etc) Designed to obey rules of the underlying component framework Objects Bound to OO languages Many tight dependencies such as impl. Inheritance, fragile base class Fine-grained units of composition Limited forms of connectors (method invocation) Limited sets of supported services such as security, transactions, etc. Designed to obey Object-oriented principles
7
Advanced Programming 2004 Slide 14. 7 Component and Composition Keyboard CD Rom Mouse Motherboard Memory Harddisk Video card Printer Monitor
8
Advanced Programming 2004 Slide 14. 8 Component - JavaBeans The JavaBeans API makes it possible to write component software in the Java programming language. Components are self-contained, reusable software units that can be visually composed into composite components, applets, applications, and servlets using visual application builder tools. JavaBeans components are known as Beans.
9
Advanced Programming 2004 Slide 14. 9 Properties, Methods and Events Properties are the named attributes associated with a bean. Methods of a Bean are the normal Java methods which can be called from other components. Events are a way of providing information to other components by notifying them about something which happened.
10
Advanced Programming 2004 Slide 14. 10 JavaBeans Requirements one or more Java classes packaged in JAR file, bean target class marked serializable implements Serializable default constructor, no-parameters
11
Advanced Programming 2004 Slide 14. 11 Writing a simple bean Creating a simple Bean Compiling and saving the Bean into a Java Archive (JAR) file Inspecting the Bean's properties, methods, and events
12
Advanced Programming 2004 Slide 14. 12 A simple Bean: SimpleBean.java import java.awt.*; import java.io.Serializable; public class SimpleBean extends Canvas implements Serializable { //Constructor sets inherited properties public SimpleBean(){ setSize(60,40); setBackground(Color.red); } Implements serializable No-parameter constructor
13
Advanced Programming 2004 Slide 14. 13 Compiling and packaging a beans Compile the Bean: javac SimpleBean.java Create a manifest file. Use your favorite text editor to create a file, we'll call it manifest.tmp, that contains the following text: Name: SimpleBean.class Java-Bean: True Create the JAR file. The JAR file will contain the manifest and the SimpleBean class file: jar cfm SimpleBean.jar manifest.tmp SimpleBean.class
14
Advanced Programming 2004 Slide 14. 14 Where to Get More Information JavaBeans™ API Specification Java™ Tutorial : JavaBeans™
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.