Memory Management in Java Interview Questions (+Answers) – Java中的内存管理面试问题(+答案)

最后修改: 2017年 1月 30日

1. Introduction

1.绪论

In this article, we’ll explore some memory management questions that frequently pop up during Java developer interviews. Memory management is an area that not so many developers are familiar with.

在这篇文章中,我们将探讨一些在Java开发人员面试中经常出现的内存管理问题。内存管理是一个并非很多开发者都熟悉的领域。

In fact, developers don’t generally have to deal with this concept directly – as the JVM takes care of the nitty-gritty details. Unless something is going seriously wrong, even seasoned developers may not have accurate information about memory management at their fingertips.

事实上,开发人员一般不需要直接处理这个概念–因为JVM负责处理这些琐碎的细节。除非发生了严重的错误,否则即使是经验丰富的开发者也不一定能在指尖上获得关于内存管理的准确信息。

On the other hand, these concepts are actually quite prevalent in interviews – so let’s jump right in.

另一方面,这些概念在面试中其实很普遍–所以我们直接跳进去。

2. Questions

2.问题

Q1. What Does the Statement “Memory Is Managed in Java” Mean?

Q1.”内存在Java中被管理 “这一说法是什么意思?

Memory is the key resource an application requires to run effectively and like any resource, it is scarce. As such, its allocation and deallocation to and from applications or different parts of an application require a lot of care and consideration.

内存是一个应用程序有效运行所需的关键资源,像任何资源一样,它是稀缺的。因此,它在应用程序或应用程序的不同部分之间的分配和撤销需要非常谨慎和考虑。

However, in Java, a developer does not need to explicitly allocate and deallocate memory – the JVM and more specifically the Garbage Collector – has the duty of handling memory allocation so that the developer doesn’t have to.

然而,在Java中,开发者不需要明确地分配和删除内存–JVM,更确切地说,垃圾收集器–有责任处理内存分配,这样开发者就不必这样做。

This is contrary to what happens in languages like C where a programmer has direct access to memory and literally references memory cells in his code, creating a lot of room for memory leaks.

这与C语言中发生的情况相反,在C语言中,程序员可以直接访问内存,并在他的代码中直接引用内存单元,为内存泄漏创造了很多空间。

Q2. What Is Garbage Collection and What Are Its Advantages?

Q2.什么是垃圾收集,它有哪些优点?

Garbage collection is the process of looking at heap memory, identifying which objects are in use and which are not, and deleting the unused objects.

垃圾收集是查看堆内存的过程,识别哪些对象正在使用,哪些没有,并删除未使用的对象。

An in-use object, or a referenced object, means that some part of your program still maintains a pointer to that object. An unused object, or unreferenced object, is no longer referenced by any part of your program. So the memory used by an unreferenced object can be reclaimed.

一个使用中的对象,或一个被引用的对象,意味着你的程序的某些部分仍然保持着一个指向该对象的指针。一个未使用的对象,或未引用的对象,不再被你程序的任何部分引用。因此,未引用的对象所使用的内存可以被回收。

The biggest advantage of garbage collection is that it removes the burden of manual memory allocation/deallocation from us so that we can focus on solving the problem at hand.

垃圾收集的最大优点是它消除了我们手动分配/重新分配内存的负担,这样我们就可以专注于解决手头的问题。

Q3. Are There Any Disadvantages of Garbage Collection?

Q3.垃圾收集有什么缺点吗?

Yes. Whenever the garbage collector runs, it has an effect on the application’s performance. This is because all other threads in the application have to be stopped to allow the garbage collector thread to effectively do its work.

是的。每当垃圾收集器运行时,它都会对应用程序的性能产生影响。这是因为应用程序中的所有其他线程都必须停止,以允许垃圾收集器线程有效地完成其工作。

Depending on the requirements of the application, this can be a real problem that is unacceptable by the client. However, this problem can be greatly reduced or even eliminated through skillful optimization and garbage collector tuning and using different GC algorithms.

根据应用程序的要求,这可能是一个真正的问题,是客户无法接受的。然而,通过熟练的优化和垃圾收集器的调整,以及使用不同的GC算法,这个问题可以大大减少甚至消除。

Q4. What Is the Meaning of the Term “Stop-The-World”?

Q4.停止–世界 “一词的含义是什么?

When the garbage collector thread is running, other threads are stopped, meaning the application is stopped momentarily. This is analogous to house cleaning or fumigation where occupants are denied access until the process is complete.

