1. What is the use of serialization? Why use serialization? I answered according to most of China's blog, it seems that they do not agree.
Serialization is a mechanism for dealing with the flow of objects, so-called object flow is the flow of the object's contents.
It is possible to read and write to a Fluidized object, or to transfer the streamed object between the networks.
Serialization is a problem that is raised when reading and writing to an object stream.
Serialization implementation: Implements the serializable interface for a class that needs to be serialized, which does not have a method to implement,
Implements serializable just to mark that the object is serializable,
A ObjectOutputStream (object flow) object is then constructed using an output stream (for example: FileOutputStream).
Then, using the WriteObject (Object obj) method of the ObjectOutputStream object, you can write out (that is, save its state) the object with the parameter obj, and then use the input stream to recover.
Serialization: Serialization is the process of converting an object into a format that is easy to transfer. For example, you can serialize an object,
the object is then transferred between the client and the server using HTTP over the Internet. At the other end, deserialization reconstructs the object from the stream. is a mechanism for object persistence.
Specifically, the object should be serialized, the general program at run time, the production of objects, these objects as the program stops running and disappears,
But if we want to save some objects (because they are objects, so they have different characteristics), these objects still exist after the program terminates.
You can read the values of these objects while the program is running again, or take advantage of these saved objects in other programs. In this case, the serialization of the object is used.
The most important use of object serialization is to guarantee the integrity and transitivity of objects when passing, and saving objects (object).
For example, when transmitting over a network, or storing an object as a file, the serialization interface is implemented.
2, new A Java object, how the memory is allocated?
object exists in the heap, object references exist in the stack
Register: We can't control it in the program
Stack: A reference to a primitive type of data and objects, but the object itself is not stored in the stack, but is stored in the heap
Heap: Storing data generated with new
Static domain: Static members that are stored in the object with static definitions
Constant pool: Storing constants
Non-RAM storage: Persistent storage space such as hard drives
3. How does the container manage the session?
Reference http://jingyan.baidu.com/article/25648fc1bf0da29191fd0020.html
4. What is the principle of spring AOP? I answer the dynamic agent, he said there is another, do not know what is?
Spring AOP is implemented by relying on the JDK dynamic agent and the Cglib proxy.
In spring, the interface will implement proxy proxy object in the way of JDK, when there is no interface, the Prixy proxy object will be implemented in Cglib.
JDK Dynamic Proxy: Its proxy object must be an implementation of an interface that accomplishes a proxy to the target object by creating an implementation class of an interface during runtime.
Cglib Proxy: The implementation principle is similar to the JDK dynamic proxy, except that the proxy object that it generates during runtime is a subclass of the target class extension.
Cglib is an efficient code generation package that relies on ASM (open source Java bytecode editing class library) to operate bytecode implementations that are more robust than JDK.
1, JDK mode: Personservice for the interface, Personservicebean for the implementation of the class
public class Jdkproxyfactory implements Invocationhandler { private Object targetObject; public Object Createproxyintance (object TargetObject) { this.targetobject=targetobject; Return Proxy.newproxyinstance (This.targetObject.getClass (). getClassLoader (), This.targetObject.getClass (). Getinterfaces (), this); } public object invoke (object proxy, Method method, object[] args) throws Throwable { Personservicebean person= ( Personservicebean) This.targetobject; Object Result=null; if (Person.getuser ()!=null) { result = Method.invoke (TargetObject, args); } return result;}}
2, using Cglib Package implementation: Personservicebean for the implementation of the class, and no Personservice interface
public class Cglibproxyfactory implements methodinterceptor{ private Object targetObject; public Object Createproxyinstance (object TargetObject) { this.targetobject=targetobject; Enhancer enhancer=new Enhancer (); Enhancer.setsuperclass (This.targetObject.getClass ());//sets the subclass of the target class that overrides the non-final method Enhancer.setcallback in all the parent classes ( this);//Set callback return enhancer.create (); } public object Intercept (object proxy, Method method, object[] args, methodproxy methodproxy) throws Throwable {
personservicebean person= (Personservicebean) this.targetobject; Object Result=null; if (Person.getuser ()!=null) { result = Methodproxy.invoke (TargetObject, args); } return null;}}
5. How does the JVM work? Note It's not a workflow, everybody knows.
The principle and characteristics of the JVM is mainly that the operating system is loaded into the JVM through the JDK Java.exe to complete the JVM environment through the following 4 steps.
1. Creating a JVM load environment and configuration
2. Loading JVM.dll
3. Initialize JVM.dll and hang bounds to jnienv (JNI call interface) instance
4. Call the JNIEnv instance to mount and process the class.
Continuous update ...
Java Intermediate question