2019-06-05 Java reflective learning diary

Overview timing of load and load class:

A: Overview

When you want to use a class if the class has not yet been loaded into memory, the system by loading, connect, initialize three steps to achieve this class is initialized

load

  The class file is read into memory, and whom to create a Class object. Any class that will be used by the system to create a class object

connection

  Verify that the correct internal structure, and coordinated with other classes

  Responsible for the preparation of a static class members to allocate memory and set the default initialization value

  Parsing the binary data class is replaced symbolic references direct reference

initialization

  It is the initialization step

B: Load opportunity

Create an instance of the class

Access class static variable or static variable assignment

Static method call class

Using reflection to create a way to force the class or interface objects corresponding java.lang.class

Initiating a subclass of class

Direct use java.exe command to run a master class

Class loader and an overview of the classification:

A: Overview

Responsible for loading .class file into memory for, and generate the corresponding class object.

B: Classification

Bootstap ClassLoader root class loader

Extension ClassLoader extension classloader

System ClassLoader system class loader

C: Role

Bootstap ClassLoader root class loader

  Also known as the bootstrap class loader is responsible for loading java core classes

  Such as System, String. In rt.jar file under the JDK jre lib directory

Extension ClassLoader extension classloader

  JRE extensions directory is responsible for loading the jar package

  In the JDK jre lib directory under ext directory

System ClassLoader system class loader

  Responsible for loading class files from the java command, and classpath environment variable specified jar package and class path when JVM startup

Reflection Overview:

A: Overview

JAVA reflection really operating state, for any class, are made known to all properties and methods of this class

For any object, you can call any of its methods and properties

Reflection function of this approach and the dynamic invocation object information acquired dynamically called java language

To Anatomy of a class, you must first get to the bytecode file object class

The class's method is used in anatomy, so first acquired each object class bytecode files corresponding to the type of

B: three ways

a: getClass Object class () method, it is determined whether the two objects are the same bytecode files

b: static property class. Lock objects

c: forName class class static method (), reads the configuration file

class.forName () reads the configuration file example:

Juicer

Obtaining parameters configured by a reflection method using:

Constructor

Obtain and use the member variables by reflection:

Field

By using the method for obtaining and reflecting:

Method

By reflection across the generic inspection:

Write a generic set of an object by reflecting a property value specified:

Exercise:

Dynamic Agent overview and implementation:

A: Overview

Agent: things could have been done yourself, others do, was asked who is the proxy object

Dynamic Agent: generating the object program is running, dynamic proxies in fact be generated by reflecting a proxy

Overview template design patterns and use:

A: Overview

Template Method is to define the skeleton of an algorithm, the algorithm will be specific to subclasses to achieve a delay

B: advantages and disadvantages

a: the advantages

Template Method pattern, the definition of the algorithm in the skeleton at the same time, can be very flexible to achieve specific algorithm to meet user demand for flexible

b: shortcomings

If the algorithm has to modify the skeleton, then you need to modify the abstract class

JDK5 new features (own implementation enumerated classes):

A: Overview

Refers to the value of the variable to be listed, the value of the variable is limited within a range of values ​​enumerated.

B: Recall singleton design pattern: singleton instance of a class has only one

Example much class is a class has multiple instances, but not an infinite number of examples, but the limited number of examples. This order is an enumeration class

C:Demo

Achieved by enumeration class enum:

Note enumeration:

Enumeration class that defines use keyword enum

All of the enumeration classes are subclasses of Enum

On the first line enumeration class must enumeration, enumeration semicolon after the last entry can be omitted, but if there are other things enumeration class, the semicolon can not be omitted. Best not to omit

Enum class can have a constructor, but it must be private, and it's the default is private

Enum class can have abstract methods, but enumeration must override this method

A common method of enumeration class:

JDK7 of six new features:

A: binary literals

B: numeric literals can be underlined

C: switch statement can use the string

D: Generic simplified, generic diamond

E: abnormal multiple catch merger, each with abnormal or |

F: try-with-resources statement

JDK8 new features:

Interface may be defined with a body methods, if modified non-static, default must

If you do not have to be static

 

 

Guess you like

Origin www.cnblogs.com/clqbolg/p/10989810.html