JAVA程序员笔试题目与答案

JAVA程序员笔试题目与答案
JAVA程序员笔试题目与答案

1.Given:

Integer i = new Integer (42);

Long l = new Long (42);

Double d = new Double (42.0);

Which two expressions evaluate to True?

A. (i == 1)

B. (i == d)

C. (d == 1)

D. (i.equals (l))

E. (d.equals (l))

F. (i.equals (42))

G. none of above

Answer:

2. Given:

public class Foo {

public static void main (String [] args) {

StringBuffer a = new StringBuffer("A");

StringBuffer b = new StringBuffer ("B");

operate (a,b);

System.out.println(a + "," +b);

}

static void operate(StringBuffer x, StringBuffer y) {

x.append(y);

y = x;

}

}

What is the result?

A. The code compiles and prints “A,B”.

B. The code compiles and prints “A,A”.

C. The code compiles and prints “B,B”.

D. The code compiles and prints “AB,B”.

E. The code compiles and prints “AB,AB”.

F. The code does not compile because “+” cannot be overloaded for StringBuffer.

Answer:

3.Given:

class BaseClass {

private float x = 1.0f ;

protected float getVar() {return x;}

}

class Subclass extends BaseClass {

private float x = 2.0f;

//insert here

}

Which two are valid examples of method overriding?

A. float getVar() { return x;}

B. public float getVar() { return x;}

C. public double getVar() { return x;}

D. protected float getVar() { return x;}

E. public float getVar(float f) { return f;}

Answer:

4. Which of the following are methods of the Runnable interface

A) run

B) start

C) yield

D) stop

Answer:

5. Which of the following are legal statements?

A) float f=1/3;

B) int i=1/3;

C) float f=1.01;

D) double d=999d;

Answer:

6. Given:

public class test(

public static void main(string[] args){

String foo = args[1];

String baz = args[2];

String bax = args[3];

}

}

And the command line invocation:

Java Test red green blue

What is the result?

A. baz has the value of “”

B. baz has the value of null

C. baz has the value of “red”

D. baz has the value of “blue”

E. bax has the value of “green”

F. the code does not compile

G. the program throws an exception

Answer:

7. Which of the following statements are true?

A) The garbage collection algorithm in Java is vendor implemented

B) The size of primitives is platform dependent

C) The default type for a numerical literal with decimal component is a float.

D) You can modify the value in an Instance of the Integer class with the setValue method Answer:

8. Given:

int i = 1, j = 10;

do {

if(i++ > --j) continue;

} while(i<5);

After execution, what are the values for i and j?

A. i = 6 and j= 5

B. i = 5 and j= 5

C. i = 6 and j= 4

D. i = 5 and j= 6

E. i = 6 and j= 6

Answer:

9. Given:

import java.io.IOException;

public class ExceptionTest {

public static void main (String[] args){

try {

methodA();

} catch (IOException e) {

System.out.println("Caught IOException");

} catch (Exception e) {

System.out.println("Caught Exception");

}

}

public void methodA(){

throw new IOException();

}

}

What is the result?

A. The code will not compile.

B. The output is: caught exception.

C. The output is: caught IOException.

D. The program executes normally without printing a message.

Answer:

10. Given:

public class Test {

public static String output = "";

public static void foo(int i) {

try {

if(i==1) {

throw new Exception ();

}

output += "1";

} catch(Exception e) {

output += "2";

return;

} finally {

output += "3";

}

output += "4";

}

public static void main (String args[]){

foo(0);

foo(1);

//line 24

}

}

What is the value of the variable output at line 24? Answer:

11. Given:

public class Foo implements Runnable { //line 1 public void run (Thread t) { //line 2

System.out.println("Running.");

}

public static void main (String[] args) {

new Thread(new Foo()).start();

}

}

What is the result?

A. An exception is thrown

B. The program exists without printing anything

C. An error at line 1 causes compilation to fail.

D. An error at line 2 causes the compilation to fail.

E. “Running” is printed and the program exits Answer:

12. Given:

ClassOne.java

package com.abc.pkg1;

public class ClassOne {

private char var = …a?;

char getVar() { return var; }

}

