20 BAT favorite interviewer asked JVM + MySQL interview questions (with answers parsing)

1. The memory model and partition, you need to detail what to put in each area.
JVM stack area and the heap area is divided into, and method area, the objects instantiated on the heap, which references on the stack,
class constant pool class information (static constants and static variables) or the like on the method area
new:
Method Area: the main class information is stored, the constant pool (static and static variables constant), the compiled code (word
bytecode) data such as
the heap: initializing object member variables (variables that non-static), all object instances and arrays It should be
allocated on the heap
stack: the stack structure is composed of stack frames, calling a method with a press-fitting, the above frame memory local variable table, operation
operand stack, and other information for export, is stored in the local variable table 8 plus a large base type application type, the
order is a pointer to the address of the
native method stacks: the main method for the native services
program counter: the number of rows in the current thread of execution

2. heap inside the partition: Eden, survival (from + to ), old time, their own characteristics.
Stack which is divided into the old generation and the new generation (java8 canceled permanent generation using Metaspace), the new generation packet
-containing Eden + Survivor region, which is divided into survivor region from and to the memory recovery, if the complex
system algorithm, copied from from to to, when one or more times after GC, surviving objects are moved
to old age area, when the JVM memory is not enough, will trigger full GC, clean up older JVM area
when the young generation is full after triggers YGC, first surviving objects into one Survice
area, then clean up the garbage. Because if only clean up the object to be deleted, this will lead to memory broken
pieces, it is generally Eden will be completely clean, then come up memory. GC then the next time,
the next will use a Survive, so recycling. If there is a particularly large objects, the new generation does not fit,
it will guarantee the use of old age, directly into old's inside. Because the JVM think, general store large objects in
live time is usually more distant.

3. Object creation method, the object of memory allocation, access the location of the object.
new object

4. GC method for determining two kinds:
Reference counting: means that if a certain place on the object referenced +1, -1 if it fails, when it is 0
will not recover but the JVM this way, since the each cycle can not be determined by reference (a reference B, B referenced a)
case where the
reference chain method: by means of a GC ROOT object (an object or the like becomes -static static variable region reference
amount) is determined, if one strand can be GC ROOT reach it shows, it shows can not reach the GC ROOT
can be recycled

5. SafePoint what
such GC have to wait until the time Java thread into the safepoint when VMThread to begin
the implementation of GC,

  1. The end of the cycle (to prevent a cycle time has not entered safepoint, while other threads are waiting for it to enter the
    safepoint)
  2. Method returns before
  3. After the call to invoke a method
  4. Throw abnormal position

20 BAT favorite interviewer asked JVM + MySQL interview questions (with answers parsing)

Three kinds of collection methods 6. GC: Mark Clear, finishing mark, copy the principles and characteristics of the algorithm were used
in any place, if let you optimize collection methods, what ideas?
First mark, then clear after marking is completed, the efficiency is not high, will produce debris
replication algorithm: divided into 8: Eden District 1 and District survivor, is mentioned above YGC
tags to organize: After labeling is completed, all surviving objects to mobile end

7. GC collector What? Features CMS collector and G1 collector.
Parallel Collector: serial collector uses a separate thread to collect, GC pause time when services are
serial collector: secondary recovery using multiple threads to execute
CMS collector is based on the "mark - sweep" algorithm to achieve, after several markers will be cleared
G1 on the whole is based on the "mark - finishing" collector algorithm from the local (between two Region)
on the point of view is based on the "copy" of the algorithm

8. Minor GC and Full GC, respectively, when did it happen?
When the new generation of memory is not enough when the MGC occurs also called YGC, JVM is not enough memory occurs FGC

9. several commonly used memory debugging tools: jmap, jstack, JConsole, jhat
jstack can see the current stack, jmap view memory, jhat information dump heap
mat (eclipse should also find out)

10. The process of loading several classes:
loading, verification, preparation, parsing initialization. It is then unloaded and the use
to load generated by the fully qualified name of the object class into the memory, and then verify this class file, including text
formats that check, metadata validation bytecode verifier and the like. It is ready to allocate memory for this object. Symbol resolution is the
number of references into direct reference (pointer reference), is the initialization code starts execution constructor
20 BAT favorite interviewer asked JVM + MySQL interview questions (with answers parsing)

1. What is the database three paradigms?

  1. The first paradigm (1NF): the field is atomic, can not be divided. (All based relational database
    systems meet the first paradigm database table fields are a single property, can not be divided)
  2. 第二范式(2NF)是在第一范式(1NF)的基础上建立起来的,即满足
    第二范式(2NF)必须先满足第一范式(1NF)。要求数据库表中的每
    个实例或行必须可以被惟一地区分。通常需要为表加上一个列,以存储
    各个实例的惟一标识。这个惟一属性列被称为主关键字或主键。
  3. 满足第三范式(3NF)必须先满足第二范式(2NF)。简而言之,第三
    范式(3NF)要求一个数据库表中不包含已在其它表中已包含的非主关
    键字信息。 >所以第三范式具有如下特征: >>1. 每一列只有一个
    值 >>2. 每一行都能区分。 >>3. 每一个表都不包含其他表已经包含
    的非主关键字信息。

