Java Framework Java Bean

Source: Internet
Author: User
Tags call back message queue

Links https://www.zhihu.com/question/19773379 Summary

Java classes that conform to a certain specification are not a technique, but a specification. For this specification, we summarize a lot of development techniques, tool functions.

1. All properties are private
2. Provide default construction method
3. Provide getter and setter
4. Implement Serializable interface

In the year of java1996 release, December that was released the Java bean1.00-a, what is the use of it? The value of the object (Get,set method) can be set by a uniform specification, which is the original Java bean;

    • In the actual enterprise development, need to realize the transaction, the security, the distributed, the JavaBean is not good to use. Sun began to heap functions, where Java beans are complex ejb;
    • The EJB is powerful, but it's too heavy. There is a Di (dependency injection), AOP (aspect-oriented) technology, through the simple Java bean can also complete the EJB thing, where the Java bean is simplified to pojo;
    • Spring was born.
    • PO (Persistence object): Used for persistence (for example, saving to a database or cache);
    • VO (Value object): Used for front-end display use (e.g. in JSP parsing or passing data to the front end)
    • DTO (data Transfer object): Used for interfaces to call back, data transfer (for example, many interface call return value or message queue content);


The main distinction is three: Javabean,ejb,pojo.
JavaBean
JavaBean is a public Java class, but for editing tool recognition, at least three conditions need to be met:
    1. There is a public default constructor (for example, no parameter constructor)
    2. The Get,set property is accessed using the public's method, which means it is set to private, and the Get,set method and the property name need to be the same size. For example, the attribute Name,get method will be written, public String getName () {},n uppercase.
    3. Serialization is required. This is the framework, tools cross-platform to reflect the state must be

EJB
In enterprise development, the need for scalable performance and transaction, security mechanism, so as to ensure the smooth development of enterprise systems, rather than the development of a scale to replace a set of software systems. Then there was an increase in protocol requirements, and there was a Enterprise Bean.
EJB has made some demands on the basis of JavaBean, which is of course more complicated.
POJO
There is a call Josh Mackenzie people think, EJB is too complex, there is no need to use every time, so invented a pojo,pojo is ordinary javabean, what is ordinary, and EJB corresponding.
In short, the difference is that you first determine whether to meet the conditions of JavaBean, and then if the implementation of some requirements, the EJB is satisfied with the condition of the EJB, otherwise it is pojo.


The Java language lacks attributes, events, and multiple inheritance capabilities. So, if you want to implement some of the common requirements of object-oriented programming in Java programs, you can only write a lot of glue code. Java beans are the idiomatic pattern or convention for writing this set of glue code. These conventions include GetXXX, Setxxx, Isxxx, Addxxxlistener, Xxxevent, and so on. Classes that follow these conventions can be used in several tools or libraries.

The purpose of Java bean design

1. Compact and easy to create and use

2. Complete portability

3. Inherit the powerful features of Java

4. Development tools Support

5. Distributed computing Support

Java beans are defined as "a reusable, platform-independent software component that is visualized in a development tool"

Features of Java beans

1, support self-test: The constructor can analyze how the bean works;

2, Support customization: The user uses the constructor tool to customize the appearance and behavior of the bean;

3, Support event Processing: The bean can communicate with the outside;

4, support attributes: The bean can have the content of the state, easy to customize and application development;

5. Support Persistence: Beans can be customized in the Application Builder tool and stored in custom state for easy use.


Java java Bean (top)original 2016-05-27 Liu Xin yard Farm roll overIntroduction: Recently saw the bean configuration of spring, suddenly thought that many people may not necessarily know the context of the thing called Bean, so write an article to say.
In addition, the last time out of the open source China plagiarism incident, in order to prevent the reprint after my public information was deliberately deleted, I added some Liu Xin in the content of the article (Public number: yards Nong turn over) such words, may cause some annoyance, please forgive me. The Java Empire, which I created in a very short time, was hit hard, and the troops I sent to occupy desktop development were almost wiped out.
Intelligence that Microsoft's visual Basic and Borland Delphi recently in the propaganda of what component development, is this thing brought us down?
Liu Xin (public number: yards Nong) Note: see "Java: The Birth of an Empire" and "Basic: A Veteran's readme"

I hurried to buy a visual Basic came over to study, and sure enough, this guy is really handy, and what amazes me most is that it has a visual editor!
I just need to drag a component (such as a button) onto a form, set the property (color, font), add an event (onclick), and finally write the code in the onclick!
Not only that, but I can also put my code in accordance with the specification as a component, published to let others use.
I looked at my men bought me the "Programmer's Base" CD, which actually contains a good thousands of such components, there are database browsing components, timer components, color selection components, and even the components to send and receive mail ...
Gosh, it's not too easy to develop desktop programs later!
No wonder my Java is being beaten up everywhere!
Liu Xin (public number: yards Nong) Note: Programmers and students in the late 90 were expected to know "the programmer's Stronghold", produced by Csdn's founder Jiang Tao.
I hastened to call my Gan small size elder brother: Small yards ah, you hurriedly look at this visual Basic and Delphi, give you 7 days, we Java also have to hurry up a set of such things out.
Is it small? In three days, I got one thing out of my mind: Java Bean API specification.
I opened a look, wow, up to 114 pages, and asked him: "What is this?" What about the visual editor I want for Visual Java? ”
Liu Xin (public number: yards Nong) Note: I downloaded the Java Bean specification, which is really 114 pages
He said: "Boss, we are an open-source community, we have to make full use of everyone's power, so I did not do things like VB and Delphi, instead, I define a set of specifications, as long as you follow this specification, who can use Java to make visual development tools like VB." ”
"What exactly is the specification of this Java bean?" he said. "I asked.
"First, a Java bean is actually a generic Java class, but we have some requirements for this class:
1. This class needs to be public, then a parameterless constructor is required
2. The properties of this class should be private, accessed by Setxxx () and GetXXX ()
3. This class needs to be able to support "events" such as Addxxxxlistener (Xxxevent e), events can be click events, keyboard events, and so on, but we also support custom events.
4. We have to provide a so-called introspection/reflection mechanism that allows you to view various information about Java beans at runtime "
5. This class should be serializable, that is, the state of the bean can be saved on the hard disk so that it recovers later.

