错题
1.javac的作用是( )。
正确答案: A 你的答案: B (错误)
A.将源程序编译成字节码
B.将字节码编译成源程序
C.解释执行Java字节码
D.调试Java代码
2.执行语句“int a= ’ 2 ’ ”后,a的值是( )
正确答案: B 你的答案: D (错误)
A.2
B.50
C.49
D.0
这个题考察的是java的向上转型,char自动转为int类型
' 'ASCII码
常见字符的ASCII码值如下:空格的ASCII码值为32;数字0到9的ASCII码值分别为48到57;大写字母“A”到“Z”的ASCII码值分别为65到90;小写字母“a”到“z”的ASCII码值分别为97到到122。
1、整数类型byte(1个字节)short(2个字节)int(4个字节)long(8个字节)
2、字符类型char(2个字节)
3、浮点类型float(4个字节)double(8个字节)
一个字节8位
3.java语言的下面几种数组复制方法中,哪个效率最高?
(1)从速度上看:System.arraycopy > clone > Arrays.copyOf > for
(2)for的速度之所以最慢是因为下标表示法每次都从起点开始寻位到指定下标处(现代编译器应该对其有进行优化,改为指针),另外就是它每一次循环都要判断一次是否达到数组最大长度和进行一次额外的记录下标值的加法运算。
(3)查看Arrays.copyOf的源码可以发现,它其实本质上是调用了System.arraycopy。之所以时间差距比较大,是因为很大一部分开销全花在了Math.min函数上了。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
public static byte [] copyOf( byte [] original, int newLength) { byte [] copy = new byte [newLength]; System.arraycopy(original, 0 , copy, 0 , Math.min(original.length, newLength)); return copy; } <ul style= "text-align: right;" > <li style= "color: rgb(153,153,153);" > 1 </li><li style= "color: rgb(153,153,153);" > 2 </li><li style= "color: rgb(153,153,153);" > 3 </li><li style= "color: rgb(153,153,153);" > 4 </li><li style= "color: rgb(153,153,153);" > 5 </li></ul> |
(4)查看System.arraycopy的源码,可以发现它实质上是通过Jni调用本地方法,及c/c++已经编译成机器码的方法,所以快。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
public static native void arraycopy(Object src, int srcPos, Object dest, int destPos, int length); <ul style= "text-align: right;" > <li style= "color: rgb(153,153,153);" > 1 </li><li style= "color: rgb(153,153,153);" > 2 </li><li style= "color: rgb(153,153,153);" > 3 </li></ul> |
(5)clone的源码不详,鄙人无法比较
索引:
正确答案: B C D E 你的答案: A B D (错误)
A.select * from game_order where plat_game_id=5 and plat_id=134
B.select * from game_order where plat_id=134 and plat_game_id=5 and plat_order_id=’100’
C.select * from game_order where plat_order_id=’100’
D.select * from game_order where plat_game_id=5 and plat_order_id=’100’ and plat_id=134
E.select * from game_order where plat_game_id=5 and plat_order_id=’100’
解释:
- 这道题目想考察的知识点是MySQL组合索引(复合索引)的最左优先原则。最左优先就是说组合索引的第一个字段必须出现在查询组句中,这个索引才会被用到。只要组合索引最左边第一个字段出现在Where中,那么不管后面的字段出现与否或者出现顺序如何,MySQL引擎都会自动调用索引来优化查询效率。
- 根据最左匹配原则可以知道B-Tree建立索引的过程,比如假设有一个3列索引(col1,col2,col3),那么MySQL只会会建立三个索引(col1),(col1,col2),(col1,col2,col3)。
- 所以题目会创建三个索引(plat_order_id)、(plat_order_id与plat_game_id的组合索引)、(plat_order_id、plat_game_id与plat_id的组合索引)。根据最左匹配原则,where语句必须要有plat_order_id才能调用索引(如果没有plat_order_id字段那么一个索引也调用不到),如果同时出现plat_order_id与plat_game_id则会调用两者的组合索引,如果同时出现三者则调用三者的组合索引。
- 题目问有哪些sql能使用到索引,个人认为只要Where后出现了plat_order_id字段的SQL语句都会调用到索引,只不过是所调用的索引不同而已,所以选BCDE。如果题目说清楚是调用到三个字段的复合索引,那答案才是BD。