java软件工程师笔试题目(II) 规则: 1. 时间:40分钟 2. 个人独立完成,不能使用手机等上网上查询。如果被发现作弊,则零分。 3. 为了环保和节约纸张,请在答题卡上填写答案 一、不定项选择题(每题5分) Question 1 Given: 11. public class Test {
( z; u% O. w J) l$ \/ v g12. public static void main(String [] args) {
, M+ e9 U6 _3 B* b8 a. Y13. int x =5; . v% w4 P: f5 U) h" M/ _6 S1 {/ j
14. boolean b1 = true; * N/ l3 n9 L! T6 z+ g# R
15. boolean b2 = false;
2 A. v9 r& f% ^17.if((x==4) && !b2) $ b$ O1 T; Y! H6 b
18. System.out.print(”l “); # j E8 Q2 s7 U9 X5 T# }
19. System.out.print(”2 “); - h) i7 p0 f" h0 Y/ M, g+ K: S8 x
20. if ((b2 = true) && b1) 6 @0 h' n7 r. m* Q# t: v$ r
21. System.out.print(”3 “);
1 r- O5 ~) }! ~& `7 F22. }
- o+ ^& H) k. G- n) G1 d m23. } 8 o; j G6 Y Q3 ]4 R* Q
What is the result?
% c( \2 _6 t' B6 wA. 2 $ @& {3 [! ^' m/ W
B. 3
& `3 N; o4 I+ o+ y- s A! A* HC. 1 2
J* _ P5 n$ K9 h" i- d xD. 2 3 + x' m; X0 k6 O3 e/ I& W( X
E. 1 2 3
* }+ J% s* u% C4 `0 RF. Compilation fails.
. |! b8 a% O: ]- s$ x- i3 _' I2 O8 \G. Au exceptional is thrown at runtime. Question 2 Assume that country is set for each class. Given: 10. public class Money {
" b" q+ `4 B4 ]3 e# }; E: x0 ^11. private String country, name;
+ I& L2 ]5 J7 ?! h) M12. public String getCountry() { return country; }
/ s' ]' }) x3 O0 a13.} and: 24. class Yen extends Money { 2 l2 y, q: O3 }+ k; G3 Z
25. public String getCountry() { return super.country; }
% ?8 S! V+ B0 H26. }
( V/ V7 `0 Q, ^6 T1 j" V27.
) {( X* _& r) W3 l( D3 @28. class Euro extends Money {
8 F+ c' A' \- X4 [2 R/ j J29. public String getCountry(String timeZone) {
8 E: O4 o5 `" y/ Z F$ o9 |4 T1 h30. return super.getCountry();
' {" O Z8 r; u8 ~0 k! ?31. }
% u o3 \3 K6 t* \: t32. }
" A9 K" G( _: V& J$ IWhich two are correct? (Choose two.) A. Yen returns correct values. % S4 P- O3 ]; P
B. Euro returns correct values. 6 x7 t4 r4 }- a$ x! `4 W
C. An exception is thrown at runtime.
; ^* B/ @3 V2 f: ^' j6 fD. Yen and Euro both return correct values.
, F% h6 i: P% ^9 w- z4 VE. Compilation fails because of an error at line 25.
8 E" n3 Z$ O% CF. Compilation fails because of an error at line 30. Question 3 Given: 1. class TestA {
+ Z) q, e! s, W2. public void start() { System.out.println(”TestA”); }
1 @8 U1 h6 \; F3. } , A3 t" f7 ?9 t3 f+ b3 N# n4 w
4. public class TestB extends TestA { & C$ i+ b: ^% l
5. public void start() { System.out.println(”TestB”); } # {0 O! V! Q ?0 A6 @
6. public static void main(String[] args) {
& v* L4 E8 |5 g i5 }' b7. ((TestA)new TestB()).start(); ' T; y P6 q' y/ u. M; L
8. } & a* S7 X, R, g, P" M
9. }
7 e* T+ j1 e, U, R! n/ XWhat is the result? A. TestA
# e) S+ K/ u. uB. TestB 3 T0 Z S' o& g* k( \
C. Compilation fails.
O/ g& O, q' b( C. A6 ~( WD. An exception is thrown at runtime. Question 4 Given: 11. public static void main(String[] args) { , F, w8 L6 E' N1 v+ i; L
12. String str = “null’; & P( u) h. m2 c @
13. if (str == null) {
& v/ b3 C- `9 H3 o8 W14. System.out.println(”null”); : I. S* G) [6 l1 }2 h y0 I
15. } else (str.length() == 0) {
6 D0 J4 F* H9 h0 \- c$ C16. System.out.println(”zero”); 9 L! w1 I0 r- L$ s8 g+ A; o7 j
17. } else { 6 Z0 N) Q. `' m. c( T8 b; c4 h
18. System.out.println(”some”);
6 c: O/ D0 a9 z! J/ y0 t19. } , u$ h- n3 m$ M' G
20. }
' i1 @0 E6 Z; B. Y7 k& F% Z. y‘What is the result? A. null
9 m6 h2 f9 J# M$ N+ n+ ?# wB. zero 8 ~2 r& }$ f. x- X' v& t
C. some ) A0 k4 U+ I6 M: @; P& w
D. Compilation fails. 8 y J7 d: `% L5 P1 d
E. An exception is thrown at runtime. Question 5 Given: 33. try { ! f: u* z) @3 C# y [/ \
34. // some code here 4 \, o. w' L% }& z* U4 L+ b
35. } catch (NullPointerException e1) { 5 K1 X% u: ]9 A( D4 K
36. System.out.print(”a”);
2 |5 _( F+ d; m" _" G" z37. } catch (RuntimeException e2) {
0 h8 ?' A) A1 s2 f38. System.out.print(”b”);
; E: D) e& h( h$ E O0 i39. } finally {
, G' N* e; ^& T3 ?( K- X40. System.out.print(”c”); 4 f" q" l8 Q0 r6 l W8 O6 ~
41. }
1 l& B$ n6 d' k$ CWhat is the result if a NullPointerException occurs on line 34? 9 c B Z7 M6 b' g
A. c 7 E9 ?+ c4 C7 D5 {3 P
B. a 2 D# Z r l- A4 I( R4 `: _
C. ab ! Z7 r; S* I4 G/ R! U
D. ac
4 h* c% t$ T* Q' k3 L) v' w* k: }E. bc , e+ T. X t5 C
F. abc Question 6 Given this method in a class: 21. public String toString() {
e' e: q9 Q9 q u22. StringBuffer buffer = new StringBuffer();
/ m, |' F0 J; ?- Q' R3 F. M6 t4 ^23. buffer.append(’<’);
8 y, q: h {" }: L24. buffer.append(this.name);
+ C% h# o9 o A$ [25. buffer.append(’>’); - Z. ~& [3 h9 a. Z- g
26. return buffer.toString(); 4 f" m+ C! n) t7 B2 c1 O& G
27. }
) K& v. b4 G: U) }" KWhich is true? A. This code is NOT thread-safe. 8 k. e& f/ S) t
B. The programmer can replace StringBuffer with StringBuilder with no
6 l9 S- [; w# e8 oother changes. & e5 E, A* j+ \8 s: S
C. This code will perform well and converting the code to use
. p d) z, C0 t7 ~/ t# b! i) kStringBuilder will not enhance the performance. " V4 J, _- h5 k
D. This code will perform poorly. For better performance, the code - {. h- v" a# H
should be rewritten: return “<“+ this.name + “>”; Question 7 Given: 14. DateFormat df; 6 O# n/ b' Z; I1 T" v6 C
15. Date date = new Date();
% }4 q# p: K* h3 \7 }; T16. //insert code here . z9 }$ L6 L; `! G8 Y! w
17. String s = df.format( date);
9 X" Y; G. L9 L$ B3 @Which two, inserted independently at line 16, allow the code to compile? (Choose two.) A. df= new DateFormat();
2 Q3 ?0 X8 {4 j( @# J- |* dB. df= Date.getFormatter();
6 c" e9 {4 N; G: [! jC. df= date.getFormatter();
+ j$ e4 w \2 J, Z! _6 v: b, {* RD. df= date.getDateFormatter();
4 W# ~; U- V1 n* Y6 m. iE. df= Date.getDateFormatter(); ( X( d+ z" V% ?
F. df= DateFormat.getInstance(); . c% M+ o; g y3 a$ O9 s9 F- T& E
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的执行流程。 L" q& t3 T1 o5 z: @# _8 D5 z+ q7 k
|