search
HomeJavaJavaInterview questions2020 New Java Interview Questions-Reflection

2020 New Java Interview Questions-Reflection

Jun 12, 2020 pm 04:26 PM
javareflectionInterview questions

2020 New Java Interview Questions-Reflection

1. What is reflection?

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

Java reflection:

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?

(Recommended related video tutorials: java video tutorial)

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.

  • Determine the member variables and methods of any class at runtime.

  • Call the method of any object at runtime.

#2. 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.

(recommended related tutorials: Getting Started with Java)

Under what circumstances is serialization required:

  • When you want to When the object state in memory is saved to a file or database;

  • When you want to use sockets to transmit objects over the network;

  • When you want to transfer objects through RMI;

3. What is a dynamic proxy? 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 a new class with 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 proxy:

  • Spring’s AOP

  • Add transaction

  • Add permissions

  • Add log

4. 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. In fact, it is just a tool class that generates proxy objects). Use InvocationHandler to splice the source code of the proxy class, 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.

Recommended interview questions: java interview questions

The above is the detailed content of 2020 New Java Interview Questions-Reflection. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:csdn. If there is any infringement, please contact admin@php.cn delete

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)