java软件工程师笔试题目(II) 规则: 1. 时间:40分钟 2. 个人独立完成,不能使用手机等上网上查询。如果被发现作弊,则零分。 3. 为了环保和节约纸张,请在答题卡上填写答案 一、不定项选择题(每题5分) Question 1 Given: 11. public class Test { 2 t7 L& m& S+ J8 a& ?8 z* f
12. public static void main(String [] args) { ( U) _# r2 h! P
13. int x =5; V6 {% ~5 p8 q" m; G
14. boolean b1 = true;
# { X- @3 K# E8 U6 ~3 x4 f15. boolean b2 = false; ! O2 W [. q6 p" }" D8 _+ L0 |; N k
17.if((x==4) && !b2) F8 J; z$ g( O7 |
18. System.out.print(”l “); 3 Y& n# `, N( ^; ]7 \2 ^7 ^; ^
19. System.out.print(”2 “);
1 v) f. }- A- O) F: L0 i20. if ((b2 = true) && b1) / Z, W+ E+ y8 ]8 S' c
21. System.out.print(”3 “); 3 r/ J, e* q1 ^ E1 O& x
22. }
; R; @: }8 a4 _ W( j+ w& s23. }
7 G' Y1 b$ f( j' h$ x9 T& G$ bWhat is the result? - r3 k; d' L0 x1 p
A. 2 0 [( |* a) f$ k- M# m
B. 3
W8 i C/ X6 ~% M/ n' BC. 1 2
8 \# K8 n" n9 x* ^9 ~& x: W6 aD. 2 3 3 E( H( j1 _) \# I# @% U$ F# h
E. 1 2 3 7 m, T( ?* j7 M
F. Compilation fails. 3 J; ?% Z5 l( T) O3 N& R: t" a
G. Au exceptional is thrown at runtime. Question 2 Assume that country is set for each class. Given: 10. public class Money {
/ c+ W' o' V6 ]* R6 o11. private String country, name;
0 v B. p- X( @; o" g* @12. public String getCountry() { return country; } 1 O W* J4 X1 b/ f% C6 Q
13.} and: 24. class Yen extends Money { 1 Q* V2 L6 ]3 ]
25. public String getCountry() { return super.country; } * W$ K, z. x/ u' U7 _5 e6 x
26. } , J U4 ^% t; \& [2 U6 L6 u
27.
' P& t8 b, U- i0 G28. class Euro extends Money {
2 j4 l, Y7 }& i% p2 G( V6 L29. public String getCountry(String timeZone) {
/ o1 O- c$ K6 X9 e. }30. return super.getCountry();
+ v. d X* Y% N( A) k" t31. }
& U8 S8 b' A$ i8 @0 {( t8 y% V1 I/ H32. } ; e$ N5 y; a* K- N/ _+ Q! V; `
Which two are correct? (Choose two.) A. Yen returns correct values. # ^/ i4 ?, S* j E3 y
B. Euro returns correct values.
$ Z. w$ k& P0 k0 LC. An exception is thrown at runtime. 4 `# G9 M0 b" X# \$ O
D. Yen and Euro both return correct values.
1 v3 n3 Y: F/ a$ oE. Compilation fails because of an error at line 25. 8 ~" `! g$ K! L; R) v# p
F. Compilation fails because of an error at line 30. Question 3 Given: 1. class TestA { ( n' \+ _6 e6 Z% t* n. @
2. public void start() { System.out.println(”TestA”); }
. A; R. j0 c) f, C8 d3. }
: f- B- ?. M2 y6 O4 y4. public class TestB extends TestA {
; X( v! }! ]9 T" O2 s- T5. public void start() { System.out.println(”TestB”); }
! f: y. \. v) p: g6. public static void main(String[] args) { . F( @. B3 \/ h3 X" o
7. ((TestA)new TestB()).start();
* [! }" m& C8 m1 T9 F4 y4 }8. }
3 t6 k9 F+ r" v; m9 v3 U; X9. } 5 m% h3 L* r, _# J( @
What is the result? A. TestA
# T9 ^# [% V! k; o" U2 ^+ y1 }B. TestB 5 [. q! } c+ E) h x/ w. `1 M
C. Compilation fails.
S9 ^) o1 h `8 h: C5 hD. An exception is thrown at runtime. Question 4 Given: 11. public static void main(String[] args) {
; m. a! Z! l* I0 T, Q# W$ p* H12. String str = “null’;
$ t' g7 J* W- k* P13. if (str == null) {
! ]# G9 Y6 j) _' h14. System.out.println(”null”); ) B4 X% h& f5 U1 n
15. } else (str.length() == 0) { ' y+ h7 ]3 E" W9 A( h0 O
16. System.out.println(”zero”);
5 [3 W( U0 m/ u5 o17. } else {
\& z6 G' t% e18. System.out.println(”some”);
. f: z: w& s8 T+ m19. }
- J* K" ~5 J6 b& Q& M* N3 M20. }
) V8 p7 x# }! @ I+ V& U- ^% i' w‘What is the result? A. null 6 l4 m" e+ b9 ^$ ?& M; n
B. zero ' }" L6 y8 W4 X! Z
C. some
! h8 b5 X; ^6 \ eD. Compilation fails. * V: x$ U+ ` ]# l' G M- E f
E. An exception is thrown at runtime. Question 5 Given: 33. try { 5 u* C6 s6 K1 q) K$ D) j) G( C; `
34. // some code here / v3 M, Y$ u/ L% X/ G. d6 ^; t1 v: h# Y
35. } catch (NullPointerException e1) { ! W$ z2 d E m# q, B
36. System.out.print(”a”); 0 R0 b9 Q- r" I. c" \' F, F* F
37. } catch (RuntimeException e2) { # M! h% _$ g; T* Y- @! `2 v! l
38. System.out.print(”b”);
+ \. s0 T5 d. d# W0 q9 [" [9 s39. } finally { 3 z$ C# u- N: y4 |
40. System.out.print(”c”);
0 H. r! Y+ e+ y, t- v# Z. i, M$ T N41. } - X4 j& K8 Y) P$ [6 A6 d
What is the result if a NullPointerException occurs on line 34? . ]" \ ^5 @5 j0 h! x
A. c # m+ c$ [3 O E; ]
B. a
- C& o) L( {3 F# l0 o$ ~C. ab
- M7 R6 W( V+ ED. ac
+ z& J$ n _2 p9 [5 [E. bc " x1 u' J0 c, i) }8 X
F. abc Question 6 Given this method in a class: 21. public String toString() { 6 B7 b) c; ]# M; r: |1 s
22. StringBuffer buffer = new StringBuffer(); 0 A$ E3 w2 A4 \, f2 M% l& `7 G
23. buffer.append(’<’); - I& I( y1 d2 p9 _5 O) ^' j
24. buffer.append(this.name); # M: ~. H" c& }, S
25. buffer.append(’>’);
" }, s" [2 P/ F+ \* o26. return buffer.toString(); # }& H: W) g- C/ a O
27. } ' e" T, y. x0 M. Z& @2 G: |
Which is true? A. This code is NOT thread-safe.
9 L2 K- k& F* N% lB. The programmer can replace StringBuffer with StringBuilder with no * j; |' N" Q0 P$ m
other changes. V* W0 v8 [$ F, T
C. This code will perform well and converting the code to use
2 m/ G( e2 ?7 J0 yStringBuilder will not enhance the performance. : T( a9 v* T- w! k7 D% y& n2 K% E
D. This code will perform poorly. For better performance, the code 0 ?0 ^& w! h! L
should be rewritten: return “<“+ this.name + “>”; Question 7 Given: 14. DateFormat df; , Z1 Q! k E' o: E# m, G
15. Date date = new Date(); * ^, A1 L8 V( t! e3 g9 W
16. //insert code here . v9 }6 ], k n0 D/ c# d5 H
17. String s = df.format( date);
8 m4 S# e" L$ D; d) d) zWhich two, inserted independently at line 16, allow the code to compile? (Choose two.) A. df= new DateFormat();
+ l* l4 W/ e% ZB. df= Date.getFormatter(); u1 X( M9 [7 R" A
C. df= date.getFormatter();
( i. N7 t, ^; B/ d8 D4 lD. df= date.getDateFormatter();
* e# H+ h6 f, D' l( p$ H: EE. df= Date.getDateFormatter(); ' [7 R, Y, L% Q3 H" b
F. df= DateFormat.getInstance(); 0 ~9 z3 a+ J' R* s
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的执行流程。
. r. g2 d+ X7 K; [ |