java软件工程师笔试题目(II) 规则: 1. 时间:40分钟 2. 个人独立完成,不能使用手机等上网上查询。如果被发现作弊,则零分。 3. 为了环保和节约纸张,请在答题卡上填写答案 一、不定项选择题(每题5分) Question 1 Given: 11. public class Test {
9 |, F/ b i3 G1 A12. public static void main(String [] args) { " P4 B) @+ S6 @# ~; t
13. int x =5;
' x5 l( ?. Z- g1 Q14. boolean b1 = true; 8 w$ C) {' r ^8 }6 o- ^
15. boolean b2 = false;
7 m: ?: n0 X' A- O17.if((x==4) && !b2) : \) y* I! o$ y8 M% H
18. System.out.print(”l “);
/ u# J9 w" x G+ Z' L& k" w4 T" ~19. System.out.print(”2 “); / Q/ c; y& }. O; w( K
20. if ((b2 = true) && b1)
8 _) @) M I: \/ X/ k, I21. System.out.print(”3 “);
; E6 Y- {" ?4 \8 k, f/ {8 |22. } # A$ r1 e0 ^& ~
23. }
M. O. x3 i1 |' J& oWhat is the result?
8 ^% t2 E9 U% r/ O" uA. 2
" e5 `7 K1 Z( }) `/ `3 dB. 3 , F$ D. S/ `4 \# |9 ~0 P
C. 1 2
" J" i/ m, p" b& @' t g# I1 ]: Y. {D. 2 3 . T+ Y8 R3 c4 }; G" o2 R
E. 1 2 3
+ X! r1 H+ I( U1 ^- t, |F. Compilation fails.
; I* R7 b1 A# s9 \& F* V6 ?G. Au exceptional is thrown at runtime. Question 2 Assume that country is set for each class. Given: 10. public class Money { ) a* B5 o1 v* F5 K
11. private String country, name; 3 O6 t* [ M9 T* E
12. public String getCountry() { return country; } - {5 ^+ L; |+ |% R
13.} and: 24. class Yen extends Money {
1 o3 U5 [- q& @7 v K9 a25. public String getCountry() { return super.country; } - {% u, A" {9 @3 e: z, o( I8 o' P
26. }
3 N) p+ q4 F9 p5 c9 N4 o9 y6 T' n27. 1 D0 s, |2 K6 m7 [/ n5 n- x
28. class Euro extends Money { 1 \; s. x; w0 F# H0 w
29. public String getCountry(String timeZone) { 6 p% S8 H6 g& U% ?2 n
30. return super.getCountry(); 0 o/ _5 { E2 O; [7 u$ E
31. } 5 E3 q0 {) \$ I k2 F' P; z( J0 B
32. } ( r; [* V) T" w* c% ]- F: V& P
Which two are correct? (Choose two.) A. Yen returns correct values.
# Q" W- d, d( _6 v( HB. Euro returns correct values.
- N3 h, T+ ?8 [. n. y; i+ cC. An exception is thrown at runtime.
2 Q6 J# X6 Y7 u) uD. Yen and Euro both return correct values. 4 k8 k: c, i0 Y, j6 |$ C% Z# S
E. Compilation fails because of an error at line 25.
- R' k! M8 k% BF. Compilation fails because of an error at line 30. Question 3 Given: 1. class TestA {
; `3 }( h* T: E2. public void start() { System.out.println(”TestA”); } 5 v; R. U2 g8 {3 Y6 g
3. }
# A$ l; s3 W: N' {! A `$ @$ L4. public class TestB extends TestA { 1 q3 |" y: a9 ]4 G
5. public void start() { System.out.println(”TestB”); } 4 r, A9 O* W* y0 `$ h2 m8 B
6. public static void main(String[] args) {
5 |3 ?/ n A& i& _0 Z& ]" t* N7. ((TestA)new TestB()).start();
P9 @4 _% r$ Y/ h; E, n8. } / P) a6 b, L4 n2 _: t* @: N
9. }
% i5 O5 O6 l! O( ^+ d, g, JWhat is the result? A. TestA 6 o4 H. p: N7 r
B. TestB
- G5 \+ Y7 J! `C. Compilation fails.
5 U) L, h% D5 C8 b) tD. An exception is thrown at runtime. Question 4 Given: 11. public static void main(String[] args) { " |; e2 w% p# z: G; e+ d( d; _
12. String str = “null’;
" A) N- r/ c0 }: G4 S. }3 Q13. if (str == null) { 8 n/ N% _0 x5 e' k
14. System.out.println(”null”);
7 t, f" o6 {4 H8 [3 x4 C15. } else (str.length() == 0) { # i& W1 _) H5 m9 L% X( h
16. System.out.println(”zero”); % j' A/ ?; ^3 O( a' B6 q' J `
17. } else {
5 W* h1 w! M5 l7 _( v6 R4 `18. System.out.println(”some”);
+ a6 l8 ?) v% A1 }% E) `( W% h19. } u* K" a: P7 D' B! E P
20. } 1 G; c$ i0 x6 C1 b* K, e& s
‘What is the result? A. null
7 p$ c. W; d* J1 uB. zero 4 |1 |, g4 P7 u/ F2 z2 U
C. some " Y" U* `3 ^: p# y
D. Compilation fails. + i3 m* A* g) L }) Y7 g
E. An exception is thrown at runtime. Question 5 Given: 33. try {
0 J, q6 @4 w+ g ~5 G& `* n34. // some code here % y+ ]2 s0 G* Z2 u+ e) P( h; W- I
35. } catch (NullPointerException e1) { " Z( J4 P8 f4 Y U5 H& r7 Q' S! S
36. System.out.print(”a”);
& i5 _# l# S$ b6 o37. } catch (RuntimeException e2) { + C) @2 G9 C. \6 }( M
38. System.out.print(”b”); 7 E* q* v1 ]: a& \
39. } finally {
[) Y* s( _. \* ]/ E2 p40. System.out.print(”c”); ) o9 M6 t. m2 ]$ C1 X/ s) e$ u9 M
41. }
% U3 f( I0 [" @What is the result if a NullPointerException occurs on line 34? 0 S2 V$ R i& k1 c! v8 U/ K1 @
A. c
/ j4 N/ g M$ m. v% ^0 Z9 hB. a 7 O( l! M" m) f; \4 ?
C. ab
, w; ?2 x$ K; t- ?, w Y0 V5 JD. ac
( x" M3 u U- N4 W7 V2 EE. bc
: R: b2 U# n0 k4 p% x% S$ b) Z/ RF. abc Question 6 Given this method in a class: 21. public String toString() { : @ c2 I- y( g" N
22. StringBuffer buffer = new StringBuffer(); 3 o D! x4 p; H7 z( J
23. buffer.append(’<’); 6 N# Z# ~& ^4 J: v
24. buffer.append(this.name);
5 S6 \+ n ?& J. g25. buffer.append(’>’);
6 @0 L1 n+ k6 @, }& {/ ]+ L* }26. return buffer.toString();
3 k: ?5 R V, ?1 r/ ^27. }
, P6 k1 O! t$ o- K. h& @/ g5 k' {+ cWhich is true? A. This code is NOT thread-safe.
8 C2 t. m; T, N- H p6 pB. The programmer can replace StringBuffer with StringBuilder with no ' E- h/ v' v9 m" ?1 u9 v9 t
other changes.
4 t- N, A# I# E0 tC. This code will perform well and converting the code to use
l: ^$ C% j% T, aStringBuilder will not enhance the performance. * K* y: v4 y: C7 u% O" ?1 g
D. This code will perform poorly. For better performance, the code ) x u. I @9 r
should be rewritten: return “<“+ this.name + “>”; Question 7 Given: 14. DateFormat df;
) m5 B/ I, G; Z8 E3 G15. Date date = new Date();
3 d- G5 f! |% l( |( a# e16. //insert code here M6 {; D0 e9 B; U8 V+ O
17. String s = df.format( date);
0 d. H5 N# y, x; KWhich two, inserted independently at line 16, allow the code to compile? (Choose two.) A. df= new DateFormat();
3 r6 r9 l7 b) Y6 J5 t, g$ zB. df= Date.getFormatter(); 4 K. m8 {, \" g9 p( \! f% M
C. df= date.getFormatter();
) o8 A) i1 {( ]2 xD. df= date.getDateFormatter(); - k% N3 H* }1 u( g) c6 U+ @
E. df= Date.getDateFormatter();
# v1 Q/ @3 B2 e7 L$ B. ZF. df= DateFormat.getInstance();
4 J' v9 G F( u# {# ]( T( jG. 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的执行流程。
* x) ~+ k% L( _ `5 U7 Z) V |