java软件工程师笔试题目(II) 规则: 1. 时间:40分钟 2. 个人独立完成,不能使用手机等上网上查询。如果被发现作弊,则零分。 3. 为了环保和节约纸张,请在答题卡上填写答案 一、不定项选择题(每题5分) Question 1 Given: 11. public class Test { 2 |4 {& P2 K. h, _+ p$ T
12. public static void main(String [] args) {
1 s4 h0 O' ?- E13. int x =5;
/ l) O0 Q, j: Y+ P14. boolean b1 = true; D; \3 U$ |) D. M. A5 s$ J
15. boolean b2 = false;
5 c0 _/ `% c, e1 |17.if((x==4) && !b2) : ?9 I3 r* \- Z$ \4 i: H
18. System.out.print(”l “);
3 X" z( v3 e; J9 l19. System.out.print(”2 “); ; }+ G M- y9 A( Z( j: R0 Z, ?0 g( H
20. if ((b2 = true) && b1)
3 c; S) A( Q+ d& i/ s* J8 {, Z21. System.out.print(”3 “); ( C$ {4 B8 K/ p( ^5 R4 [
22. } 5 e' N3 B) b: F9 @8 ~- F0 K
23. }
0 g% j0 J9 p- @+ l7 D6 J6 M+ GWhat is the result? # O- _" B& q* C
A. 2
! n$ n- X. R6 _ v* X* x. dB. 3
, n" d7 _; R C$ OC. 1 2
, [: p+ e# ^; M$ M) P8 c2 j# sD. 2 3 ' ?9 l2 Z( q: g
E. 1 2 3
' ]6 G1 L- k( W7 l/ {$ u4 zF. Compilation fails. 8 _% t" S5 v4 ^
G. Au exceptional is thrown at runtime. Question 2 Assume that country is set for each class. Given: 10. public class Money { # [) ]! p4 _& g$ C( `4 \
11. private String country, name;
/ f+ r( |! i/ R/ f12. public String getCountry() { return country; }
* P8 \" _/ v* c( e Z$ N! N- l. m+ u% @13.} and: 24. class Yen extends Money {
$ c+ S2 N' ]0 ]# V! {3 h# \2 Z25. public String getCountry() { return super.country; }
& a, O/ V( g2 ?26. } & c+ B+ W0 ~& \( m9 J( c$ K4 n
27. & w3 W) R z' H8 x% t5 P
28. class Euro extends Money {
i1 B6 J% S3 v. L( @7 k29. public String getCountry(String timeZone) {
$ M3 R. `* Q; N1 @3 n30. return super.getCountry();
3 z7 X4 L/ Y, @: w! v( X s) D31. } " c4 T* k. Q) b5 F/ z
32. } 1 H* m+ X6 F! ~- k3 [5 W' A6 w
Which two are correct? (Choose two.) A. Yen returns correct values.
5 I7 T9 A* I$ f& T& j' E8 aB. Euro returns correct values.
) f) c, U9 {, d- f% ~C. An exception is thrown at runtime.
3 W/ ?! `! @; V" b ^+ f2 TD. Yen and Euro both return correct values.
% m/ {2 [8 `% [, n% wE. Compilation fails because of an error at line 25. 1 x$ Y+ B0 k- C8 b) V1 w
F. Compilation fails because of an error at line 30. Question 3 Given: 1. class TestA { 4 |' c, Q: \7 Z+ c
2. public void start() { System.out.println(”TestA”); } 7 V* G8 A: c8 ?4 u& O& B% l
3. } , \" g, `5 o# a" D, I
4. public class TestB extends TestA { % D' l6 @0 I6 @) g+ z+ A
5. public void start() { System.out.println(”TestB”); } 4 R( W5 I) ]2 h! s$ i
6. public static void main(String[] args) { 3 G) i6 L) p& K! {$ s/ W `
7. ((TestA)new TestB()).start(); % w1 c* C! j$ Q4 s3 S a% H0 D
8. } , j5 F( H% @% e a/ M
9. }
# D/ O# t7 G! r4 {! p) U' m. c/ kWhat is the result? A. TestA ) V/ N$ I% P9 u1 A9 Y6 k* j7 j
B. TestB
$ w) q4 t( R/ L2 yC. Compilation fails.
1 S3 g3 N4 p6 p$ _D. An exception is thrown at runtime. Question 4 Given: 11. public static void main(String[] args) {
. `3 ^5 a# f% |4 Q0 Y) }' f12. String str = “null’; 8 e/ N( w, q: `7 B' w
13. if (str == null) {
# `# M% V P# d) K! N14. System.out.println(”null”);
9 P1 d& R0 n# g/ }* D! j+ h15. } else (str.length() == 0) { 5 k- u) ]# d( {1 u% z
16. System.out.println(”zero”); ( ^3 h1 a. d& u6 H
17. } else { % O0 d5 G( {7 b4 ~' X
18. System.out.println(”some”); / w4 R B7 M8 | H
19. }
# p) C, h B+ p8 h$ X" L) t20. }
, i( _$ k) ~7 o6 P" L8 _‘What is the result? A. null % z# u [5 c4 Q! E6 \7 A" M
B. zero
# X8 |6 F9 S" f8 AC. some % j' x# g$ p/ F) p9 d8 k5 {! |
D. Compilation fails.
% K6 ], M- w7 u8 |E. An exception is thrown at runtime. Question 5 Given: 33. try { . c% v; ~" ^/ e: s' o& @3 Q
34. // some code here 0 j6 H9 N Z) H5 X) |2 M
35. } catch (NullPointerException e1) {
; W4 a. L+ l9 ~ X36. System.out.print(”a”);
; i4 y! `! r0 t8 ]% b# ^; E37. } catch (RuntimeException e2) { : ?% i G% a* Z& J- G
38. System.out.print(”b”);
4 Q R! O) P/ j3 H% F" Y39. } finally {
' M- u5 F; {. U- `7 }" i40. System.out.print(”c”);
1 Y8 u+ o& K" s, q+ \* E% \41. }
3 j' Y0 ^2 p: h* V5 S6 N" Q$ d0 F2 RWhat is the result if a NullPointerException occurs on line 34?
g. H; J1 q! y* ZA. c
) {* b9 J1 b$ v3 qB. a 3 c# f, q2 d6 P9 W ^
C. ab / ~4 w# R5 ?" f5 e
D. ac
Z% X, _: ?+ {* o; m+ d; ]E. bc
; r S* d9 [ ?; G! ^; `+ s% B OF. abc Question 6 Given this method in a class: 21. public String toString() {
. U# o9 S% F, {4 d- x+ b8 q* P22. StringBuffer buffer = new StringBuffer();
% c0 \9 t; g& T0 x5 H; a23. buffer.append(’<’);
f' K. m- ^9 | u4 X' f" J24. buffer.append(this.name);
6 e3 F1 G* |/ U' c25. buffer.append(’>’);
0 q2 X: z! E* k, }0 Y- N26. return buffer.toString(); 1 O. M! b, Y6 Z5 F* e! ?) o
27. }
, O" X( `7 V$ C5 A2 ^Which is true? A. This code is NOT thread-safe. / e+ |% ]9 h# o# M
B. The programmer can replace StringBuffer with StringBuilder with no
9 J- k. }& y+ mother changes. , x; {$ V( |5 Q5 j n/ Z+ x
C. This code will perform well and converting the code to use
- ~( v5 m' a- m% E! S. uStringBuilder will not enhance the performance.
* r% P/ t2 y ]& J: ?' G. VD. This code will perform poorly. For better performance, the code ' b) L7 ?$ M( S4 T
should be rewritten: return “<“+ this.name + “>”; Question 7 Given: 14. DateFormat df; $ J- R) J/ ^" ^* t$ ~' C! n
15. Date date = new Date(); 0 t: v$ k0 i. [- v
16. //insert code here
& w' a' l$ H4 c$ @8 c! t. P17. String s = df.format( date); 0 g: ?4 q) M4 k" h
Which two, inserted independently at line 16, allow the code to compile? (Choose two.) A. df= new DateFormat();
! l1 m+ e& X) g2 q& sB. df= Date.getFormatter();
. y, C% Q. z0 e X+ q3 J4 XC. df= date.getFormatter();
# Q, R* [5 Y" ]$ w7 ID. df= date.getDateFormatter(); ) s6 Y3 g8 \6 i. \$ H3 J& G! w
E. df= Date.getDateFormatter(); 9 B, [9 C) P2 g( Q
F. df= DateFormat.getInstance();
* t# A7 O9 T( J9 w0 m6 G( ?G. df = DateFormat.getDateInstance(); Question 8 为数据库中一个或者多个表中的数据提供另外一种查看方式的逻辑表被称为()。(选择一项) A. 存储过程 B. 数据库关系图 C. 视图 D. 表 Question 9 已知employee表中具有默认约束df_email,删除该约束的语句为()。A. alter talbe employee drop constraint df_email B. alter talbe employee remove constraint df_email C. alter talbe employee delete constraint df_email D. remove constraint df_email from talbe employee Question 10 将E-R图转换为表的过程中,如果实体之间存在多对多的关系,通常的做法是()。 A. 在两个实体间建立主外键关系。 B. 在两个实体间建立关联表,把一个多对多的关系分解成两个一对多的关系。 C. 在两个实体间建立关联表,把一个多对多的关系分解成两个一对一的关系。 D. 在两个实体间不建立任何关系。 Question 11 假设有scores表的设计如下: ID(编号,主键) StudentID(学生编号) CourseID(课程编号) Score(分数) 现在要查询参加过至少两门课程考试的学生各门课程的平均成绩。以下SQL语句正确的是()。 A. select StudentID,avg(score) from scores group by StudentID having count(studentID)>1 B. select StudentID,avg(score) from scores group by StudentID where count(studentID)>1 C. select StudentID,avg(score) from scores group by StudentID where count(studentID)>1 group by StudentID D. select StudentID,avg(score) from scores having count(studentID)>1 Question 12 在()的列上更适合创建索引。 A. 需要对数据进行排序 B. 具有默认值 C. 频繁更改 D. 频繁搜索 Question 13 (hibernate)以下哪个选项不是持久化层的对象状态? A. 临时状态B. 独立状态C. 游离状态D. 持久化状态 Question 14 设计模式一般用来解决什么样的问题( ) A.同一问题的不同表相 B不同问题的同一表相 C.不同问题的不同表相 D.以上都不是 Question 15 设计模式的两大主题是( ) A.系统的维护与开发 B 对象组合与类的继承 C.系统架构与系统开发 D.系统复用与系统扩展 Question 16 单子模式中,两个基本要点( )和单子类自己提供单例 A .构造函数私有 B.唯一实例 C.静态工厂方法 D.以上都不对 二、简答题(每题5分) 1、AOP和IOC的概念以及在spring中是如何应用的。 2、简单描述hibernate持久化对象三种状态转换关系。 3、spring的事务有几种方式?并描述spring事务的隔离级别和传播行为。 4、简要阐述struts2的执行流程。 ; V2 k& N i" M/ L7 ^- I
|