---
title: "JAVA软件工程师考证模拟试题3"
author: "icejadelove"
date: "2009-04-01T20:01:00Z"
tags: []
slug: "java-3"
draft: false
lastmod: "2009-04-01T20:01:00Z"
id: 572043
url: "https://jdkdev.iteye.com/blog/572043"
---

一、 判断（10分，每题1分）1、 System.gc()使Java虚拟机立刻执行垃圾回收。( 2)  
2、 JFrame是Frame的子类。( 1)  
3、 构造方法不可以被private访问修饰符修饰。（2）  
4、 String a=new String();与String b = new String()属于一个对像。(2)  
5、 FileChannel类位于java.io包中。（2）  
6、 接口是的成员变量必须显示的给出初始值。（1）  
7、 abstract不能与private、final、static共同使用。（1）  
8、 成员变量Boolean b;的默认值为false。（1）  
9、 代表Servlet生命周期的三个方法为：init、execute、destory。（2）  
10、HttpSession的销毁方法为destory。（2）  
二、单选(50分，每题1分)  
1、以下哪一个包是默认导入到Java类当中的(A)  
A、java.lang B、java.io  
C、java.nio D、java.long  
2、对于以下类：D  
public class Q2{  
public static void main(String\[] args){  
method();  
}  
private static void method(){  
System.out.println("Hello");  
}  
}  
A、编译失败,行3错误。 B、编译失败，行5错误。  
C、编译通过，无运行结果。 D、打印Hello。  
3、以下哪个是不正确的标识符：D  
A、Abc3 B、a\_bc\_3 C、\_3abc D、3\_abc  
4、局部变量boolean的默认值为：D  
A、false B、true C、null D、无默认值，必初始化  
5、对于Person p = new Person();，以下哪个能编译通过：C  
A、Object o = new Object(p); B、p = new Object();  
C、boolean b = p instanceof Object; D、boolean b = Object instanceof p;  
6、对于以下代码，运行的结果是：C  
public class Q6{  
int a=1;  
public static void main(String\[] args){  
i++;  
++i;  
System.out.println(i);  
}  
}  
A、2 B、3 C、编译出错 D、运行出错  
7、对于boolean b = (2&gt;=1 || 2/0&gt;=0)；b的结果为：C  
A、false B、运行出错，2/0抛出被0除错误  
C、true D、null  
8、以下能编译通过的for循环是：C  
A、for(int a,int b;a&lt;100;a++){} B、for(int a=0,int b = 0;a&lt;100;;){}  
C、for(int a=0,b=100;a&lt;50;a++,b--){}  
D、for(int a=0,b=100;a&lt;50,b&gt;50;a++,b--){}  
9、对于方法public void a(int a,String b){}以下哪一个是它正确的重载方法：C  
A、public int a(int a,String b){} B、protected void a(int a,String b){}  
C、public int a(int a,String\[] b){} D、public static void a(int a,String b){}  
10、以下哪一个不是受检查的异常类：C  
A、SQLException B、FileNotfoundException  
C、NullPointerException D、IOException  
11、将一个对像序列化的方式是，使此类实现以下哪一个接口：B  
A、Cloneable B、Serializable  
C、File D、Exception  
12、启动一个线程应使用线程类的：B  
A、run() B、start()  
C、go() D、thread()  
13、以下哪一个是正确初始化数组的方式：C  
A、int\[1] a = new int\[1]{1}; B、int\[] a = new int\[1]{1};  
C、int\[] a = new int\[]{1}; D、int\[1] a = new int\[1];  
14、以下代码输出的结果是：D  
public class Q14{  
int a = 20;  
static{  
int a = 10;  
}  
public static void main(String\[] args){  
Q14 q14 = new Q14();  
System.out.println(q14.a);  
}  
}  
A、编译出错，变量a重复定义 B、运行出错，q14.a不能确定是哪个变量a  
C、打印10 D、打印20。  
15、以下代码编译/运行结果为：C  
public class Q15{  
public static void main(String\[] args){  
int i=10;  
int j = 10;  
boolean b = false;  
if(b= i = = j){ //行6  
System.out.println("true");  
}else{  
System.out.println("false");  
}  
}  
A、在第6行编译出错 B、在第6行运行出错  
C、打印true D、打印false  
16、对于以下代码，哪个能编译通过：C  
public interface Animal{}  
public class Dog implements Animal{}  
public class Cat implements Animal{}  
A、Dog dog = new Cat(); B、Cat cat = new Animal();  
C、Animal cat = new Dog(); D、Cat c = new Cat(); Dog d = (Dog)c;  
17、对于以下类，那一行是正确的方法覆盖：D  
public class Q17{  
public void method(int a) throws Exception{}  
}  
public class Q17\_A{  
//在此输入正确的一行，  
}  
A、void method(int a){} B、void method(String a){}  
C、public int method(int a){} D、public void method(int a) throws IOException{}  
18、以下代码输出的值为：B  
public class Q18{  
Boolean\[] boo = new Boolean\[1];  
Q18(){  
System.out.println(boo\[0]);  
}  
public static void main(String\[] args){  
new Q18();  
}  
}  
A、false B、null C、true D、运行出错  
19、对于以下代码,运行结果为，即a的值为：A  
HashMap map = new HashMap();  
map.put("a","Hello");  
map.put("a","World");  
String a = map.get("a");  
A、最后一行编译出错 B、最后一行运行出错。  
C、a的值为Hello D、a的值为World  
20、以下哪个是jsp声明：B  
A、&lt;%= %&gt; B、&lt;%! %&gt; C、&lt;% %&gt; D&lt;%@ %&gt;  
21、在web项目的Filter中，通过以下哪个方法能获取web.xml配置的初始化参数：B  
A、doFilter B、init C、destory D、service  
22、在web项目中，日志级别由高到低为：C  
A、ERROR，FATAL，INFO，WARN，DEBUG  
B、FATAL，ERROR，INFO，WARN，DEBUG  
C、FATAL，ERROR，WARN，INFO，DEBUG  
D、WARN，ERROR，FATAL，INFO，DEBUG  
23、以下代码运行结果为：  
public class ForBar{  
public static void main(String\[] args) {  
int i=0,j=5;  
tp: for( ; ; i++) {  
for ( ; ; --j)  
if (i&gt;j) break tp;  
}  
System.out.println("i="+i+",j="+j);  
}  
}  
A 程序可以运行并打印"i=1, j=-1"  
B 程序可以运行并打印"i=1, j=4"  
C 程序可以运行并打印"i=0, j=-1"  
D第4行有个错误导致编译失败  
24、哪个事件类标识基于一个java.awt.component的按键动作?A  
A KeyEvent  
B. KeyDownEvent  
C. KeyPressEvent  
D. KeyTypedEvent  
25、如何得到文件"file.txt"的父目录名字?B  
A String name=File.getParentName("file.txt");  
B String name=(new File("file.txt")).getParent();  
C String name=(new File("file.txt")).getParentName();  
D String name=(new File(file.txt)).getParentFile();  
26、以下哪一个是正确处理事务的开始(conn是Connection对像的变量)：（ A ）  
A、conn.setAutoCommit(false); B、conn.autoCommit = false;  
C、conn.setCommit(false); D、conn.rollback();  
27、以下哪一个是ant中，将java文件编译成class文件的内置任务：( C )  
A、java B、complier C、javac D、mkclass  
28、以下哪一个是正确的将自定义标签导入到jsp页面上：( B )  
A、&lt;%@ page uri="/aa.tld" prefix="aa"%&gt;  
B、&lt;%@ taglib uri="/aa.tld" prefix="aa"%&gt;  
C、&lt;%@ include uri="/a.tld" prefix="aa"%&gt;  
D、&lt;% taglib uri="/a.tld" prefix="aa"%&gt;  
29、jsp页面上有以下语句&lt;% request.setAttribute("hello","HelloWorld");%&gt;，取出并正确输出到页面的方法为：C  
A、&lt;% String hello = request.getAttribute("hello")； out.print(hello)；%&gt;  
B、&lt;% String hello = request.getParameter("hello")；out.print(hello)；%&gt;  
C、&lt;% String hello = (String)request.getAttribute("hello")； out.print(hello)；%&gt;  
D、&lt;%=request.getAttribute("hello")； %&gt;  
30、以下是一段javascript脚本，请问最后i的值是多少：（ B ）  
function abc(){  
for(var i=0;i&lt;10;i++){  
}  
alert(i); //此处i的值是多少?  
}  
A、 运行出错，因为i在for之外不能访问  
B、 提示10 C、提示11 D、提示null或是undefained  
31、PreparedStatement或是Statement执行批处理executeBatch()后返回以下哪种数据类型：（ C ）  
A、int类型 B、boolean类型 C、int\[]类型 D、void类型  
32、看以下代码，说出结果：B  
public void a() throws Exception{  
try{  
int a = 0;  
int b = 0;  
int c = a/b; （行5）  
}catch(Exception e){  
e.printStackTrace();  
}  
}  
A：编译出错，不能try与throws共同使用 B：运行出错在第5行  
C：不打出任何结果 D：运行不出错。也不出结果。  
33、以下代码：B  
public void a(){  
try{  
int a = 0/0; //行3  
}catch(Exception e){//行4  
System.err.println("error");//出错,行5  
}catch(ArithmeticException e){//行6  
System.err.println("/ by zero");//被0除错误,行7  
}  
}  
A：编译出错在第4行。 B：编译出错在第6行。  
B：编译通过，打出errro D：编译通过，打出/ by zero.  
34、以下程序运行的结果为：C  
public void abc(){  
try{  
return;  
}catch(Exception e){//行4  
}finally{  
System.err.println("finally");//行6  
}  
}  
A：编译出错在第4行。 B：运行不打出任何结果  
C：运行打出finally D：编译出错在第6行。  
35、垃圾回收的时间说哪个正确:C  
A：System.gc()时执行 B：Runtime.getRuntime().gc()时执行  
C：不确定 D：CPU空闲时执行  
36、当子类中的内部类与父类中的内部类同名时：D  
A：子类复盖了父类的内部类 B：编译出错  
C：运行出错 D：各自拥有自己的内部类，互不影响  
37、对于以下代码，运行打印什么结果：D  
class RunHandler{  
public void run(){  
System.out.println("run");  
}  
}  
public class Tester{  
public static void main(String\[] args){  
Thread t = new Thread(new RunHandler());  
t.start();  
}  
}  
A：打印run B：不打印任何内容 C：运行出错 D：编译出错  
38、创建FileChannel的方式，以下哪一个是正确的：C  
A：FileChannel f = new FileChannel() B：FileChannel f = FileChannel.getChannel();  
C：FileChannel f = new InputStream("d:/a.txt").getFileChannel();  
D：FileChannel f = new FileOutputStream("d:/a.txt").getChannel();  
39、取消JFrame frame = new JFrame()的默认布居管理器的方式是：C  
A：frame.setLayout(""); B：frame.setLayout("none");  
C：frame.setLayout(null); D：frame.deleteLayout();  
40、以下哪一个是正确了使用BigDecimal b = new BigDecimal(10)对像的加方法：C  
Ａ：b = b +10 B：b = b.add(10)  
Ｃ：b = b.add(new BigDecimal(10); D：b +=10;  
41、JFrame是以下哪个类的子类：B  
A：JComponent B：Frame C：JPanel D：JApplet  
42、继承使用（ B）关键字，实现一个接口，使用（ ）关键字？  
A：implements、extends B：extends、implements  
C：extends、static D：implements、abstract  
43、方法public void abc(int a){}，以下哪一个是它的重载方法（ C）  
A：private void a(){} B：private int abc(int a){}  
C：public int abc(int a,String name){}  
D：private void abc(int a){}  
44、局部变量可以被下列哪一个修饰（ C）  
A：public B：synchronized  
C：final D：native  
45、double d = 0.0/0 的结果是：( D)  
A：正无穷大 B：不能编译 C：运行出错 D：NaN  
46、声明成员变量：public final String name;后，直接输出，结果为：（A）  
A：null B:NULL C：空 D:编译出错  
47、接口当中，所有的成员变量默认都是：C  
A：public abstract类型 B：public abstract final类型  
C：public static final类型 D：private类型  
48、接口中的方法默认都是：(C )  
A：protetcted类型。 B：public abstract final类型。  
C：public abstract类型 D：protected abstract类型  
49、在子类中，声明了同父类相同名称的成员变量，此时要引用父类的成员变量，可以使用关键字：（ C ）  
A：this B：abstract C：super D：parent  
50、在一个接口当中，只定义很多常量，不包含任何的方法，这种模式叫做：（B ）  
A：代理模式 B：常量接口模式 C：标识模式 D：适配器模式  
三、多选(30分，每题2分)  
1、this关键字可以使用在以下哪些方法中：AC  
A、构造方法 B、成员静态方法 C、成员非静态方法 D、static代码块  
2、以下哪些能编译通过：BC  
A、char a = 3C; B、long a = 123L;  
C、double a = 23.4D; D、float f = 23.4;  
3、对于String a = "Hello"; String b = "Hello";以下哪些对比为true值：ABCD  
A、boolean boo = (a==b); B、boolean boo = (a.equals(b));  
C、boolean boo = (a.toString()==b.toString());  
D、boolean boo = (a.toString().equals(b.toString());  
4、对于以下接中和类，哪些是正确的继承（实现）的代码：C  
public interface Q4\_1{}  
public interface Q4\_2{}  
public abstract class Q4\_3{}  
A、 public class Q4\_5 extends Q4\_1,Q4\_2,Q4\_3{}  
B、 public class Q4\_5 implements Q4\_1,Q4\_2,Q4\_3{}  
C、 public class Q4\_5 extends Q4\_3 implements Q4\_1,Q4\_2{}  
D、 public class Q4\_5 extends Q4\_1,Q4\_2 implements Q4\_3{}  
5、不能被子类覆盖的方法有：AD  
A、private方法 B、abstract方法  
C、public方法 D、final方法  
6、以下哪种类不能拥有了类：AD  
A、使用final修饰的类 B、使用static修饰的类  
C、使用final修饰的构造方法的类 D、使用private修饰构造方法的类  
7、以下哪些创建类的方式会调用类的构造方法：AC  
A、使用new关键字 B、调用对像的clone（）方法。  
C、使用Class.forName("SomeCls").newInstance();  
D、使用反序列化方式  
8、以下哪些是正确的：ABCD  
A、内部类可以定义成final类型。  
B、内部类可以定义成private类型。  
C、内部类可以实现多个接口。  
D、内部类可以访问外部类所有final类型的变量。  
9、以下Servlet的哪些方法会响应http的get请求：AC  
A、service B、doPost  
C、doGet D、execute  
10、以下哪些是JavaBean的特点：BCAD  
A、拥有公开的构造方法 B、所有的成员变量为private类型  
C、提供getters和setters方法 D、对于boolean类型，提供isXxxx方法  
11、哪两个直接导致线程停止执行?DB  
A 从一个同步块跳出  
B 基于一个对象调用wait方法  
C基于一个对象调用notify方法  
D 基于一个线程对象调用setPriority方法  
12、哪两个接口提供用键值对存储数据的功能? (2个正确答案)AD  
A Map  
B Set  
C SortedSet  
D SortedMap  
13、哪个正确创建整型二维数组?(3个答案)BCD  
A. int a\[]\[] = new int\[]\[];  
B. int a\[]\[] = new int\[10]\[10];  
C. int \[]\[]a = new int\[10]\[10];  
D. int \[]a\[] = new int\[10]\[10];  
14、对于jsp声明说法正确的是：DC  
A、在jsp声明中，只能声明变量 B、在jsp声明中，只能声明方法  
C、在jsp声明中，可以声明静态变量  
D、在jsp声明时，即可以声明方法、也可以声明变量  
15、在以下代码横线处加入哪些异常可以让程序编译通过：( )  
pulic void query() throws \_\_\_\_\_ACB\_\_\_\_\_\_\_\_\_\_\_\_\_{  
Statement st = Conn.getConn().createStatement(); //获取数据操作对像  
ResultSet rs = st.executeQuery("select * from stud");  
}  
A、Exception B、Throwable  
C、SQLException D、RuntimeException

四、综合题(10分，每题10分)  
请书写一个字符过虑器Filter，对某个web项目中的所有url都应用GBK格式的编码。并正确配置到web.xml中(10分)

&lt;!-- 配置过滤器 --&gt;  
&lt;filter&gt;  
&lt;filter-name&gt;SetCharacterEncoding&lt;/filter-name&gt;  
&lt;filter-class&gt;util.SetEncodingFilter&lt;/filter-class&gt;  
&lt;init-param&gt;  
&lt;param-name&gt;encoding&lt;/param-name&gt;  
&lt;param-value&gt;utf-8&lt;/param-value&gt;  
&lt;/init-param&gt;  
&lt;/filter&gt;  
&lt;filter-mapping&gt;  
&lt;filter-name&gt;SetCharacterEncoding&lt;/filter-name&gt;  
&lt;url-pattern&gt;/\*&lt;/url-pattern&gt;  
&lt;/filter-mapping&gt;

package util;  
import javax.servlet.Filter;  
import javax.servlet.FilterConfig;  
import javax.servlet.ServletException;  
import javax.servlet.ServletRequest;  
import javax.servlet.ServletResponse;  
import javax.servlet.FilterChain;  
import java.io.IOException;

/\**  
\* Filter that sets the character encoding to be used in parsing the  
\* incoming request, either unconditionally or only if the client did not  
\* specify a character encoding. Configuration of this filter is based on  
\* the following initialization parameters:  
\*  
\* encoding - The character encoding to be configured  
\* for this request, either conditionally or unconditionally based on  
\* the ignore initialization parameter. This parameter  
\* is required, so there is no default.  
\*  
\* ignore - If set to "true", any character encoding  
\* specified by the client is ignored, and the value returned by the  
\* selectEncoding() method is set. If set to "false,  
\* selectEncoding() is called only if the  
\* client has not already specified an encoding. By default, this  
\* parameter is set to "true".  
\*  
\* Although this filter can be used unchanged, it is also easy to  
\* subclass it and make the selectEncoding() method more  
\* intelligent about what encoding to choose, based on characteristics of  
\* the incoming request (such as the values of the Accept-Language  
\* and User-Agent headers, or a value stashed in the current  
\* user's session.  
\*/

public class SetEncodingFilter implements Filter {

// ---------------------- Instance Variables

/\**  
\* The default character encoding to set for requests that pass through this filter.  
\*/  
protected String encoding = null;

/\**  
\* The filter configuration object we are associated with.  
\* If this value is null, this filter instance is not currently configured.  
\*/  
protected FilterConfig filterConfig = null;

/\**  
\* Should a character encoding specified by the client be ignored?  
\*/  
protected boolean ignore = true;

// ---------------------- Public Methods

/\**  
\* Place this filter into service.  
\*  
\* @param filterConfig The filter configuration object  
\*/  
public void init(FilterConfig filterConfig) throws ServletException {  
this.filterConfig = filterConfig;  
this.encoding = filterConfig.getInitParameter("encoding");  
String value = filterConfig.getInitParameter("ignore");  
if (value == null)  
this.ignore = true;  
else if (value.equalsIgnoreCase("true"))  
this.ignore = true;  
else if (value.equalsIgnoreCase("yes"))  
this.ignore = true;  
else  
this.ignore = false;  
}

/\**  
\* Select and set (if specified) the character encoding to be used to  
\* interpret request parameters for this request.  
\*  
\* @param request The servlet request we are processing  
\* @param result The servlet response we are creating  
\* @param chain The filter chain we are processing  
\*  
\* @exception IOException if an input/output error occurs  
\* @exception ServletException if a servlet error occurs  
\*/  
public void doFilter(ServletRequest request,  
ServletResponse response,  
FilterChain chain) throws IOException, ServletException{  
request.setCharacterEncoding("utf-8");

response.setCharacterEncoding("utf-8");  
chain.doFilter(request, response);  
}

/\**  
\* Take this filter out of service.  
\*/  
public void destroy() {  
this.encoding = null;  
this.filterConfig = null;  
}

// ------------ Protected Methods

}