java软件工程师笔试题目(II) 规则: 1. 时间:40分钟 2. 个人独立完成,不能使用手机等上网上查询。如果被发现作弊,则零分。 3. 为了环保和节约纸张,请在答题卡上填写答案 一、不定项选择题(每题5分) Question 1 Given: 11. public class Test {
) \" e: y% q4 h/ ~, O0 X12. public static void main(String [] args) { " @9 `3 t& b- v4 _+ M/ X
13. int x =5;
( C, `' z! n. K14. boolean b1 = true;
- m! `# p( Y( Y3 J15. boolean b2 = false; % X! s9 _. [6 y- I
17.if((x==4) && !b2)
2 |3 i; D" m, o. ^* |' Q18. System.out.print(”l “);
+ Y0 ?: }, t/ S, | h K19. System.out.print(”2 “); 4 \* r( X8 l( e G
20. if ((b2 = true) && b1)
& A1 a- I+ j$ V$ z" o( ~21. System.out.print(”3 “);
3 ]0 ^$ K/ r: r5 t; B22. } ) m: _1 Y/ d) Z+ \) e1 A* B- c
23. } ) R& W8 h" Z, S) L f6 P' @
What is the result? 6 O/ W2 r ~/ A* H! R4 L) l: h3 D I
A. 2
: o& D# W2 Q( T% gB. 3 1 ]8 e0 t) u `* K" G* }; I& x: r
C. 1 2
. C# ?1 ~. p, X5 ^ s& I4 I4 {D. 2 3 " X; U7 ]3 G/ K ]! F
E. 1 2 3
2 ?: S& A$ T @* h8 i* l3 eF. Compilation fails. & N4 f& [& a* v. q# p
G. Au exceptional is thrown at runtime. Question 2 Assume that country is set for each class. Given: 10. public class Money {
, z8 [" C( p1 w8 g- ^% b" O v11. private String country, name;
! h a, H- e7 D12. public String getCountry() { return country; }
3 |+ e# E6 s' ~, p" o13.} and: 24. class Yen extends Money {
! i: W0 e# o7 ~25. public String getCountry() { return super.country; }
O7 }1 s$ ^- O26. } * C7 \$ l' q3 z+ O- g x. O# a
27. + E6 w8 l! U! f# X
28. class Euro extends Money {
% {! J, d: x, W: ~9 N/ T/ r29. public String getCountry(String timeZone) {
. p9 E; b( a) |8 a. D2 {30. return super.getCountry(); $ p" w- G, ]4 b
31. } 9 s+ @/ T! g( ]! A R' F9 K
32. } ' z8 S! W: N0 Q; p' t. k. a. \
Which two are correct? (Choose two.) A. Yen returns correct values.
( S/ A O, O8 Q% hB. Euro returns correct values. / p3 b& I' O5 e" e
C. An exception is thrown at runtime. 8 C$ Q2 S# w9 j& H, Q5 e
D. Yen and Euro both return correct values.
: a; E& |, K+ M& ~3 u3 n' YE. Compilation fails because of an error at line 25.
3 Y% K$ A) Q% E* }* F( r0 P5 Z2 ]F. Compilation fails because of an error at line 30. Question 3 Given: 1. class TestA { $ v3 |2 E" o& d3 S8 [# b1 K; W- B
2. public void start() { System.out.println(”TestA”); }
2 Q: O C/ B5 J3. }
! L( d" A3 A' d: F2 \1 v4. public class TestB extends TestA {
9 Q; I5 X5 d- x* g1 c; t5. public void start() { System.out.println(”TestB”); }
) s/ {" ?6 x/ _6. public static void main(String[] args) { # M3 ?8 M( m3 {, }" A
7. ((TestA)new TestB()).start();
: m1 _! `& u3 J+ `7 w7 s2 z8. }
9 G3 U& u7 O" T2 q& A9 R9. } 1 x+ V' I' m2 d0 x. n
What is the result? A. TestA ( U1 X5 ?7 n5 C
B. TestB * A+ u6 Y4 `& y
C. Compilation fails. ! q; b9 s( q+ K
D. An exception is thrown at runtime. Question 4 Given: 11. public static void main(String[] args) {
' T4 q9 @; t" s4 H2 ^12. String str = “null’; ; F2 B. A: W. O) B6 o
13. if (str == null) { ! ?0 Z8 D+ I6 h5 |) X
14. System.out.println(”null”); + l2 n# y% H1 ^( t& ^
15. } else (str.length() == 0) { & r5 b4 W: `) \7 R/ m) |
16. System.out.println(”zero”);
; H/ w* X7 a+ V6 \) d% i6 M; k17. } else { 5 ^* J( [% G' J/ N7 B
18. System.out.println(”some”);
/ B) n$ j2 E$ z. d19. }
. I- @2 K# g4 k( p20. }
/ c$ `+ \3 l3 f9 Z5 h‘What is the result? A. null
7 b! g H" e3 O) zB. zero * Q% @' A; c- q# a" Q
C. some 0 Z6 T7 b( H, `& y( F) s
D. Compilation fails. 1 g& M8 X6 p m; g( f L) g
E. An exception is thrown at runtime. Question 5 Given: 33. try {
. L( `' q( G0 G" B5 b; ~34. // some code here
8 |. [4 t# E8 z/ L35. } catch (NullPointerException e1) {
' L3 o+ ^& w$ s% }* m# I; W; _36. System.out.print(”a”);
; A) W4 I5 {2 T M/ F37. } catch (RuntimeException e2) {
1 T: u' D" }( ]( X* E* U38. System.out.print(”b”);
: \6 H; m5 Z% ~: F9 X39. } finally {
9 v% ?1 A4 q) A# Z! i. M1 r40. System.out.print(”c”); ; [( |0 d4 y, e9 o
41. }
$ t/ f3 v6 w& n/ A. ~6 u5 [What is the result if a NullPointerException occurs on line 34? & \5 M( `* n& L$ I n5 Z
A. c
- l) A3 P r+ _B. a
7 e; z; h4 m9 A! \- Q- A* |C. ab 9 c% A% }$ y% a- O. `7 A
D. ac ! S; i- d8 i D" o5 D! ^
E. bc
% _' C- P" K7 D% H5 @! aF. abc Question 6 Given this method in a class: 21. public String toString() {
' C! A$ J* D) a5 a* [; v, l22. StringBuffer buffer = new StringBuffer(); U3 k5 m( {# x) N- t9 Y% V
23. buffer.append(’<’); $ R0 `) R( A8 R0 G8 \( @ a
24. buffer.append(this.name);
, N' f- c* K8 @2 [5 B* ?, @! ^25. buffer.append(’>’); : |4 F2 ?; i# P" N8 d! k R
26. return buffer.toString(); : W6 l- h0 [% i( \* k3 _
27. }
% X# T' R [% h6 u7 ]$ |8 B7 D: j vWhich is true? A. This code is NOT thread-safe. & h8 A/ g8 [. X% }7 `5 V
B. The programmer can replace StringBuffer with StringBuilder with no
+ y2 p6 a! t* P* a7 Jother changes.
0 s1 s2 [+ ], A5 ?% kC. This code will perform well and converting the code to use 0 N# q, |# m t. K1 q: H7 m
StringBuilder will not enhance the performance. . e; Z% Z& _7 }0 K% c
D. This code will perform poorly. For better performance, the code 4 ~" A8 Z/ B; V! B h; B! p) k
should be rewritten: return “<“+ this.name + “>”; Question 7 Given: 14. DateFormat df;
* V& f: r8 R, g5 V/ i# q3 C15. Date date = new Date(); + Y" s6 O5 h' F' d$ P2 U2 |
16. //insert code here
u8 i l( N. f: ~+ t, s17. String s = df.format( date); x, y% T: ?, n7 ^! O0 h8 [; r
Which two, inserted independently at line 16, allow the code to compile? (Choose two.) A. df= new DateFormat(); 0 O) U7 b: O5 \2 |3 p& t$ i
B. df= Date.getFormatter();
5 X: a1 f0 z' P; V& oC. df= date.getFormatter(); ! b, L; j: }* r# o) Z: y
D. df= date.getDateFormatter(); $ d7 i! Z3 ~$ }- l6 }7 p1 A
E. df= Date.getDateFormatter();
) t/ [- F3 R4 S' q0 ZF. df= DateFormat.getInstance();
/ n- Z6 }2 O% c ~- tG. 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的执行流程。
6 T/ V8 p5 y+ R0 [7 @. S* C' r |