Corejava notes of JavaBean, static methods and final

Source: Internet
Author: User

Remember two words:

1. The property is statically bound to the variable type;

2. Method is dynamic binding, determined by the method of the final object

===============================

About JavaBean:

1, is not the grammatical rule, is the habitual programming norm, uses this standard to write the class to use conveniently;

2. Specification:

A, must have a package;

b, is a Java class, with no parameter constructor;

C, the bean properties that are useful for getxxx () and setxxx () declarations.

For example, the Bean property declared by GetName () and SetName (String N) is: name, regardless of whether there is an instance variable name.

The Get method of the Boolean type can take two forms: Getmarried () or ismarried ()

D. The serialization interface must be implemented (learn specifically when learning IO)

E, the classes provided by the JDK are almost compliant with the JavaBean specification, such as String

3, JavaBean the biggest advantage: "Easy to use"

===============================

Instance variables: Object properties, each object is different, such as: width of the rectangle

static modifier (keyword) that is used to modify the members of a class.

1, static modified member variable, is a class-level variable, is allocated during the load of the class, all classes and instances of the class share a variable, equivalent to a global variable. Static properties are generally accessed using the class name, koo.x = 3;

2, the static method. is a method that belongs to a class and can be accessed through the class name. Is the public tool method of the whole class. Static methods are independent of the instance of the class.

Note: Static methods do not have the bearing "this", or static methods that access static members .

3, static code block, is the code block that runs during class load, because the class is loaded only once, so the static code block executes only once! Usage is not very common and is typically used to initialize some static resources after a class is loaded, such as loading a configuration file.

4. Static inner class (see later internal class notes)

===========================

1. The final modified class can no longer be inherited

Java's string is the final class and cannot be inherited!

In practical development, the final class is not allowed in principle!

2, final modification of the way, can no longer be overwritten

3, final modified variables, initialization is not allowed after the modification of the

Final local variable, method parameter, member variable

4, Final Static--Java uses the final static modified variable as a constant, generally requires that the constant name has uppercase letters

Corejava notes of JavaBean, static methods and final

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.