2. 有哪些数据库优化方面的经验?

  1. 用 PreparedStatement, 一般来说比 Statement 性能高:一个 sql
    发给服务器去执行,涉及步骤:语法检查、语义分析, 编译,缓存。
  2. 有外键约束会影响插入和删除性能,如果程序能够保证数据的完整性,
    那在设计数据库时就去掉外键。
  3. 表中允许适当冗余,譬如,主题帖的回复数量和最后回复时间等
  4. UNION ALL 要比 UNION 快很多,所以,如果可以确认合并的两个结
    果集中不包含重复数据且不需要排序时的话,那么就使用 UNION
    ALL。 >>UNION 和 UNION ALL 关键字都是将两个结果集合并为一
    个,但这两者从使用和效率上来说都有所不同。 >1. 对重复结果的处
    理:UNION 在进行表链接后会筛选掉重复的记录,Union All 不会去除
    重复记录。 >2. 对排序的处理:Union 将会按照字段的顺序进行排
    序;UNION ALL 只是简单的将两个结果合并后就返回。

3. 请简述常用的索引有哪些种类?

  1. 普通索引: 即针对数据库表创建索引
  2. 唯一索引: 与普通索引类似,不同的就是:MySQL 数据库索引列的值
    必须唯一,但允许有空值
  3. 主键索引: 它是一种特殊的唯一索引,不允许有空值。一般是在建表的
    时候同时创建主键索引
  4. 组合索引: 为了进一步榨取 MySQL 的效率,就要考虑建立组合索引。
    即将数据库表中的多个字段联合起来作为一个组合索引。

4. 以及在 mysql 数据库中索引的工作机制是什么?
数据库索引,是数据库管理系统中一个排序的数据结构,以协助快速查询、更
新数据库表中数据。索引的实现通常使用 B 树及其变种 B+树

5.MySQL 的基础操作命令:

  1. MySQL 是否处于运行状态:Debian 上运行命令 service mysql
    status,在 RedHat 上运行命令 service mysqld status
  2. 开启或停止 MySQL 服务 :运行命令 service mysqld start 开启服
    务;运行命令 service mysqld stop 停止服务
  3. Shell 登入 MySQL: 运行命令 mysql -u root -p
  4. 列出所有数据库:运行命令 show databases;
  5. 切换到某个数据库并在上面工作:运行命令 use databasename; 进入
    名为 databasename 的数据库
  6. 列出某个数据库内所有表: show tables;
  7. 获取表内所有 Field 对象的名称和类型 :describe table_name;
    20 BAT favorite interviewer asked JVM + MySQL interview questions (with answers parsing)

6.mysql 的复制原理以及流程。
Mysql 内建的复制功能是构建大型,高性能应用程序的基础。将 Mysql 的数据
分布到多个系统上去,这种分布的机制,是通过将 Mysql 的某一台主机的数据
复制到其它主机(slaves)上,并重新执行一遍来实现的。 * 复制过程中一
个服务器充当主服务器,而一个或多个其它服务器充当从服务器。主服务器将
更新写入二进制日志文件,并维护文件的一个索引以跟踪日志循环。这些日志
可以记录发送到从服务器的更新。 当一个从服务器连接主服务器时,它通知主
服务器在日志中读取的最后一次成功更新的位置。从服务器接收从那时起发生
的任何更新,然后封锁并等待主服务器通知新的更新。 过程如下 1. 主服务器
把更新记录到二进制日志文件中。 2. 从服务器把主服务器的二进制日志拷贝
到自己的中继日志(replay log)中。 3. 从服务器重做中继日志中的时间,
把更新应用到自己的数据库上。

7.mysql 支持的复制类型?

  1. 基于语句的复制: 在主服务器上执行的 SQL 语句,在从服务器上执行
    同样的语句。MySQL 默认采用基于语句的复制,效率比较高。 一旦发
    现没法精确复制时,会自动选着基于行的复制。
  2. 基于行的复制:把改变的内容复制过去,而不是把命令在从服务器上执
    行一遍. 从 mysql5.0 开始支持
  3. 混合类型的复制: 默认采用基于语句的复制,一旦发现基于语句的无法
    精确的复制时,就会采用基于行的复制。

8.mysql 中 中 varchar 与 与 char 的区别以及 varchar(50) 中的 50 代表的涵
义?

  1. varchar 与 char 的区别: char 是一种固定长度的类型,varchar 则是
    一种可变长度的类型.
  2. varchar(50)中 50 的涵义 : 最多存放 50 个字节
  3. int(20)中 20 的涵义: int(M)中的 M indicates the maximum
    display width (最大显示宽度)for integer types. The maximum
    legal display width is 255.

9. The table has a large field X (for example: text type), and the X field will not be updated frequently to read as
main, this field is split into sub-table what the benefits?

If the field there are large fields (text, blob) type, and access to these fields is not much, this
time together becomes a drawback. MYSQL database record store is stored by row, the data
block size is smaller fixed (16K), each record, the more the same block stored records. This
time should be removed the large field, so when most small to cope with the query field, will be able to improve efficiency. When required
when you want to query a large field, this time associated with the query is inevitable, but it is worth it. After the split open,
UPDAE field necessary for the UPDATE plurality of tables

InnoDB row lock 10.MySQL in the engine is done by adding on what (or realization)
of?

InnoDB row lock is achieved by the index to the index items on the lock, which is MySQL and
Oracle different, which is locked by the corresponding data line in the data block to achieve. InnoDB these
kinds of features meant to achieve row lock: only through index conditions to retrieve the data, only InnoDB uses row-level
locking, otherwise, would use InnoDB table lock!

Guess you like

Origin blog.51cto.com/14442094/2427523