"These requirements don't seem to be much, is it a common Java class for programmers?" How do you use it? ”
"Let's imagine that our Java Bean is a big line, and a user is using a visual development tool such as visual Java Builder, and when he uses this tool to create an application, he can select a component called JButton and add it to a form, visu Al Java Builder needs to have this JButton class reflected to new, so it needs an parameterless constructor. ”
"If the user wants to set this JButton property, Visual Java Builder needs to first use introspection/reflection to get the properties of this JButton (through Getter/setter), and to give the user A Property List, such as background color, font, and so on. You can set the background color and font after the user sees it, and visual Java Builder needs to call the Bean's Setbackgroundcorlor ()/setfont () method internally, which is called the Setxxxx () method. ”
"If the user wants to program this JButton, Visual Java Builder is still using introspection/reflection to get the events of this JButton, showing the user A List of events, for example, click, keyboardpressed user can choose one, then can write program to this event programming. ”
"But what is the use of that serialization?" ”
"This is because after the user design is finished, may turn off the visual Java Builder Ah, if not through serialization to save the design of the JButton, the next time you open visual Java Builder, you can have nothing."
I think about it, small brother design is good, just a simple specification to meet all the requirements of the visual editor.

"Then we will publish this code, let us make a visual editor, give others a role model, name I have to think about, called Netbeanit. "
Liu Xin (public number: yards Nong) Note: This is what I invented, actually netbean the name may not actually be associated with the Java bean.

As expected, Java beans released after the strong driving the Java IDE Market, the development of Delphi Borland company also to plug a foot, made a jbuilder, rage.
IBM made a visual age for Java, and later turned into an open platform called Eclipse, super Popular, it turned to our Netbean and JBuilder to force the fast.
Although we have a good time, but the programmer does not buy, Java in the desktop development market is still not good, the use of Java beans to create desktop programs less programmers, only some of the financial, ERP and other territories are still stuck.
It seems that there is no medicine to save.
But where do java beans go? Throw away too pity, I and small size elder brother discussed, we think: Since we Java in the rule of the server-side programming, or there to think of ways to do it ... Java java bean (bottom)original 2016-05-29 Liu Xin yard Farm roll overThe previous specification of Java beans, though well-defined, was not expected to be successful, especially in the desktop development component market that the Java Empire expected.
My little brother and I look forward to CSDN can also be a "programmer's stronghold", which contains thousands of Java bean components ah.
Don't fantasize, it's a matter of applying Java beans to the server side.JSP + Java BeanSmall code elder brother suggested first to use on the JSP to try, can use Java bean to encapsulate business logic, save data to database, like this: (Public number "farm turn over" Note: This is actually called JSP Model 1)
Where JSP is directly used to accept the user's request, and then through the Java bean Processing business, the specific use is: <jsp:usebean id= "user" scope= "page" class= "Com.coderising.User"/ ><jsp:setproperty property= "UserName" name= "user" param= "userName"/><jsp:setproperty property= " Password "name=" user "param=" password "/>
This allows all parameters in the HTTP request to be set to the properties of the user's Java bean.
If you want to be lazy, you can also:
<jsp:setproperty name= "User" property= "*"/>
Of course, make sure that the parameter names in the HTTP request are the same as the property names in the Java bean.
This model, known as JSP Model 1, is popular with many Java programmers because they are very small in size and use model 1 to make development fast.
In fact, this approach is almost the same as the Microsoft Empire's ASP, as well as the open source PHP.
But soon someone came to me complaining that their project using Model 1 led to a crash of the entire system.
He said, "You know what?" There are thousands of JSP in our system, these JSPs call each other (through Get/post), to the last call relationship no one can understand. ”
In fact, we have expected, small brother to have an image of the metaphor: spaghetti these thousands of JSP like this bowl of noodles, stirred together, it is not clear.
In order to solve this problem, small code brother has launched: JSP Model 2, this is a model really embodies the idea of Model-view-controller: Servlet as controller, JSP as a View Java bean is of course m It's Odel!
The business logic, the page display, and the processing process have done a good separation.
Based on the expansion and improvement of this model, many web development frameworks have sprung up, the most famous of which is struts, SPRINGMVC.
Java Web development is booming.
Once again, we realize the benefits of openness!



Java Framework Java Bean

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.