The relationship between JavaBean and Java class

Source: Internet
Author: User
Tags definition html tags reflection

To say beans, you have to mention introspection and reflection, and "dynamic".

Generally speaking, the developer community speaks of dynamic languages, with a broadly agreed definition of: "When a program runs, it allows you to change the program structure or variable type, which is called a dynamic language." From this point of view, Perl,python,ruby is a dynamic language, c++,java,c# is not a dynamic language.

Although Java is not a dynamic language in this definition and classification, it has a very prominent dynamic correlation mechanism (in fact C + + is also such a dynamic mechanism): Reflection. The meaning of this word is "reflection, image, reflection," which is used in Java to refer to the classes that we can load, detect, and use during compilation. In other words, a Java program can load a class that knows its name at run time, learns its full structure (but does not include methods definitions), generates its object entity, or sets a value on its fields, or evokes its methods. This ability to "See Through Class" (the ability of the program to examine itself) is called introspection (introspective, internal, introspective). Reflection and introspection are two terms that are often mentioned. Classes in Java have this feature (you can look at the class in Java, if you have time).

And JavaBean, first of all, is a class of Java, and then has the characteristics of the bean. In short, it is a class that conforms to certain specifications (getter and setter names are consistent with variable names). Such a class can automatically get the value of a property through the Java reflexion mechanism. Common is some method of naming GetXXX (), setxxx (), some event receiver registration to comply with certain specifications.

Because JavaBean is also a class of Java, JavaBean also has the properties of introspection and reflection. The former introspection is the get and set method of the class, that is, the method of setting and obtaining its own property value. The latter reflection is the ability of the Java program to check its own contained objects in run, that is, to get the name of the object's properties and methods after the object is loaded, and to obtain a value by invoking the former. Another is that the name of the Bean's Methode and interface is characteristic of design pattern (this is also negligible.) )

The purpose of the bean is to be modular, as is the case with other programming languages such as Delphi, but it gives some specifications, and if you do, you can use the same mechanism to invoke different controls. Just to make it more convenient and reusable, it's not specifically for Web service. In contrast, a GUI class bean is more like a generic conceptual component. In addition, the bean's class has many specifications and limitations than normal class, so their implementation mechanism is different.

In other words, JavaBeans is actually a common Java code fragment, but is to consider the reuse of the code into some "modular" Java program code, and based on a certain pattern of production.

There is no difference between the JavaBean in nature and the general class. But there are some differences in thought and use. For example, JavaBean uses methods such as SETXXX (), getxxx (), and so on to manipulate the data in the bean, so that when web application development, the page designer can manipulate the data directly through HTML tags without having to deal with Java code. The purpose of the bean design is to isolate the page designer from the program developer. As for reusability, I feel that there is little difference between the ordinary classes.

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.