Bean (software component model that describes Java)

Source: Internet
Author: User
Tags connection pooling

EJB is the abbreviation for Enterprise Java beans, and a bean plays the role of application footage. It contains a functional interface, a life-cycle interface, and a category that implements the business methods it supports.Foreign namesEnterprise Java BeanAbbreviationsBeandefinitionSoftware component model that describes JavatypeRole of application footagePurposePackaging software code that can be reusedApplication ScopeParts applied to the server1 definition JavaBean is a software component model that describes Java, a bit similar to Microsoft's COM component concepts. In the Java model, JavaBean can extend the functionality of Java programs infinitely, and the combination of JavaBean can quickly generate new applications. For programmers, the best thing is that JavaBean can implement code reuse, but also for the ease of maintenance of the program, and so has a great significance. For example, a shopping cart program, to achieve a shopping cart to add a product such a function, you can write a shopping cart operation of the JavaBean, the establishment of a public AddItem member method, the foreground JSP file directly call this method to achieve. If you later consider adding goods when you need to determine whether the inventory of goods, no goods can not be purchased, at this time we could directly modify the JavaBean AddItem method, add processing statements to achieve, so that the front-end JSP does not have to modify the program. A simple Javabean firstjavabean.javaimportjava.io.*; public class Firstjavabean {private String Firstproperty = new String ("");p ublic Firstjavabean () {}public String getfirstproperty () {return firstproperty;} public void Setfirstproperty (String value) {firstproperty = value;} public static void Main (string[] args) {System.out.println ("My first javabean!");}} If you run this program, the following results will appear: My first javabean! This is a typical representative of the JavaBean, simply explaining that Firstproperty is one of the properties, the external through the get/ The set method can operate on this property, and if you write a VB class, you will be familiar with this. The main method is to test the program, write JavaBean can not be added to the JSP program call, and directly with the main method to debug, debugging can be in the JSP program after the call.  2 Overview Users can use JavaBean to package functionality, processing, values, database access, and any other objects that can be created with Java code, and other developers can go through internal JSP pages, Servlets, other JavaBean, Applets or applications to use these objects. Users can assume that JavaBean provides a way to copy and paste anytime, anywhere, without worrying about any changes.3 Development Initially, JavaBean was designed to package standards for reusable software code. Specifically used to help manufacturers develop Java software components for use in a comprehensive development environment (IDE). These include, for example, a grid control where users can drag and drop the part into the development environment. From then on, JavaBean can be extended to a standard part of a Java Web application, and the JavaBean part framework has been extended to the enterprise version of the Bean (EJB).4 Requirements JavaBean is a Java class that belongs to some specific decoding guidelines and extends the adaptability and scope to allow users to access internal properties and methods. With these, the JavaBean class can be used for the following methods: 1. In the IDE, JavaBean's functionality allows the app developer to browse through the methods, even if JavaBean is compiled and cannot take advantage of the original source files. 2. This feature does not sound exciting in the distributed style of Remote Method invocation (RMI), but it will change after future inclusion of the Enterprise edition of JavaBean. 3. In order to javabean the property value and state can be saved to disk.5 precautions In practical applications, it is very useful to extend the design of JavaBean before performing objects or processing. It is generally assumed that if information is provided, Web developers will function to meet the user's needs for JavaBean. For example, when sensitive data is displayed in HTML, the user can block entries such as passwords, phone numbers, and so on. The JavaBean of good planning and design is trustworthy. Null in Java differs from NULL in SQL to see such a test program: public class Nulltest{public static void Main (string[] args) {int i = 0;//int i = Nu ll;//not a valid initializationstring str = NULL; String strzerooutvalue = ""; StringBuffer sb = new StringBuffer ("null test:string initialized as NULL ="); Sb.append (str); Sb.append ("\ n String Represe Nting a Zero out Value: "); Sb.append (Strzerooutvalue); System.out.println (Sb.tostring ());}} This program will produce the following result: null test:string initialized as NULL = NullString representing a Zero out Value: In JavaBean, we declare the I variable as an int , we must deal with the value associated with the variable, because I default no value, the int type cannot be initialized to NULL, and if the int value is not explicitly initialized, the compiler will prompt for an error. Executing the Nulltest program will verify that the empty string in the text is an alternative to null values that are used to display SQL insertions and updates. If we need to delete some information, we need to send the database a string of length 0 by deleting the text in the form area. Although most databases operate with empty strings as null values, if we use a database that does not support the processing of empty strings, we must write additional Java code to create our own SQL Insert declarations. For example: if (test.length==0) {sb.append ("null");} Else{sb.append (test);}  6 Range Range of JavaBean. Scope is a variable with a life time. The JavaBean range is represented on the right side of the <jsp:usebean scope= "....> flag. will produce a quick reference for JavaBean. Description: The JSP server engine will peel <jsp .... Mark. and the actual code cannot be displayed on the end user's browser. There are four types of scopes: page, request, conversation, app. Dialogue Scope:The JavaBean of the conversation scope is primarily applied across multiple pages and time periods: for example, populating user information. Add information and accept feedback to save the user's track of executing the page. The conversation scope JavaBean retains some information related to the user's conversation ID. This information is from a temporary conversation cookie and is removed from the client and server when the user closes the browser. page/Request scope:Page and request scope JavaBean are sometimes similar to forms of beans, because most of them are used to process forms. The form takes a long time to process the user's input, usually for the page to accept Http/post or get requests. Additional pages and request-scoped beans can be used to reduce the load on a large site server, and if you use a dialog bean, the delayed processing can consume a lot of resources. Application:Application scopes are typically applied to parts of the server, such as JDBC connection pooling, app monitoring, advocacy counts, and other classes that participate in user behavior. Restricting the generation of HTML in the bean: Theoretically, JavaBean will not produce any HTML because it is the work of the JSP layer, however, it is useful to provide some pre-prepared format for dynamic messages. The resulting HTML will be returned by the callout's JavaBean method. Here are some very important things: 1. Do not attempt to place any font dimensions in the HTML returned by JavaBean. Not all browsers are the same. Many browsers cannot handle the full font size. 2. Do not attempt to place any script or DHTML in the HTML returned by JavaBean. outputting the script directly to the page or DHTML is equivalent to self-destruct, because some browser versions crash when processing an incorrect script (very few, but there are). If the user's JavaBean is dynamically rolled out in a complex HTML language at run time, the user will fall into a debugging nightmare. In addition, complex HTML will limit the lifetime and flexibility of JavaBean. 3. Do not provide any options. If a user uses a different system browse page, you can provide a way to replace it.7 Differences Java beans are reusable components, and there is no strict specification for Java beans, and in theory, any Java class can be a Bean. In general, however, because Java beans are created by containers (such as Tomcat), Java beans should have a parameterless constructor, and in addition, Java beans typically implement the serializable interface to implement Bean persistence. Java beans are actually equivalent to the local in-process COM component in the Microsoft COM model, which cannot be accessed across processes. Enterprise Java beans are equivalent to DCOM, which is distributed components. It is a Java-based remote method invocation (RMI) technology, so EJBS can be accessed remotely (across processes, across computers). However, EJBS must be deployed in containers such as WebSphere, WebLogic, and EJB clients never directly access real EJB components, but are accessed through their containers. The EJB container is the proxy for the EJB component, and the EJB component is created and managed by the container. The customer accesses the real EJB component through the container.

Bean (software component model that describes Java)

Related Article

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.