当垃圾收集器线程运行时,其他线程被停止,这意味着应用程序被暂时停止。这类似于房屋清洁或熏蒸,在这个过程完成之前,居住者被拒绝进入。

Depending on the needs of an application, “stop the world” garbage collection can cause an unacceptable freeze. This is why it is important to do garbage collector tuning and JVM optimization so that the freeze encountered is at least acceptable.

根据应用程序的需要,”停止世界 “的垃圾收集可能会导致不可接受的冻结。这就是为什么要进行垃圾收集器的调整和JVM的优化,使遇到的冻结至少是可以接受的。

Q5. What Are Stack and Heap? What Is Stored in Each of These Memory Structures, and How Are They Interrelated?

Q5.什么是堆栈和堆?这些内存结构中分别存储了什么,它们是如何相互关联的?

The stack is a part of memory that contains information about nested method calls down to the current position in the program. It also contains all local variables and references to objects on the heap defined in currently executing methods.

堆栈是内存的一部分,它包含了关于嵌套方法调用的信息,一直到程序中的当前位置。它还包含所有局部变量和对当前执行的方法中定义的堆上的对象的引用。

This structure allows the runtime to return from the method knowing the address whence it was called, and also clear all local variables after exiting the method. Every thread has its own stack.

这个结构允许运行时从方法中返回,知道它被调用时的地址,并且在退出方法后清除所有的局部变量。每个线程都有自己的堆栈。

The heap is a large bulk of memory intended for allocation of objects. When you create an object with the new keyword, it gets allocated on the heap. However, the reference to this object lives on the stack.

堆是一大块用于分配对象的内存。当你用new关键字创建一个对象时,它被分配在堆上。然而,对这个对象的引用却存在于堆栈中。

Q6. What Is Generational Garbage Collection and What Makes It a Popular Garbage Collection Approach?

Q6.什么是代际垃圾收集,是什么让它成为流行的垃圾收集方法?

Generational garbage collection can be loosely defined as the strategy used by the garbage collector where the heap is divided into a number of sections called generations, each of which will hold objects according to their “age” on the heap.

代际垃圾收集可以被松散地定义为垃圾收集器所使用的策略,其中堆被分为若干部分,称为代际,每个部分将根据其在堆上的 “年龄 “来保存对象。

Whenever the garbage collector is running, the first step in the process is called marking. This is where the garbage collector identifies which pieces of memory are in use and which are not. This can be a very time-consuming process if all objects in a system must be scanned.

每当垃圾收集器运行时,该过程的第一步被称为标记。这就是垃圾收集器识别哪些内存正在使用,哪些没有。如果系统中的所有对象都必须被扫描,这可能是一个非常耗时的过程。

As more and more objects are allocated, the list of objects grows and grows leading to longer and longer garbage collection time. However, empirical analysis of applications has shown that most objects are short-lived.

随着越来越多的对象被分配,对象列表不断增长,导致垃圾收集时间越来越长。然而,对应用程序的经验分析表明,大多数对象都是短命的。

With generational garbage collection, objects are grouped according to their “age” in terms of how many garbage collection cycles they have survived. This way, the bulk of the work spread across various minor and major collection cycles.

通过代际垃圾收集,对象根据它们的 “年龄 “被分组,即它们已经存活了多少个垃圾收集周期。这样一来,大部分的工作就分散在各个小的和大的收集周期中。

Today, almost all garbage collectors are generational. This strategy is so popular because, over time, it has proven to be the optimal solution.

今天,几乎所有的垃圾收集器都是生成性的。这种策略之所以如此受欢迎,是因为随着时间的推移,它被证明是最佳的解决方案。

Q7. Describe in Detail How Generational Garbage Collection Works

Q7.请详细描述世代垃圾收集的工作原理

To properly understand how generational garbage collection works, it is important to first remember how Java heap is structured to facilitate generational garbage collection.

为了正确理解生成性垃圾收集的工作原理,首先必须记住Java堆的结构,以方便生成性垃圾收集。

The heap is divided up into smaller spaces or generations. These spaces are Young Generation, Old or Tenured Generation, and Permanent Generation.

堆被划分为更小的空间或世代。这些空间是年轻的一代,老的或有任期的一代,以及永久的一代。

The young generation hosts most of the newly created objects. An empirical study of most applications shows that majority of objects are quickly short lived and therefore, soon become eligible for collection. Therefore, new objects start their journey here and are only “promoted” to the old generation space after they have attained a certain “age”.