ClassTest.java

package com.abc.pkg2;

import com.abc.pkg1.ClassOne;

public class ClassTest extends ClassOne {

public static void main(String[]args) {

char a = new ClassOne().getVar(); //line 5

char b = new ClassTest().getVar(); //line 6

}

}

What is the result?

A. Compilation will fail.

B. Compilation succeeds and no exceptions are thrown.

C. Compilation succeeds but an exception is thrown at line 5 in ClassTest.java.

D. Compilation succeeds but an exception is thrown at line 6 in ClassTest.java.

Answer:

13. Which is a valid identifier?

A. false

B. default

C. _object

D. a-class

Answer:

14 If you run the code below, what gets printed out?

String s=new String("Bicycle");

int iBegin=1;

char iEnd=3;

System.out.println(s.substring(iBegin,iEnd));

A) Bic

B) ic

C) icy

D) error: no method matching substring(int,char) Answer:

15 What will happen when you attempt to compile and run the following code public class MySwitch{

public static void main(String argv[]){

MySwitch ms= new MySwitch();

ms.amethod();

}

public void amethod(){

int k=10;

switch(k){

default: //Put the default at the bottom, not here

System.out.println("This is the default output");

break;

case 10:

System.out.println("ten");

case 20:

System.out.println("twenty");

break;

}

}

}

A) None of these options

B) Compile time error target of switch must be an integral type

C) Compile and run with output "This is the default output"

D) Compile and run with output of the single line "ten"

Answer:

第二部分:J2EE部份

1.简述J2EE Architecture。

2.简述JSP在Web Container中的生命周期。

3.如何使用数据库连接池?有什么好处?

4.列举您在开发中用到的一些模式与框架。模式与框架有什么区别吗? 5.列举您知道的几种持久化技术。

6.什么是SOA? WebServices与SOA有什么样的关系?

第三部分:通用知识

1.简述OSI七层协议。IP/TCP/UDP/HTTP/SMTP分别属于哪一层?

2.简述TMN,TOM,eTOM, NGOSS四个模型之间的关系。

3.什么是数据库系统?列举几个常见的数据库系统。

4.请简单描述软件开发过程的主要阶段。

5.请将下面一段文字翻译成中文。

An enterprise service bus (ESB) is a pattern of middleware that unifies and connects services, applications and resources within a business. Put another way, it is the framework within whic

h the capabilities of a business? applications are made available for reuse by other applications

throughout the organization and beyond. The ESB is not a new software product —it?s a new way of looking at how to integrate applications, coordinate resources and manipulate informa tion. Unlike many previous approaches for connecting distributed applications, for example R PC or distributed objects, the ESB pattern enables the connection of software running in parall el on different platforms, written in different programming languages and using different prog ramming models.

答案

第一部分:JA V A语言基础(3*15=45)

1 G

2 D

3 BD

4 A

5 ABD

6 G

7 A

8 D

9 A 10 13423

11 C 12 A 13 C 14 B 15 A

第二部分:J2EE部份简答题(5*6=30)

1.简述J2EE Architecture。

要点:

a) J2EE是使用Java技术开发企业级应用的一组标准规范:JSP/Servlet/JDBC/JMS XML/EJB/JSF/WebServices等;

b) J2EE是一个分布的多层应用体系架构:客户端,Web层,业务层,数据层。

2.简述JSP在Web Container中的生命周期。

要点:

a) 当一个请求映射到一个Jsp页面时,由一个特殊的servlet来处理,该servlet首先检查一下对应的JSP页面有没有改动,如果有变动则将该JSP页面转换为servlet类并编译这个类。

b) 一旦页面被解释并执行,JSP页面的servlet的生命周期大部分与servlet类似:

i. 如果JSP页面的servlet实例不存在,容器将:

1) 载入JSP的servlet class

2) 实例化一个servlet class

3) 通过调用jspInit 方法实例化servlet

ii. 调用_jspService方法,传递请求及响应对象。

iii. 如果容器需要移除JSP页面的servlet,就调用jspDestroy方法。

3.如何使用数据库连接池?有什么好处?

