java软件工程师笔试题目(II) 规则: 1. 时间:40分钟 2. 个人独立完成,不能使用手机等上网上查询。如果被发现作弊,则零分。 3. 为了环保和节约纸张,请在答题卡上填写答案 一、不定项选择题(每题5分) Question 1 Given: 11. public class Test {
0 k9 a* }: b8 ^% m12. public static void main(String [] args) {
8 ^* I* }& U! T13. int x =5; - b5 c7 _2 Y; N. M" u! D
14. boolean b1 = true;
. t' H+ U9 J0 h! K/ e15. boolean b2 = false;
. J5 Z' E7 X/ k17.if((x==4) && !b2)
; ^* \. a) Z$ x7 C% G1 p5 M% {18. System.out.print(”l “); ' _* I& w- j8 B: C
19. System.out.print(”2 “);
! K. j/ Z8 n: ^* I* \3 D4 f20. if ((b2 = true) && b1)
' ]+ R2 \& f- z6 @, O# K( o+ [2 N21. System.out.print(”3 “);
+ u$ n9 j6 o8 }% c22. } d7 }# Y+ G! g3 J/ [& P' t
23. } 1 R3 a+ K! W3 E& \! ~- x
What is the result?
) i. l9 o* h8 T! d9 e( HA. 2 6 R6 b1 |+ m( V5 ?6 B
B. 3
$ m% p+ n# E$ @# C; r- G: |- tC. 1 2 5 D) r4 ^; d" a# e5 b2 ]
D. 2 3 : c/ O" k0 q1 d1 b9 |% x
E. 1 2 3 : R l, H" a6 f5 L: L
F. Compilation fails.
2 T$ I: `+ A+ @, c2 q. [G. Au exceptional is thrown at runtime. Question 2 Assume that country is set for each class. Given: 10. public class Money { 8 Q7 k C' K; ?# n4 n
11. private String country, name; , j1 ~" m& t _% x6 @) y( P
12. public String getCountry() { return country; }
/ N& W+ O) [8 V& u7 p3 X13.} and: 24. class Yen extends Money {
6 k* A+ L6 I8 T25. public String getCountry() { return super.country; } : l) k. C( p. v" X* A
26. } 0 R% ~* I- D- u9 w
27.
3 W9 ^1 z# S, {* _8 W! @3 M1 N! n/ B28. class Euro extends Money {
2 M# d6 b! k; L' ?29. public String getCountry(String timeZone) {
9 i) q+ c8 u; s6 b, S30. return super.getCountry();
; a5 T) [2 l6 ^. Y* ?31. }
x, Q8 k0 z6 C4 c+ g0 k32. } 8 e( _ v t8 y: p
Which two are correct? (Choose two.) A. Yen returns correct values.
* \% }; J) Q4 ^. l/ X+ b3 B" B' fB. Euro returns correct values. % ]& |+ j" f8 j
C. An exception is thrown at runtime.
8 @) C7 o3 x9 f9 v6 |D. Yen and Euro both return correct values.
$ {$ B7 _7 c% QE. Compilation fails because of an error at line 25.
8 B" X0 V l1 G) D0 iF. Compilation fails because of an error at line 30. Question 3 Given: 1. class TestA {
3 a9 R+ W& \% ?3 e8 ^0 n2. public void start() { System.out.println(”TestA”); }
* ~+ a+ R. P4 s9 l7 c5 ~ B3. } ' A& @( O7 S% }9 L" [7 Z; [
4. public class TestB extends TestA { " W6 e% K1 d5 V6 Z5 y; H" \
5. public void start() { System.out.println(”TestB”); } % P/ @) ?% K0 `5 C$ J4 b
6. public static void main(String[] args) {
/ L: x, u9 P9 Y2 L4 i% u" B/ g# U7. ((TestA)new TestB()).start();
& s/ ]/ y; @4 k. W: f8. }
, Z* {# I9 o% _& I9. }
, \) R: d6 p7 c' sWhat is the result? A. TestA / O2 Q8 {( n/ v; y# M @
B. TestB
# I; y. t: [) fC. Compilation fails. : c( O) h5 ?* m
D. An exception is thrown at runtime. Question 4 Given: 11. public static void main(String[] args) { # F: V: Q& l; _5 `( b
12. String str = “null’; - r* ~ T9 H# b3 n5 C: l
13. if (str == null) {
0 i% U) u9 M6 f Q2 h/ V6 {14. System.out.println(”null”); ) A- R7 E( y0 q
15. } else (str.length() == 0) {
9 {, V% T8 Y5 O2 z4 E0 l% W16. System.out.println(”zero”); ) I; l6 j$ K- D3 _- C$ \
17. } else { 7 F' B# k% X5 I W- L( N! n+ n& B5 ]
18. System.out.println(”some”);
' a, O# \1 ~2 @6 V19. }
, C. \+ U/ a" H+ L) `2 m3 s2 x20. } 8 y5 C6 X) ^/ g T, S& x
‘What is the result? A. null ; e. }- ?7 ^0 t7 _- }- }
B. zero
! V3 b) d% H3 C4 Z+ dC. some ; t3 K4 O4 ^5 v2 [0 \* w( |6 E
D. Compilation fails.
0 N. o7 E2 S2 O1 k* [, k. ]! {E. An exception is thrown at runtime. Question 5 Given: 33. try { / }& c. z% S: c* k, r# s7 L; f0 B
34. // some code here
: S; w0 i; L8 l2 S9 Z4 u: N/ t35. } catch (NullPointerException e1) { " k8 {+ Y, c: k+ t6 Z
36. System.out.print(”a”);
* k9 m/ [3 _* u; e+ y37. } catch (RuntimeException e2) { ( J a" N$ K+ N; K
38. System.out.print(”b”); / u) W# U2 ^% r" T0 f N
39. } finally {
. r2 @" f, C! `0 U. r40. System.out.print(”c”);
/ h# m5 l, @' q# O/ G41. } 9 o: e$ s! O; ]4 m
What is the result if a NullPointerException occurs on line 34? 6 z4 S! m9 M' x
A. c 5 ]0 I) B$ Q- Y% i8 I# N$ | i
B. a
/ t1 u3 p: w, \$ ~5 v8 z2 i F3 bC. ab
/ N8 R/ \6 r4 i" p4 W- f5 `8 wD. ac
( |- a0 h% h2 ^7 G. ZE. bc a4 M; [/ H& ?. ? \
F. abc Question 6 Given this method in a class: 21. public String toString() { 0 ~ r- f& C' j3 Z
22. StringBuffer buffer = new StringBuffer(); 7 c8 b9 P' G- Q5 |
23. buffer.append(’<’);
2 T6 B+ N4 T6 j! a2 N& U/ H6 t24. buffer.append(this.name); - C o: d# o+ R+ j
25. buffer.append(’>’); : z: H; t& F' S. L1 V3 T7 ^, n
26. return buffer.toString(); / Z% j& j, ^$ I+ `5 E3 ]/ t
27. }
* K. R1 a- p0 t& N' ]0 @# ^% @Which is true? A. This code is NOT thread-safe. " p) E& J1 b" Y
B. The programmer can replace StringBuffer with StringBuilder with no
2 t" N* Z1 g3 d. R& i) xother changes.
8 Z: q( U% p, j9 W3 [% G: g, Y0 ~C. This code will perform well and converting the code to use ; i9 j {0 g$ N, ~
StringBuilder will not enhance the performance.
* `$ G6 J5 d" A3 qD. This code will perform poorly. For better performance, the code
# y2 Y) u1 S$ q# n, w. U/ [should be rewritten: return “<“+ this.name + “>”; Question 7 Given: 14. DateFormat df;
- d/ X% ~3 }& M3 [5 A9 z+ f15. Date date = new Date(); ; C% l# Z* {0 z6 m
16. //insert code here " {/ t! L- C# x( Z" ^3 H
17. String s = df.format( date);
& U T, `1 V; b3 B, Y1 r$ w9 u MWhich two, inserted independently at line 16, allow the code to compile? (Choose two.) A. df= new DateFormat(); ; c& L7 J1 P2 h8 B$ x: m. L2 [5 g, q! p
B. df= Date.getFormatter(); & K6 n# D4 C. ?- e( p0 c. G
C. df= date.getFormatter();
' P- \. G: l1 s$ bD. df= date.getDateFormatter(); ' T1 @2 f9 _. j. L9 f
E. df= Date.getDateFormatter();
, D' C& |& y, T6 }F. df= DateFormat.getInstance(); 9 p% a& [ L5 J8 o% g1 p
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的执行流程。
: J/ A8 k% J+ W* G* K6 K4 B$ d% n |