search
HomeJavaJavaInterview questionsJava reflection common interview questions

Java reflection common interview questions

What is reflection?

Reflection mainly refers to the ability of a program to access, detect and modify its own state or behavior

Java reflection:                                                  (Recommended study : java common interview questions)

In the Java runtime environment, for any class, can you know what properties and methods this class has?

For any object, can any of its methods be called?

The Java reflection mechanism mainly provides the following functions:

In Determine the class to which any object belongs at runtime.

Construct an object of any class at runtime.

Judge the member variables and methods of any class at runtime.

Call the method of any object at runtime.

What is java serialization? When is serialization required?

Simply put, it is to save the status of various objects in memory (that is, instance variables, not methods), and to read out the saved object status.

Although you can use your own various methods to save object states, Java provides you with a mechanism that should be better than your own to save object states, and that is serialization.

Under what circumstances is serialization required:

a) When you want to save the object state in memory to a file or database;

b) When you want to use sockets to transfer objects over the network;

c) When you want to transfer objects through RMI;

Dynamic proxy is What? What are the applications?

Dynamic proxy:

When you want to add some additional processing to the methods in the class that implements a certain interface.

For example, add logs, add transactions, etc. You can create a proxy for this class, so the name implies that you create a new class. This class not only contains the functions of the original class methods, but also adds new classes for additional processing on the original basis.

This proxy class is not defined but is dynamically generated. It has decoupling significance, flexibility and strong scalability.

Application of dynamic agent:

Spring’s AOP

Add transaction

Add permissions

Add log

How to implement dynamic proxy?

First you must define an interface, and there must also be an InvocationHandler (pass the object of the class that implements the interface to it) processing class.

There is another tool class Proxy (it is customary to call it a proxy class, because calling its newInstance() can generate a proxy object, but in fact it is just a tool class that generates proxy objects).

Use InvocationHandler to splice the proxy class source code, compile it to generate the binary code of the proxy class, load it using the loader, instantiate it to generate the proxy object, and finally return.

For more Java related technologies, please visit the java video tutorial column to learn!

The above is the detailed content of Java reflection common interview questions. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment