In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the JavaSE reflection interview questions?" Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let Xiaobian take you to learn "JavaSE reflection interview questions"!
Tell me about your understanding of reflection in Java.
In the running state, for any class, you can get all the properties and methods of this class, and for any object, you can call any of its properties and methods. This kind of information obtained dynamically and the method of calling objects dynamically is Java reflection.
What does reflection do?
Determine the member variables and methods of a class at runtime Determine the class to which any object belongs at runtime Construct an object of a class at runtime Call a method of any object at runtime
The difference between class.forName and classLoader
class.forName:
Load the.class file of the class into jvm
Interpreting classes, executing static blocks in classes
classLoader:
Just do one thing: load the.class file into jvm, nothing in static will be executed, static blocks will only be executed in newInstance.
Class.forName(className): The method called internally is Class.forName(className,true,classloader); the second boolean parameter indicates whether the class needs initialization, which is required by default. Once initialized, the static block code execution of the target object is triggered, and the static parameters are initialized again.
ClassLoader.loadClass(className): The method called internally is ClassLoader.loadClass(className,false); the second boolean parameter indicates whether the target object is linked, false means no linking, no linking means no initialization and other steps, then static blocks and static objects will not be executed
The difference between static and dynamic agents, what scenarios are used?
A static proxy typically proxies only one class, while a dynamic proxy proxies multiple implementation classes under one interface.
A static proxy knows in advance what it is to proxy, while a dynamic proxy doesn't know what it is to proxy, only at runtime.
Dynamic proxy is the invoke method that implements the InvocationHandler interface in JDK, but note that the proxy is the interface, that is, your business class must implement the interface, and get the proxy object through newProxyInstance in Proxy. There is also a dynamic proxy CGLIB, which is a class that does not require the business class to inherit the interface and implements the proxy through derived subclasses. This is achieved by dynamically modifying the bytecode at runtime.
AOP programming is based on dynamic proxy implementation, such as the famous Spring framework, Hibernate framework and so on are examples of the use of dynamic proxy.
What are Java class loaders?
1. Bootstrap--C++, no source code
2. Extension loader--Loading location: jre\lib\ext
3. System (application) class loader (System\App) --Loading location: classpath
4, custom loader (must inherit ClassLoader)
When are classes initialized?
Create an instance of the class, that is, new an object
Access or assign a static variable to a class or interface
Calling static methods of a class
Reflection (Class.forName("com.hcx.load"))
Initialize a subclass of a class (the parent of the subclass is initialized first)
The startup class indicated at JVM startup, i.e. the class with the same file name and class name
Initialize the class:
If the class is not already loaded and linked, load and link it first
If the class has a direct parent and the class has not been initialized (note: classes can only be initialized once in a class loader), initialize the direct parent (does not apply to interfaces)
If there are initialization statements in the added class (such as static variables and static blocks), execute these initialization statements in turn.
What are the ways to get a class object?
Type.class, e.g. String.class
Object.getClass(), e.g."hello".getClass()
Class.forName(), e.g. Class.forName("java.lang.String")
At this point, I believe that we have a deeper understanding of "JavaSE reflection interview questions," may wish to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.