年轻一代承载了大部分新创建的对象。对大多数应用的实证研究表明,大多数对象很快就会短命,因此,很快就有资格被收集。因此,新的对象在这里开始它们的旅程,只有在它们达到一定的 “年龄 “后才会被 “提升 “到老一代空间。

The term “age” in generational garbage collection refers to the number of collection cycles the object has survived.

代际垃圾收集中的术语“年龄”指的是对象已经存活的收集周期的数量。

The young generation space is further divided into three spaces: an Eden space and two survivor spaces such as Survivor 1 (s1) and Survivor 2 (s2).

年轻一代的空间被进一步划分为三个空间:一个伊甸园空间和两个幸存者空间,如幸存者1(s1)和幸存者2(s2)。

The old generation hosts objects that have lived in memory longer than a certain “age”. The objects that survived garbage collection from the young generation are promoted to this space. It is generally larger than the young generation. As it is bigger in size, the garbage collection is more expensive and occurs less frequently than in the young generation.

老一代寄存的对象在内存中生存的时间超过了一定的 “年龄”。从年轻一代的垃圾收集中幸存下来的对象被提升到这个空间。它通常比年轻一代的空间大。由于它的大小更大,垃圾收集的成本更高,而且发生的频率比年轻一代要低。

The permanent generation or more commonly called, PermGen, contains metadata required by the JVM to describe the classes and methods used in the application. It also contains the string pool for storing interned strings. It is populated by the JVM at runtime based on classes in use by the application. In addition, platform library classes and methods may be stored here.

永久生成 或更常见的称呼,PermGen,包含JVM所需的元数据,以描述应用程序中使用的类和方法。它还包含用于存储内部字符串的字符串池。它是由JVM在运行时根据应用程序使用的类来填充的。此外,平台库的类和方法也可以存储在这里。

First, any new objects are allocated to the Eden space. Both survivor spaces start out empty. When the Eden space fills up, a minor garbage collection is triggered. Referenced objects are moved to the first survivor space. Unreferenced objects are deleted.

首先,任何新对象都被分配到伊甸园空间。两个生存者空间开始时都是空的。当伊甸园空间填满时,会触发一个小的垃圾回收。被引用的对象被移到第一个幸存者空间。未引用的对象被删除。

During the next minor GC, the same thing happens to the Eden space. Unreferenced objects are deleted and referenced objects are moved to a survivor space. However, in this case, they are moved to the second survivor space (S2).

在下一个小的GC期间,同样的事情发生在Eden空间。未被引用的对象被删除,被引用的对象被移到一个生存者空间。然而,在这种情况下,它们被移到第二个生存者空间(S2)。

In addition, objects from the last minor GC in the first survivor space (S1) have their age incremented and are moved to S2. Once all surviving objects have been moved to S2, both S1 and Eden space are cleared. At this point, S2 contains objects with different ages.

此外,来自第一个幸存者空间(S1)的最后一个小GC的物体,其年龄增加,并被移到S2。一旦所有幸存的对象都被转移到S2,S1和Eden空间都被清空。在这一点上,S2包含有不同年龄的对象。

At the next minor GC, the same process is repeated. However this time the survivor spaces switch. Referenced objects are moved to S1 from both Eden and S2. Surviving objects are aged. Eden and S2 are cleared.

在下一个小GC,同样的过程被重复。然而这一次,生存者的空间发生了变化。被引用的对象从Eden和S2都被移到S1。存活的对象被老化。Eden和S2被清空。

After every minor garbage collection cycle, the age of each object is checked. Those that have reached a certain arbitrary age, for example, 8, are promoted from the young generation to the old or tenured generation. For all subsequent minor GC cycles, objects will continue to be promoted to the old generation space.

在每个小的垃圾收集周期之后,每个对象的年龄都被检查。那些已经达到某个任意年龄的对象,例如,8岁,将从年轻一代晋升到老一代或终身制。对于所有后续的小规模GC周期,对象将继续被提升到老一代空间。

This pretty much exhausts the process of garbage collection in the young generation. Eventually, a major garbage collection will be performed on the old generation which cleans up and compacts that space. For each major GC, there are several minor GCs.

这几乎耗尽了年轻一代的垃圾收集过程。最终,将对老一代进行一次大的垃圾收集,清理并压缩该空间。对于每个主要的GC,都有几个次要的GC。

Q8. When Does an Object Become Eligible for Garbage Collection? Describe How the Gc Collects an Eligible Object?

