Andrews interview study day01

I really learned spit
learn, remember the feeling when the interview OK, inquisitive. Need to have their own thinking.
Directory: JVM, Object.equals, hashcode

Java Summary

JVM

1, JVM workflow
Answer: Java classloader incoming data from within a virtual machine, into binary data, and then by the program counter, stack virtual machines, local area method, heap, the method area.
Here Insert Picture DescriptionThink for yourself: How source code files compiled into bytecode file it?
In fact, the first time to learn to use Javac compiled on the command line operation for the Java virtual machine, its actual input is byte code file, rather than Java files. So for Java in terms of language, in fact, how the Java code into byte code file it? We know there is a tool javac in JDK installation directory, is that it will translate the Java code into byte code, this tool we call the compiler. Relative to other compilers talk later, because it is pre-compiled, it is also known as the front end of the compiler. No matter what language you use, eventually machine code at runtime.

2、运行时数据区
回答:其实应该叫内存区域吧,私有部分:程序计数器、虚拟机栈、本地方法区。共有部分:堆和方法栈。
这里面需要延伸一些东西,比如每个区域的作用,每个区域会出现的错误。
复习一下
程序计数器:就是确定你程序运行到哪里的一个计数器,比如走到第一行就会是1,向下走就会变为2。这个区域内不会出现错误
虚拟机栈:一个方法中开启这个栈,里面输入一些这个方法需要的数据,最后运算出结果返回,因为使用的结构是栈式的结构,所以叫做虚拟机栈。这个区域中会出现outofmemeory和outofstack的错误,那么问题
本地方法区:存放一些本地方法的地区。执行的是Native方法,
堆:共有变量中存放对象的部分,基本对象的创建出生和死亡都在这个区域内,从这个区域中又可以牵扯出对象的存放和GC
方法区:存放一些本地变量,static修饰的变量会在这里提前创建好哦
答案:Here Insert Picture Description
思考:本地方法栈仍有些不具体,什么是Native方法呢,比较简单的说就是java的方法,但是不是用java语言写的,这些方法仍然生效,目的是为了提高一些方法没有使用c或者c++快的问题。
3、方法指令
回答:这个还真不知道
答案:
Here Insert Picture Description
这个感觉不太重要啊。。
四、类加载器
回答:类加载器是java的class文件进入到内存中必须经过的加载工作。有一个自上而下的加载模式,
答案:Here Insert Picture Description
Here Insert Picture Description思考:这个问题秋招问的也不多,但是尽量记住委托机制。
4、垃圾gc
4.1、对象存活判断
回答:只要是没被人引用的实例,就可以说是垃圾1、计数法,调用一次就记一次数,返回不用了就减一次数,当为0的时候就可以认为是垃圾了。2、可达性、先每个方法的变量都产生出来,然后每个方法使用到时就会进行可达性检测,如果一个变量长期没有被可达过,那么就可以认为是垃圾。
Here Insert Picture DescriptionHere Insert Picture Description
4.2、垃圾收集算法
标记-清除算法:第一步:标记,在堆中标记出需要清除的垃圾,第二步是标记完成后回收掉标记对象,但是缺点是效率太慢和内存碎片问题。
复制算法:标记,(然后另外开辟一段相同大小的内存)错误,正确认识是原本就是将之前内存一分为二,只使用一半,在复制过程中,消除垃圾,这解决了碎片化问题,但是没有解决效率问题,原因是大量长生存期的对象大量复制。
标记-整理算法:标记完之后,让所有存活对象移向一端
分代收集算法:基本假设:绝大部分对象的生命周期短,存活时间短
分代收集算法将Java堆分为新生代老年代,新生代死亡比较快,使用复制算法,老年代使用标记清除算法。
4.3、垃圾收集器
CMS收集器:是以标记-清除算法实现的,一共有初始标记,并发标记,重新标记,并发清除四个阶段,初始标记和重新标记需要进行stop the world, 整个过程中最耗时的是并发标记和并发清除,收集器线程可以与用户线程一起工作,CMS收集器的内存回收过程是和用户线程一起并发执行的。
Here Insert Picture Description
G1
4.4、内存模型和回收策略
Whole heap space can be simply divided into the young generation of 1/3 and 2/3 years old, the young generation is divided into two parts, one eden district, a survivor area from-survivor, a survivor-to
eden: In most cases when the object is allocated in eden region, eden zone when there is not enough space allocated, the virtual launch a Minor GC, MinorGC frequently than MajorGC, after MinorGC, eden will be cleared, most of the objects to be recovered, surviving objects into from district, from region if not enough, it's old
survivor: buffer, after MinorGC, will be put to from the area, the meaning of existence survivor region is to reduce delivery to target old age, thereby reducing the MajorGC occurs only experienced 16 times MinorGC the object will be sent to the old years
old: 2/3 occupy memory space, that only majorGC will trigger StopTheWorld, the more memory the longer the pause, it's taken the old mark - finishing algorithm.

Object Methods

1, equals
answer: equals compare two objects of value is the address
to answer segment Source
Here Insert Picture Description
hashCode: this is the meaning of the hash value of each object through the corresponding hash algorithm has its own hash value, there is in the hashmap application, different objects is possible because the corresponding hash algorithms have the same hash value, but that does not mean the two of them are equal.
answer:Here Insert Picture Description
Here Insert Picture Description

Published 21 original articles · won praise 0 · Views 373

Guess you like

Origin blog.csdn.net/jo___jo/article/details/104089716