要点:

一些商用的WEB应用服务器如Bea的WebLogic和IBM的WebSphere等提供了连接池的机制;另外,我们还可以使用开源的Jakarta DBCP项目配置数据库连接池。

主要好处:

a) 数据库连接池的基本思想就是为数据库连接建立一个“缓冲池”。预先在缓冲池中放入一定数量的连接,当需要建立数据库连接时,只需从“缓冲池”中取出一个,使用完毕之后再放回去,解决数据库连接的频繁建立﹑释放所造成的性能问题。

b) 我们可以通过设定连接池最大连接数来防止系统无尽的与数据库连接。

c) 更为重要的是我们可以通过连接池的管理机制监视数据库的连接的数量﹑使用情况,为系统开发﹑测试及性能调整提供依据。

4.列举您在开发中用到的一些模式与框架。模式与框架有什么区别吗?

要点:

模式:MVC模式,IoC/DI模式,ServiceLocator模式等

框架:Struts,Spring等。

主要区别:

(一) 设计模式是对在某种环境中反复出现的问题以及解决该问题的方案的描述,它比框架更抽象。

(二) 框架可以用代码表示,也能直接执行或复用,而对模式而言只有实例才能用代码表示;设计模式是比框架更小的元素,一个框架中往往含有一个或多个设计模式,框架总是针对某一特定应用领域,但同一模式却可适用于各种应用。

(三) 可以说,框架是软件,而设计模式是软件的知识。

5.列举您知道的几种持久化技术。

要点:

Hibernate,JDO,iBatis,Castor等

6.什么是SOA? WebServices与SOA有什么样的关系?

要点:

SOA是Service-Oriented Architecture的缩写,面向服务架构,SOA是一种架构模型,它可以根据需求通过网络对松散耦合的粗粒度应用组件进行分布式部署、组合和使用。服务层是SOA的基础,可以直接被应用调用,从而有效控制系统中与软件代理交互的人为依赖性。SOA的几个关键特性:一种粗粒度、松耦合服务架构,服务之间通过简单、精确定义接口进行通讯,不涉及底层编程接口和通讯模型。

WebServices与SOA关系:

1) SOA是一种体系架构模式,WebServices是技术规范;

2) WebServices是SOA使用的一种主要技术。

第三部分:通用知识简答题(5*5=25)

1.简述OSI七层协议。IP/TCP/UDP/HTTP/SMTP分别属于哪一层?

要点:

物理层、数据链路层、网络层、传输层、会话层、表示层和应用层。

IP:网络层

TCP/UDP:传输层

HTTP/SMTP:应用层

2.简述TMN,TOM,eTOM, NGOSS四个模型之间的关系。

要点:

TMN->TOM->eTOM->NGOSS

3.什么是数据库系统?列举几个常见数据库系统。

要点:

1) 数据库系统是一个实际可运行的存储、维护和应用系统提供数据的软件系统,是存储介质、处理对象和管理系统的集合体。它通常由软件、数据库和数据管理员组成。其软件主要包括操作系统、各种宿主语言、实用程序以及数据库管理系统。数据库由数据库管理系统统一管理,数据的插入、修改和检索均要通过数据库管理系统进行。

2) 开源数据库系统有:HSQLDB、MySQL、PostgreSQL等

3) 商业数据库系统包括:Oracle10g、DB2、Sysbase、Informix、MS SQL等。

4.请简单描述软件开发过程的主要阶段。

要点:

计划,分析,设计,编码,测试,维护等。

5.请将下面一段文字翻译成中文。

An enterprise service bus (ESB) is a pattern of middleware that unifies and connects services, appl ications and resources within a business. Put another way, it is the framework within which the ca pabilities of a business? applications are made available for reuse by other applications throughout the organization and beyond. The ESB is not a new software product —it?s a new way of looking at how to integrate applications, coordinate resources and manipulate information. Unlike many pr evious approaches for connecting distributed applications, for example RPC or distributed objects, the ESB pattern enables the connection of software running in parallel on different platforms, writ ten in different programming languages and using different programming models.

企业服务总线……

相关主题
相关文档
最新文档