Q8.一个对象什么时候有资格进行垃圾收集?描述一下Gc如何收集符合条件的对象?

An object becomes eligible for Garbage collection or GC if it is not reachable from any live threads or by any static references.

如果一个对象不能从任何实时线程或任何静态引用中到达,那么它就有资格进行垃圾收集或GC。

The most straightforward case of an object becoming eligible for garbage collection is if all its references are null. Cyclic dependencies without any live external reference are also eligible for GC. So if object A references object B and object B references Object A and they don’t have any other live reference then both Objects A and B will be eligible for Garbage collection.

最直接的情况是,如果一个对象的所有引用都是空的,那么该对象就有资格进行垃圾收集。没有任何活的外部引用的循环依赖关系也有资格进行GC。因此,如果对象A引用对象B,对象B引用对象A,并且它们没有任何其他活的引用,那么对象A和对象B都将有资格进行垃圾收集。

Another obvious case is when a parent object is set to null. When a kitchen object internally references a fridge object and a sink object, and the kitchen object is set to null, both fridge and sink will become eligible for garbage collection alongside their parent, kitchen.

另一个明显的情况是当父对象被设置为null时。当一个厨房对象内部引用了一个冰箱对象和一个水槽对象,而厨房对象被设置为null时,冰箱和水槽都将与它们的父对象–厨房一起成为符合条件的垃圾收集对象。

Q9. How Do You Trigger Garbage Collection from Java Code?

Q9.如何从Java代码中触发垃圾回收?

You, as Java programmer, can not force garbage collection in Java; it will only trigger if JVM thinks it needs a garbage collection based on Java heap size.

作为Java程序员,你不能在Java中强制进行垃圾收集;只有当JVM认为它需要根据Java堆的大小进行垃圾收集时才会触发。

Before removing an object from memory garbage collection thread invokes finalize()method of that object and gives an opportunity to perform any sort of cleanup required. You can also invoke this method of an object code, however, there is no guarantee that garbage collection will occur when you call this method.

在从内存中删除一个对象之前,垃圾收集线程会调用该对象的finalize()方法,并给一个机会来执行任何需要的清理工作。你也可以调用一个对象代码的这个方法,但是,不能保证当你调用这个方法时,垃圾收集会发生。

Additionally, there are methods like System.gc() and Runtime.gc() which is used to send request of Garbage collection to JVM but it’s not guaranteed that garbage collection will happen.

此外,还有一些方法,如System.gc()和Runtime.gc(),用于向JVM发送垃圾收集的请求,但并不保证垃圾收集会发生。

Q10. What Happens When There Is Not Enough Heap Space to Accommodate Storage of New Objects?

Q10。当没有足够的堆空间来适应新对象的存储时,会发生什么?

If there is no memory space for creating a new object in Heap, Java Virtual Machine throws OutOfMemoryError or more specifically java.lang.OutOfMemoryError heap space.

如果在Heap中没有内存空间来创建一个新的对象,Java虚拟机会抛出OutOfMemoryError,或者更具体地说java.lang.OutOfMemoryErrorheap space。

Q11. Is It Possible to «Resurrect» an Object That Became Eligible for Garbage Collection?

Q11.是否有可能 “复活 “一个符合垃圾收集条件的对象?

When an object becomes eligible for garbage collection, the GC has to run the finalize method on it. The finalize method is guaranteed to run only once, thus the GC flags the object as finalized and gives it a rest until the next cycle.

当一个对象有资格进行垃圾回收时,GC必须对其运行finalize方法。finalize方法保证只运行一次,因此GC将该对象标记为最终化,并让它休息到下一个周期。

In the finalize method you can technically “resurrect” an object, for example, by assigning it to a static field. The object would become alive again and non-eligible for garbage collection, so the GC would not collect it during the next cycle.

finalize方法中,你可以在技术上 “复活 “一个对象,例如,通过将其分配给一个static字段。该对象将再次成为活体,并且不符合垃圾收集的条件,所以GC不会在下一个周期收集它。

The object, however, would be marked as finalized, so when it would become eligible again, the finalize method would not be called. In essence, you can turn this “resurrection” trick only once for the lifetime of the object. Beware that this ugly hack should be used only if you really know what you’re doing — however, understanding this trick gives some insight into how the GC works.

