What exactly is a JavaBean?

Source: Internet
Author: User
1. JavaBean and EJB
(1) JavaBean and EJB specifications share the following goals: Promote Java through standard design patterns Program Code To improve the portability between the development process and development tools, but the original problems of these two specifications are to solve different problems.
Standard Specifications defined in the JavaBean Component Model are designed to generate reusable components. These components are usually used in IDE development tools and are usually Visualized components, of course it is not necessarily a visual component.
(2) The component modulo defined in the EJB specification is just used to develop Java programs on the server. As EJB may be executed on different server platforms, including large hosts without graphics, therefore, EJB cannot use graphical libraries such as AWT or swing.
2. Differences between JavaBean and class libraries:
(1) Not all useful modules must be converted to Bean. Bean, which can be used for visualized operations to achieve some results.
(2) A class library is an effective operation that provides function operations to programmers, but it cannot benefit from visual operations.
(3) For example, it is better to provide APIs for JDBC database access as a class library than as a bean, because the core of JDBC is to use a programmable API, it is not directly visible in visual operations. however, writing a library to access bean at the top layer of JDBC makes sense. for example, you can write a customized "select" bean to help you form a query statement. When the program is running, run the query statement using JDBC and display the result set.
3. JavaBean and Visual Programming
3.1 Visual Programming
(1) drag components from the component board to the form using visual programming tools such as VB and Delphi. When you drag components, the program development tool starts to write code for you, these Code allows this component to be generated during program execution.
(2) drag a component to a form. Generally, it is not enough to complete the program. You must change the properties of the component, such as color, text, and connected database. the property that can be modified during the design period is called "attribute". A producer can modify the attributes of a component in a program development tool and build the component. The configuration is stored. When the program is executed, these settings can be replied.
(3) During the design period, a total score of a visual component is represented by an event, meaning that these events can occur on the component.
(4) The program development tool uses the reflection mechanism ("reflection") to dynamically query the content of a component and find the properties supported by the component ), and event. Once you know this information, it will be able to display its properties and allow you to change it, as well as display available events.
3.2 JavaBean
In the preceding visual programming, we can see that a component is a piece of program code. By being saved as a class, the key lies in how the program development tool discovers the attributes and events of the component. both VB and Delphi implement this through some mechanism, while Java introduces visual component development into a higher realm through JavaBeans, because a bean is a class. for the above content, JavaBean has the following rules:
(1) For a property named XXX, you usually need to write two functions, getxxx () and setxxx ().
(2) You can use the get/set method to process Boolean, and use is instead of get.
(3) bean general functions do not need to follow the naming rules described above, but must be public.
(4) You can use the swing listener to handle events.
3.3key JavaBean Technologies
(1) The most important part of the bean architecture is that when the bean is dragged from the component disk palette to the form, the program development tool can generate the bean (if there is a default constructor, ), and then in the absence of bean Source code In this case, all the necessary information of the "property sheet" and the event handler is extracted.
(2) the reflection of Java allows us to find all the functions of any unknown class. The reflection mechanism is used to solve the bean problem, which is perfect, you do not need to use additional language keywords like other visual languages. ** in fact, one of the main reasons that the reflection mechanism will be added to Java is to support beans (of course, reflection is also the serialization of objects) and remote Method Invocation (Remote Method Invocation) provides necessary technical support ). therefore, you may expect that the designer of the program development tool should use the reflection mechanism on each bean to find its function and find out the bean attributes and events.
(3) Java designers hope to provide a standard tool that not only makes beans easier to use, but also provides a standard way to produce more complex beans. this tool is an introspector class, and the most important of which is static getbeaninfo (). you can pass in a class reference to this function to thoroughly query the class and return the beaninfo object. then you can dissect it and obtain its properties, functions, and events ).
3.4 bean Packaging
Before you put beans in a visual development tool that supports beans, you must put them in the standard bean container. the so-called standard bean container is a jar file containing all bean classes and a manifest File)
5. Architecture of JavaBean
The JavaBean architecture is one of the first complete standard component-based models. In the integrated IDE, JavaBean can be operated during design.
(For details about the component model, see :)

The JavaBean Component Model provides developers with a standard way to define Java classes so that their components can operate in the JavaBean container environment. The JavaBean Component provides its attributes based on various attribute definition models, event and inner view information, which allows customization of design tools to achieve bean customization during design.
6. Basic Requirements for JavaBean programming:
If you want to create a product-level bean, remember the following:
(1) make the bean smaller, the better, but pay attention to whether the current browser supports small beans
Bean may lead to tool lag, leading to browser lag, and ultimately cause JDK lag. If you must use the cut-edge class or the bean nature requires a large bean, you should consider using your bean as a plug-in and sending it in a self-contained jar, or, if possible, make it have its own small installation process. You will lose the advantages of some small beans:
The web administrator must perform one more step: remind the user to download and install your jar or installer before browsing the Web page.
Internet surfers must also perform one more step: download and install your jar or installer before browsing the Web page.
(2) Make your bean translable
All translated texts, including brief descriptions of names and beans, and their features, are separated into. properties files. The jar Wizard will do this for you. The two things you need to remember and do yourself are: the feature editor and the customizer. The customizer, dialog box Feature Editor, or select all terms in the feature editor, such as high, medium, and low, must also be separated for translation. Ideally, you can also translate beans and provide. properties files in various languages in bean jar. However, if you provide at least the local language. properties file, a third party can translate the bean for you.
(3) specify depends-on for bean in the file list: Tag
Mark all the files in the jar of bean as "vs. is required only during editing ". All files required during runtime are listed after the: label in the jar list file. The release tag of the jar Wizard makes this operation very simple and grants you the permission to list files.
If you do not specify the dependency on: tag, the tool assumes that all files are required at runtime. This is bad for download performance (such as unnecessary download of the feature editor and other files only needed during editing.
(4) Give your bean a clear preferred size
Bean will implement the getpreferredsize method, so that it performs well when it is constructed with a feature that may be undefined for the first time. If the bean is 0x0 pixels when it is put for the first time, the user may be confused. When you change the keyword feature, the preferred size also works properly. For example, if the bean has a conversion feature between the vertical and horizontal orientations, the preferred size should be written to adjust itself accordingly.
(5) Specify the default feature for bean
Using the default features in the JavaBean specification, it makes your bean easy to use in some tools. The jar wizard simplifies this operation and grants you the beaninfo permission.
(6) specify a brief non-technical name and brief description for the bean and Its Features
Find brief non-technical names to replace lengthy technical terms. For example, replace accumulatorinterval with Sum interval. Note that the preferences of feature names are expressed in lower case with spaces between words, which is more friendly to users.
(7) narrow the visible feature Scope
Provide a clear beaninfo for bean so that every instance variable is not displayed as a bean feature, and every method is not displayed as a bean operation. The jar wizard simplifies this operation and grants you the beaninfo permission.
(8) specify large and small icons for bean
Finally, we provide beans with large (32x32) and small (16x16) color icons. Make sure that the icon has a transparent background different from the gray one. Although rarely used, you should also develop the habit of providing black and white icons. The palette tag of the jar wizard simplifies this operation and grants you the beaninfo permission.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.