Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the advanced interview questions for JAVA?

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "what are the advanced interview questions for JAVA". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what are the advanced JAVA interview questions"?

1.Sun HotSpot VM, a virtual machine included in JDK and Open JDK, is also the most widely used Java virtual machine at present.

2.JVM memory distribution

Program counter: a small piece of memory space that can be seen as a line number indicator of the bytecode executed by the current thread. The basic functions in the program, such as branch, loop, jump, exception handling, thread recovery and so on, all rely on this counter. Because multithreading is realized by thread switching in turn and allocating processor execution time, this area is the thread's private memory.

Virtual machine stack: describes the memory model executed by the Java method, which is used to store local variables, Operand stacks, dynamic links, method exits, etc.

Heap: the largest piece of memory managed by the Java virtual machine. The Java heap is a memory area shared by all threads, which is created and stored when the virtual machine starts, and is also the main part managed by the garbage collector.

Method area: used to store class information, constants, static variables, immediately compiled code and other data that have been loaded by the virtual machine. HotSVM also performs GC for this area, mainly constant recovery and classes

3.JVM memory allocation Policy

Object memory allocation, in general, is allocated on the Java heap.

In most cases, objects are allocated in the new generation Eden zone, and when there is not enough space to allocate in the Eden zone, the virtual machine will initiate a Minor GC.

In most cases, large objects directly enter the old age, the virtual machine provides parameters to define the threshold of large objects, and objects that exceed the threshold will directly enter the old age.

Objects that are still alive after many times of Minor GC (long-lived objects) will enter the old age. The virtual machine provides parameters and you can set the threshold.

4.JVM garbage collection algorithm

Mark-clear algorithm: first mark out all the objects that need to be recycled, and then uniformly recycle all the marked objects after the marking is completed.

Replication algorithm: divide the available memory into two equal blocks according to capacity, and use only one of them at a time. When one piece of memory is used up, it will be saved on top of another, and then the used memory space will be cleared at once.

Tag-collation algorithm: the marking process is the same as the "mark-clear" algorithm, but the next step is not to clean up the recyclable objects directly, but to let one end move, and then directly clean up the memory outside the end boundary.

Generation collection algorithm: generally, the Java heap is divided into the new generation and the old age, and the most appropriate collection algorithm is adopted according to the characteristics of each age. The new generation found that a large number of objects died and chose the replication algorithm. In the old days, because of the high survival rate of objects, it was necessary to use the "mark-clean" or "mark-organize" algorithm for recycling.

5. Garbage collector

Serial collector: a single-threaded collector that uses only one CPU or one collection thread to complete garbage collection. During garbage collection, all other worker threads must be paused until its collection is complete.

ParNew collector: a multithreaded version of the Serial collector that behaves exactly like the Serial collector except for garbage collection using multiple threads.

CMS collector: a collector that aims to obtain the shortest recovery pause time. The process is divided into four steps:

Initial mark

Concurrent tagging

Relabel

Concurrent cleanup

Common startup parameters of 6.JVM

-Xms /-Xmx-initial size of heap / maximum size of heap

-Xmn-the size of the younger generation in the heap

-XX:-DisableExplicitGC-make System.gc () have no effect

-XX:+PrintGCDetails-print details of the GC

-XX:+PrintGCDateStamps-print the timestamp of the GC operation

-XX:NewSize / XX:MaxNewSize-set Cenozoic size / Cenozoic maximum size

-XX:NewRatio-you can set the ratio of the old generation to the new generation

-XX:PrintTenuringDistribution-sets the age distribution of objects in Survivor Paradise after each new generation of GC

-XX:InitialTenuringThreshold /-XX:MaxTenuringThreshold: sets the initial and maximum values of the old age threshold

-XX:TargetSurvivorRatio: sets the target utilization of the survival area

7.JAVA class lifecycle

The whole life cycle of the Java class includes seven stages: loading, verification, preparation, parsing, initialization, use, and unloading from the moment it is loaded into the virtual machine memory and unloaded.

8.JVM class loading

Bootstrap class loader: a class loader implemented in native code that is responsible for loading class libraries under / lib into memory (such as rt.jar). Because the bootstrap classloader involves the local implementation details of the virtual machine, the developer cannot directly get the reference of the boot classloader, so it is not allowed to operate directly through the reference.

Standard extension (Extension) class loader: class libraries in the location specified by Sun's ExtClassLoader (sun.misc.Launcher$ExtClassLoader) implementation Java_Runtime_Home > / lib/extjava.ext.dir are loaded into memory. Developers can use the standard extension class loader directly.

System (System) class loader: implemented by Sun's AppClassLoader (sun.misc.Launcher$AppClassLoader). The class library specified in CLASSPATH is loaded into memory. Developers can directly use system classes to add

Description of parent delegation mechanism: when a specific class loader receives a request to load a class, it first delegates the loading task to the parent class loader, recursively, and returns successfully if the parent class loader can complete the class loading task; only when the parent class loader cannot complete this loading task, it loads it itself.

9.JVM tuning

View heap space allocation (younger generation, older generation, persistent generation allocation)

Garbage collection monitoring (monitoring recycling for a long time)

Thread information monitoring: number of system threads

Thread status monitoring: what state each thread is in

Thread details: view the internal operation of the thread, deadlock check

CPU hotspots: check which methods of the system take up a lot of CPU time

Memory hotspots: check which objects have the largest number in the system

At this point, I believe you have a deeper understanding of "what are the advanced JAVA interview questions?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow 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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report