然而,该对象将被标记为最终化,所以当它再次变得合格时,最终化方法将不会被调用。从本质上讲,你可以在对象的生命周期内只使用一次这种 “复活 “技巧。请注意,这个丑陋的黑客只有在你真正知道自己在做什么的情况下才可以使用–然而,理解这个技巧可以让我们对GC的工作原理有一些了解。

Q12. Describe Strong, Weak, Soft and Phantom References and Their Role in Garbage Collection.

Q12.描述强引用、弱引用、软引用和幻象引用以及它们在垃圾收集中的作用。

Much as memory is managed in Java, an engineer may need to perform as much optimization as possible to minimize latency and maximize throughput, in critical applications. Much as it is impossible to explicitly control when garbage collection is triggered in the JVM, it is possible to influence how it occurs as regards the objects we have created.

就像Java中的内存管理一样,工程师可能需要尽可能多地进行优化,以便在关键应用中最大限度地减少延迟并最大化吞吐量。就像在JVM中不可能明确控制何时触发垃圾收集一样对于我们所创建的对象,可以影响它的发生。

Java provides us with reference objects to control the relationship between the objects we create and the garbage collector.

Java为我们提供了引用对象来控制我们创建的对象和垃圾收集器之间的关系。

By default, every object we create in a Java program is strongly referenced by a variable:

默认情况下,我们在Java程序中创建的每一个对象都是由一个变量来强引用的。

StringBuilder sb = new StringBuilder();

In the above snippet, the new keyword creates a new StringBuilder object and stores it on the heap. The variable sb then stores a strong reference to this object. What this means for the garbage collector is that the particular StringBuilder object is not eligible for collection at all due to a strong reference held to it by sb. The story only changes when we nullify sb like this:

在上面的片段中,new关键字创建了一个新的StringBuilder对象并将其存储在堆中。然后,变量sb存储了该对象的strong引用。这对垃圾收集器来说意味着这个特定的StringBuilder对象由于sb对它的强引用而根本没有资格被收集。只有当我们像这样使sb无效时,故事才会发生变化。

sb = null;

After calling the above line, the object will then be eligible for collection.

调用上述行后,该对象将有资格被收集。

We can change this relationship between the object and the garbage collector by explicitly wrapping it inside another reference object which is located inside java.lang.ref package.

我们可以改变对象和垃圾收集器之间的关系,通过明确地将其包装在另一个引用对象中,该引用对象位于java.lang.ref包中。

A soft reference can be created to the above object like this:

可以像这样为上述对象创建一个软引用

StringBuilder sb = new StringBuilder();
SoftReference<StringBuilder> sbRef = new SoftReference<>(sb);
sb = null;

In the above snippet, we have created two references to the StringBuilder object. The first line creates a strong reference sb and the second line creates a soft reference sbRef. The third line should make the object eligible for collection but the garbage collector will postpone collecting it because of sbRef.

在上面的片段中,我们创建了对StringBuilder对象的两个引用。第一行创建了一个强引用 sb,第二行创建了一个软引用 sbRef。第三行应该使该对象有资格被收集,但由于sbRef,垃圾收集器将推迟收集它。

The story will only change when memory becomes tight and the JVM is on the brink of throwing an OutOfMemory error. In other words, objects with only soft references are collected as a last resort to recover memory.

只有当内存变得紧张,JVM处于抛出OutOfMemory错误的边缘时,情况才会改变。换句话说,只有软引用的对象被收集,作为恢复内存的最后手段。

A weak reference can be created in a similar manner using WeakReference class. When sb is set to null and the StringBuilder object only has a weak reference, the JVM’s garbage collector will have absolutely no compromise and immediately collect the object at the very next cycle.

弱引用可以通过类似的方式使用WeakReference类来创建。当sb被设置为null,并且StringBuilder对象只有一个弱引用时,JVM的垃圾收集器将完全不妥协,并在下一个周期立即收集该对象。

A phantom reference is similar to a weak reference and an object with only phantom references will be collected without waiting. However, phantom references are enqueued as soon as their objects are collected. We can poll the reference queue to know exactly when the object was collected.

幻象引用类似于弱引用,只有幻象引用的对象将被收集,无需等待。然而,幻象引用在其对象被收集后会立即被排队。我们可以轮询引用队列,以了解对象被收集的确切时间。

Q13. Suppose We Have a Circular Reference (Two Objects That Reference Each Other). Could Such Pair of Objects Become Eligible for Garbage Collection and Why?

Q13.假设我们有一个循环引用(两个对象互相引用)。这样的一对对象是否符合垃圾收集的条件,为什么?

Yes, a pair of objects with a circular reference can become eligible for garbage collection. This is because of how Java’s garbage collector handles circular references. It considers objects live not when they have any reference to them, but when they are reachable by navigating the object graph starting from some garbage collection root (a local variable of a live thread or a static field). If a pair of objects with a circular reference is not reachable from any root, it is considered eligible for garbage collection.

是的,一对具有循环引用的对象可以成为符合垃圾收集条件的对象。这是因为Java的垃圾收集器如何处理循环引用。它认为对象不是在有任何引用的情况下是活的,而是在它们可以从某个垃圾收集根(活线程的局部变量或静态字段)开始通过浏览对象图到达的时候。如果一对有循环引用的对象不能从任何根部到达,它就被认为符合垃圾收集的条件。

Q14. How Are Strings Represented in Memory?

Q14.在记忆中,字符串是如何表示的?

A String instance in Java is an object with two fields: a char[] value field and an int hash field. The value field is an array of chars representing the string itself, and the hash field contains the hashCode of a string which is initialized with zero, calculated during the first hashCode() call and cached ever since. As a curious edge case, if a hashCode of a string has a zero value, it has to be recalculated each time the hashCode() is called.

Java中的String实例是一个具有两个字段的对象:一个char[] value字段和一个int hash字段。value字段是一个代表字符串本身的字符数组,而hash字段包含了字符串的hashCode,它被初始化为0,在第一次hashCode()调用时被计算出来并一直缓存着。作为一个奇怪的边缘案例,如果一个字符串的hashCode有一个零值,那么每次调用hashCode()时,它都必须被重新计算。

Important thing is that a String instance is immutable: you can’t get or modify the underlying char[] array. Another feature of strings is that the static constant strings are loaded and cached in a string pool. If you have multiple identical String objects in your source code, they are all represented by a single instance at runtime.

重要的是,String实例是不可改变的:你不能获得或修改底层的char[]数组。字符串的另一个特点是,静态常量字符串被加载并缓存在一个字符串池中。如果你的源代码中有多个相同的String对象,它们在运行时都由一个实例表示。

Q15. What Is a Stringbuilder and What Are Its Use Cases? What Is the Difference Between Appending a String to a Stringbuilder and Concatenating Two Strings with a + Operator? How Does Stringbuilder Differ from Stringbuffer?

Q15.什么是字符串生成器,它有哪些用例?向Stringbuilder追加一个字符串和用+操作符串联两个字符串的区别是什么?Stringbuilder与Stringbuffer有什么不同?

StringBuilder allows manipulating character sequences by appending, deleting and inserting characters and strings. This is a mutable data structure, as opposed to the String class which is immutable.

StringBuilder允许通过追加、删除和插入字符和字符串来操作字符序列。这是一个可变的数据结构,而String类则是不可变的。

When concatenating two String instances, a new object is created, and strings are copied. This could bring a huge garbage collector overhead if we need to create or modify a string in a loop. StringBuilder allows handling string manipulations much more efficiently.

当连接两个String实例时,会创建一个新对象,并复制字符串。如果我们需要在一个循环中创建或修改一个字符串,这可能会带来巨大的垃圾收集器开销。StringBuilder可以更有效地处理字符串操作。

StringBuffer is different from StringBuilder in that it is thread-safe. If you need to manipulate a string in a single thread, use StringBuilder instead.

StringBufferStringBuilder不同,它是线程安全的。如果你需要在单线程中操作一个字符串,请使用StringBuilder代替。

3. Conclusion

3.结论

In this article, we have covered some of the most common questions that frequently appear in Java engineer interviews. Questions about memory management are mostly asked for Senior Java Developer candidates as the interviewer expects that you have built non-trivial applications which are, a lot of times, plagued by memory issues.

在这篇文章中,我们介绍了一些经常出现在Java工程师面试中的最常见的问题。关于内存管理的问题大多是针对高级Java开发人员候选人提出的,因为面试官希望你已经建立了非微不足道的应用程序,而这些应用程序在很多时候都被内存问题所困扰着。

This should not be treated as an exhaustive list of questions, but rather a launch pad for further research. We, at Baeldung, wish you success in any upcoming interviews.

这不应该被视为一个详尽的问题清单,而是一个进一步研究的启动平台。我们,在Baeldung,祝你在接下来的面试中取得成功。

Next »

Java Generics Interview Questions (+Answers)

« Previous

Java 8 Interview Questions(+ Answers)