设为首页 加入收藏

TOP

TCSD标准考试 JAVA试题 (100分制,考试时间150分钟)
2014-11-02 19:30:04 来源: 作者: 【 】 浏览:39
Tags:TCSD 标准 考试 JAVA 试题 100分制 考试时间 150分钟

一、 单选(35小题共70.0分)
1.


在Oracle中,现有Student表,其中包括学号stuId,姓名stuName,成绩stuGrade,现要查询成绩为80分的学生姓名,并且结果按照学号降序排列,下面查询语句正确的是()。
A.


SELECT stuName FROM student WHERE stuGrade=80 ORDER BY stuId
B.


SELECT stuName FROM student WHERE stuGrade=80 ORDER BY stuId DESC
C.


SELECT stuName FROM student WHERE stuGrade like 80 GROUP BY stuId
D.


SELECT stuName FROM student WHERE stuGrade=80 GROUP BY stuId DESC
2.
关于Java线程说法错误的是()。
A.


创建线程的有2种方式,方式1是继承Thread类,方式2是实现 Runnable 接口
B.


解决线程安全使用问题 synchronized关键字,使得同一时间只有一个线程执行该关键字限定的代码段
C.


线程间通信所使用的方法有,wait,notify,notifyAll,它们都是 Thread 的方法
D.


Java线程包括5个状态,线程的创建,可运行,运行,阻塞和消亡
3.


一个VIEW被以下语句创建,请问在该VIEW上可进行操作是:()。


CREATE VIEW usa_states


AS SELECT *FROM state


WHERE cnt_code =1


WITH READ ONLY;


A.


SELECT


B.


SELECT , UPDATE


C.


SELECT , DELETE


D.


SELECT , INSERT


4.


现有a表和b表


表a:jigou(机构),kehhao(客户号),jiaoyrq(交易日期),jioyje(交易金额)


表b: kehhao(客户号),表b为VIP客户号表


统计分机构VIP客户的数量,下面SQL语句正确的是:()。


A.


SELECT COUNT(a.kehhao) FROM a INNER JOIN b ON a.kehhao = b.kehhao GROUP BY jigou


B.


SELECT COUNT(a.kehhao) FROM a INNER JOIN b ON a.kehhao = b.kehhao ORDER BY jigou


C.


SELECT SUM(a.kehhao) FROM a INNER JOIN b ON a.kehhao = b.kehhao ORDER BY jigou


D.


SELECT COUNT(a.kehhao) FROM a INNER JOIN b ON a.kehhao = b.kehhao HAVING jigou


5.


下列代码的输出结果是()。


public static void main(String[] args) {


Runnable r = new Runnable() {


public void run() {


System.out.print(“Cat”);


}


};


Thread t = new Thread(r) {


public void run() {


System.out.print(“Dog”);


}


};


t.start();
}
A.


Cat
B.


Dog
C.


没有任何输出
D.


抛出运行时异常
6.


试图使用下面句子查询数据:


SELECT 100/NVL(quantity, 0) FROM inventory;


quantity为 NULL 空值时,将导致出错,其原因是:()。


A.


除数表达式为空值.


B.


函数参数数据类型不一致.


C.


空值不能被转成实际值


D.


除数表达式为零


7.
查询客户姓名以及他的推荐人,没有推荐人的客户信息不显示,下列sql语句正确的是:
A.
select a1.real_name customer,
a2.real_name recommender
from account a1 join account a2
on a1.id = a2.id;
B.
select a1.real_name customer,
a2.real_name recommender
from account a1 join account a2
on a1.recommender_id = a2.recommender_id;
C.
select a1.real_name customer,
a2.real_name recommender
from account a1 join account a2
on a1.recommender_id = a2.id;
D.
select a1.real_name customer,
a2.real_name recommender
from account a1, a2
on a1.recommender_id = a2.id;
8.
以下不可以改变线程的状态的方法是:()。
A.


start


B.


run


C.


isAlive


D.


sleep


9.
下列Oracle语句中,可以实现更新记录的是()。
A.
UPDATE 数据表 SET 字段名称=值,… [WHERE 条件] [GROUP BY 字段名称]
B.
UPDATE 数据表,数据表,… SET 字段名称=值,… WHERE 条件
C.
UPDATE 数据表 SET 字段名称=值,… [WHERE 条件]
D.
UPDATE 数据表 Set 字段名称=值,… [WHERE 条件] [ORDER BY 字段名称]
10.
下面关于PreparedStatement说法错误的是:()。
A.
PreparedStatement是Statement的子接口。
B.
使用PreparedStatement预编译SQL可以有效的防止SQL注射。
C.
PreparedStatement具有批处理执行SQL的功能。
D.
PreparedStatement的setXXX方法可以用于设置预留的表名、字段名等参数。
11.
IO 包中,唯一代表磁盘本身的对象类是()。
A.


FileInputStream
B.


File
C.


InputStream
D.


BufferedReader
12.


下列代码的作用说法不正确的是:()。


class Card implements java.io.Serializable{}
A.


开启序列化功能,使得Card类的对象可以存储到文件中
B.


开启序列化功能,使得Card类的对象可以在网络上传输
C.


使得Card类的子类的对象可以被序列化
D.


导致Card的子类的对象不可以被反序列化


13.
以下选项中可以用来从表 state中删除列 update_dt 的是( )。
A.


ALTER TABLE state DROP COLUMN update_dt;


B.


ALTER TABLE state DELETE COLUMN update_dt;


C.


DROP COLUMN update_dt FROM state;


D.


REMOVE COLUMN update_dt FROM state;


14.


下面关于ResultSet说法错误的是()。
A.


查询结束后,所有的结果数据将一次被存储在ResultSet对象中
B.


Statement对象close后,由其创建的ResultSet对象将自动的close
C.


查询结束后,ResultSet中的游标指向第一条记录之上,因此要先调用一次next()才有可能取得记录
D.


ResultSet的的方法getString(…)意为取得该列的数据以字符串的形式返回,数据库中的该列类型并不一定必须是字符类型
15.


在Oracle中,若想查询家庭地址在’北京’,’上海’,’广州’的用户信息,下列Sql语句正确的是()。



A.


SELECT * FROM student


WHERE address=’北京’,’上海’,’广州’
B.


SELECT * FROM student


WHERE address LIKE(’北京’,’上海’,’广州’)
C.


SELECT * FROM student


WHERE address IN(’北京’,’上海’,’广州’)
D.


SELECT * FROM student


WHERE address=‘北京’ AND address=’上海’ AND address=‘广州’
16.
题目代码实现的功能是:把放入到TreeSet集合中的Student进行排序,首先按照num升序,如果num相同,再按照name降序。请问《插入代码1》和《插入代码2》处应填入的代码分别是:
public class SortStudent {
public static void main(String[] args) {
TreeSet set=new TreeSet();
set.add(new Student(19,”tom”));
set.add(new Student(20,”jessica”));
set.add(new Student(19,”terry”));
}
}
class Student implements 《插入代码1》{
private int num;
private String name;
public Student(int num,String name){
this.name=name;
this.num=num;
}
《插入代码2》
}
A.
Comparable
public int compareTo(Object o) {
Student stu=null;
if(o instanceof Student){
stu=(Student)o;
}
int result=this.num>stu.num 1:(this.num==stu.num 0:-1);
if(result==0){
result=this.name.compareTo(stu.name);
}
return result;
}
B.
Comparable
public int compareTo(Object o) {
Student stu=null;
if(o instanceof Student){
stu=(Student)o;
}
int result=this.num>stu.num 1:(this.num==stu.num 0:-1);
if(result==0){
result=stu.name.compareTo(this.name);
}
return result;
}
C.
Compartor
public int compare(Object o) {
Student stu=null;
if(o instanceof Student){
stu=(Student)o;
}
int result=this.num>stu.num 1:(this.num==stu.num 0:-1);
if(result==0){
result=this.name.compareTo(stu.name);
}
return result;
}
D.
Compartor
public int compare(Object o) {
Student stu=null;
if(o instanceof Student){
stu=(Student)o;
}
int result=this.num>stu.num 1:(this.num==stu.num 0:-1);
if(result==0){
result=stu.name.compareTo(this.name);
}
return result;
}
17.
在Oracle中,删除表Student中的所有数据,可以使用的Sql是()。
A.
DROP TABLE Student
B.
DELETE FROM Student
C.
DELETE * FROM Student
D.
DROP * FROM Student
18.
显示上个月的今天,这个月的今天,下个月的今天,精度到时、分、秒,下列sql语句正确的是:
A.
alter session set nls_date_format = ‘yyyy mm dd hh24:mi:ss’;
select add_months(sysdate,-1),sysdate,add_months(sysdate,1) from dual;
B.
alter user set nls_date_format = ‘yyyy mm dd hh24:mi:ss’;
select add_months(sysdate,-1),sysdate,add_months(sysdate,1) from dual;
C.
alter session set nls_date_format = ‘yyyy mm dd hh24:mi:ss’;
select last_month(),this_month(),next_month() from dual;
D.
alter user set nls_date_format = ‘yyyy mm dd hh24:mi:ss’;
select last_month(),this_month(),next_month() from dual;
19.
下面不属于接口的是:()。
A.
java.sql.Connection
B.
java.sql.Driver
C.
java.sql.DriverManager
D.
java.sql.ResultSet
20.


可以在Oracle中获取当前时间的Sql语句是()
A.


SELECT SYSDATE
B.


SELECT SYSDATE FROM DUAL
C.


SELECT DATE
D.


SELECT DATE FROM DUAL
21.
下列异常类是RuntimeException的子类的是:()。
A.


ArrayIndexOutOfBoundsException


B.


Exception


C.


FileNotFoundException


D.


IOException


22.
查询tarena23和tarena20上的远程登录业务使用了哪些相同的资费标准,下列sql语句正确的是:
A.
select cost_id from service
where unix_host = ’192.168.0.20′
intersect
select cost_id from service
where unix_host = ’192.168.0.23′;
B.
select cost_id from service
where unix_host = ’192.168.0.20′
union
select cost_id from service
where unix_host = ’192.168.0.23′;
C.
select cost_id from service
where unix_host = ’192.168.0.20′
union all
select cost_id from service
where unix_host = ’192.168.0.23′;
D.
select cost_id from service
where unix_host = ’192.168.0.20′
minus
select cost_id from service
where unix_host = ’192.168.0.23′;
23.


阅读以下SQL语句:


INSERT INTO student(stu_no)VALUES(1001);


SAVEPOINT sp1;


DELETE FROM student;


SAVEPOINT sp2;


如果想要恢复student表中所有数据,并且结束该事务的正确做法是()。
A.


rollback to sp2;
B.


rollback to sp1;
C.


commit;
D.


rollback;
24.


DELETE和 TRUNCATE 都可以用来删除表内容,以下描述正确的是:()。


A.


TRUNCATE 不需要 RollbackSegment


B.


DELETE 不需要RollbackSegment


C.


TRUNCATE在 提交COMMIT之前仍可回滚


D.


TRUNCATE还可以删除表结构


25.
下列属于DML语句的是 :() 。


A.


COMMIT


B.


INSERT


C.


DROP


D.


GRANT


26.
下列代码中对象锁的使用效率最高的是:
A.
public class Foo{
private Object o1,o2;
public synchronized void methodA(){对o1进行操作}
public synchronized void methodB(){对o1进行操作}
public synchronized void methodC(){对o2进行操作}
public synchronized void methodD(){对o2进行操作}
}
B.
public class Foo{
private Object lock = new Object();
private Object o1,o2;
public void methodA(){synchronized(lock){对o1进行操作}}
public void methodB(){synchronized(lock){对o1进行操作}}
public void methodC(){synchronized(lock){对o2进行操作}}
public void methodD(){synchronized(lock){对o2进行操作}}
}
C.
public class Foo{
private Object lock = new Object(),lock2 = new Object();
private Object o1,o2;
public void methodA(){synchronized(lock){对o1进行操作}}
public void methodB(){synchronized(lock){对o1进行操作}}
public void methodC(){synchronized(lock2){对o2进行操作}}
public void methodD(){synchronized(lock2){对o2进行操作}}
}


D.
public class Foo{
private Object lock = new Object(),lock2 = new Object();
private Object o1,o2;
public void methodA(){synchronized(lock){对o1进行操作}}
public void methodB(){synchronized(lock2){对o1进行操作}}
public void methodC(){synchronized(lock){对o2进行操作}}
public void methodD(){synchronized(lock2){对o2进行操作}}
}
27.
下面关于事务(Transaction)的说法错误的是:()。
A.


事务具备ACID四个基本特性,即A(Atomicity)—原子性、C(Consistency)—一致性、I(Isolation)—隔离性、D(Durability)—持久性。
B.


事务的提交(Commit)指将事务中所有对数据库的更新写到磁盘上的物理数据库中去,事务正常结束。
C.


事务的回滚(Rollback)指在事务运行的过程中发生了某种故障,事务不能继续进行,将事务中对数据库的所有以完成的操作全部撤消,回滚到事务开始的状态。
D.


JDBC通过Connection对象控制事务,默认方式下,在执行完更改语句后需要必须要调用Connection的commit方法,对数据的更改才能生效。
28.
下列代码的运行结果是:
public class WrappedString {
private String s;
public WrappedString(String s) {
this.s = s;
}
public static void main(String[] args) {
HashSet hs = new HashSet();
WrappedString ws1 = new WrappedString(“aardvark”);
WrappedString ws2 = new WrappedString(“aardvark”);
String s1 = new String(“aardvark”);
String s2 = new String(“aardvark”);
hs.add(ws1);
hs.add(ws2);
hs.add(s1);
hs.add(s2);
System.out.println(hs.size());
}
}
A.
1
B.
2
C.
3
D.
4
29.


在Oracle数据库中,关于主键约束与唯一约束说法错误的是()。
A.


主键列的数据类型不限,但此列必须是唯一并且非空
B.


一张数据表只能有一个唯一约束
C.


唯一性约束所在的列允许空值
D.


数据库支持两个列做联合主键
30.


在Oracle中,当数据量较大时,删除表中所有数据,效率较高的是()。



A.


DELETE FROM Student
B.


DELETE FROM Student WHERE id>0
C.


TRUNCATE table Student
D.


TRUNCATE table Student WHERE id>0
31.
在Oracle中,有表Person,如下:
ID Name Tel
001 Amber 1234
002 Amy 2345
003 Emily 4567
004 Eric 5678
005 Roy 6789
SELECT Tel FROM Person WHERE Name = ‘A%’;
执行以上查询,结果是:
A.
1234
B.
2345
C.
4567
D.
运行后结果是“未选定行”
32.


表student有两个字段stu_no和stu_name,现在使用序列seq_student给stu_no赋值,下列写法正确的是()。
A.


String sql =


“insert into student (stu_no,stu_name)values(seq_student.nextval, )”;


PrepareStatement stmt = con.prepareStatement(sql);


stmt.setString(1,”习近平”);
B.


String sql = ” insert into student (stu_no,stu_name)values( , )”;


PrepareStatement stmt = con.prepareStatement(sql);


stmt.setString(1, seq_ student.nextval);


stmt.setString(2,”习近平”);
C.


String sql = ” insert into student (stu_no,stu_name)values( )”;


PrepareStatement stmt = con.prepareStatement(sql);


stmt.setString(1,”习近平”);
D.


String sql =


” insert into student (stu_no,stu_name)values(seq_student.nextval, )”;


PrepareStatement stmt = con.prepareStatement(sql);


stmt.setString(2,”习近平”);
33.


在Oracle中,给Student表添加Address列,如下代码正确的是()。
A.


ALTER TABLE student


ADD COLUMN(address VARCHAR2(20))
B.


UPDATE TABLE student


ADD COLUMN(address VARCHAR2(20))
C.


UPDATE TABLE student


ADD(address VARCHAR2(20))
D.


ALTER TABLE student


ADD(address VARCHAR2(20))
34.


包含事务控制方法setAutoCommit, commit, rollback的是:() 。


A.


Connection


B.


Statement


C.


ResultSet


D.


DriverManager


35.
下列代码运行的结果是:
public class TestTwo implements Runnable {
public static void main(String[] args) throws Exception {
Thread t = new Thread(new TestTwo());
t.start();
System.out.print(“Started”);
t.join();
System.out.print(“Complete”);
}


public void run() {
for (int i = 0; i < 4; i++) {
System.out.print(i);
}
}
}
A.
StartedComplete
B.
StartedComplete0123
C.
Started0123Complete
D.
0l23StartedComplete


二、 多选(5小题共10.0分)
1.
下列属于Set接口实现类的是:
A.
HashMap
B.
TreeMap
C.
HashSet
D.
TreeSet
2.
操作account表和service表,查询申请远程登录业务的客户的数据,下列sql语句正确的是:
A.
select real_name from account
where in (select account_id from service);
B.
select real_name from account o
where id exists
(select 1 from service i
where o.id = i.account_id);


C.
select real_name from account
where id in (select account_id from service);
D.
select real_name from account o
where exists
(select 1 from service i
where o.id = i.account_id);
3.
下列语句在建表的同时在c2,c3列上创建了唯一约束,其中正确的是:
A.
create table test
(c1 number constraint test_c1_pk
primary key,
c2 number constraint test_c2_uk
foreign key,
c3 number constraint test_c3_uk
foreign key);
B.
create table test
(c1 number constraint test_c1_pk
primary key,
c2 number ,
c3 number ,
constraint test_c3_uk foreign key(c2,c3));


C.
create table test
(c1 number constraint test_c1_pk
primary key,
c2 number ,
c3 number ,
constraint test_c3_uk unique(c2,c3));
D.
create table test
(c1 number constraint test_c1_pk
primary key,
c2 number constraint test_c2_uk
unique,
c3 number constraint test_c3_uk
unique);
4.
请看下列代码:
Map map=new HashMap();
map.put(“one”,100);
map.put(“two”,200);
map.put(“three”,300);
遍历map对象中的每一个元素,下列选项正确的是:
A.
Set set=map.keySet();
for(String key:set){
Integer value=map.get(key);
System.out.println(key+”:”+value);
}
B.
List list=map.keyList();
for(String key:list){
Integer value=map.getKey(key);
System.out.println(key+”:”+value);
}
C.
Set> set = map.entrySet();
for (Map.Entry per : set) {
System.out.println(per.getKey() + “:” + per.getValue());
}
D.
List list=map.entryList();
for(Entry per:list){
System.out.println(per.getKey() + “:” + per.getValue());
}
5.
关于下列代码说法正确的是:
Set set = new HashSet();
Random r = new Random();
int i = 0;
while (set.size() <10) {
set.add(r.nextInt(100)); i++;
}
A.
代码循环执行的次数一定为10次,重复的整数可以放入set集合中。
B.
代码将随机产生10个100以内的可重复的整数,并将其放入集合中。
C.
代码循环执行的次数可能会大于10次,重复的整数无法放入set集合中。
D.
代码将随机产生元素个数为10个的100以内不重复整数集合。
三、 完形填空(2小题共20.0分)
1.


joinFile方法用于将指定目录下(不包含子目录)所有的扩展名为txt的文本文件连接成一个大的文本文件,代码如下:


public void joinFile(String srcDir, String destFile)


throws IOException {


if (srcDir == null || srcDir.length() == 0 || destFile == null


|| destFile.length() == 0){


throw new IllegalArgumentException(“…”);


}


File dir = new File(srcDir);


if ( 代码处1 ) { //1


throw new IllegalArgumentException(“指定源目录不存在”);


}


BufferedOutputStream bos = new BufferedOutputStream(


new FileOutputStream(destFile));


代码处2


if (files != null && files.length > 0) {


for (File sub : files) {


if ( 代码处3 ) {


BufferedInputStream bis = new BufferedInputStream(


new FileInputStream(sub));


int b;


while ( 代码处4) {


代码处5


}


bis.close();


bos.flush();


}


}


bos.close();


}


}
(1).


程序中1处应该填入的代码是:()。
A.


dir.exists() || dir.isFile()
B.


!dir.exists() || !dir.isDirectory()
C.


dir.exists() || dir.isDirectory()
D.


!dir.exists() || !dir.isFile()
(2).


程序中2处应该填入的代码是:()。
A.


File[] files = dir.listFiles();
B.


File[] files = dir.lists();
C.


File[] files = dir.getFiles();
D.


File[] files = dir.files();
(3).


程序中3处应该填入的代码是:()。
A.


sub.isDirectory() && sub.getPath().endsWith(“.txt”)
B.


sub.isDirectory() && sub.getName().endsWith(“.txt”)
C.


sub.isFile() && sub.getPath().endsWith(“.txt”)
D.


sub.isFile() && sub.getName().endsWith(“.txt”)
(4).


程序中4处应该填入的代码是:()。
A.


(b = bis.read()) != 0
B.


(b = bis.read()) != -1
C.


(b = bis.read()) != null
D.


(b = bis.read()) >=0
(5).


程序中5处应该填入的代码是:()。
A.


bos.writeBytes(b);
B.


bos.writeInt(b);
C.


bos.write(b);
D.


bos.writeByte(b);
2.


服务器端用户日志文件的格式如下:


437100 1250524800000 1250567366000


545500 1256227200000 1256240694000


843600 1256745600000 1256826557000


………


以空格分隔的三个数据分别表示用户编号,用户登入服务器的时间(毫秒数)以及用户登出服务器的时间(毫秒数)。方法populate用于将日志文件中的数据插入到数据库的t_loginfo表中,建表的SQL如下:


drop sequence t_loginfo_seq;


create table t_loginfo (


id number(12) not null,


user_id number(6) not null,


login_time number(20) not null,


logout_time number(20) not null


);


alter table t_loginfo add constraint pk_t_loginfo primary key(id);


create sequence t_loginfo_seq;


populate方法的代码如下:


public void populate(File logFile) throws Exception {


int batchSize = 1000;


代码1


Connection con = null;


PreparedStatement stmt = null;


try {


con = ConnUtils.openConnection();


con.setAutoCommit(false);


代码2


String line = null;


int rows = 0;


while ((line = reader.readLine()) != null) {


代码3


stmt.setInt(1, Integer.parseInt(data[0]));


stmt.setLong(2, Long.parseLong(data[1]));


stmt.setLong(3, Long.parseLong(data[2]));


代码4


if (++rows >= batchSize) {


stmt.executeBatch();


stmt.clearBatch();


rows = 0;


}


}


代码5


} catch (Exception e) {


con.rollback();


throw e;


} finally {


if(stmt!=null) stmt.close();


if(con!=null) con.close();


}


}
(1).


程序中1处应该填入的代码是:()。
A.


BufferedReader reader = new BufferedReader(new InputStreamReader(


new FileInputStream(logFile), “utf-8″));
B.


BufferedReader reader = new BufferedReader(newFileReader(


newFileReader(logFile), “utf-8″));
C.


BufferedReader reader = new BufferedReader(new FileReader(logFile, “utf-8″));
D.


BufferedReader reader = new BufferedReader(new InputStreamReader(logFile, “utf-8″));
(2).


程序中2处应该填入的代码是:()。
A.


stmt = con.prepareStatement(“insert into t_loginfo


values(t_loginfo_seq.nextval(), , , )”);
B.


stmt = con.prepareStatement(“insert into t_loginfo(user_id, login_time,


logout_time)values( , , )”);
C.


stmt = con.prepareStatement(“insert into t_loginfo


values( , , )”);
D.


stmt = con.prepareStatement(“insert into t_loginfo


values(t_loginfo_seq.nextval, , , )”);
(3).


程序中3处应该填入的代码是:()。
A.


String[] data = line.split();
B.


String[] data = line.split(” “);
C.


String[] data = line.parse(” “);
D.


String[] data = line.parse();
(4).


程序中4处应该填入的代码是:()。
A.


stmt.executeQuery();
B.


stmt.execute();
C.


stmt.executeUpdate();
D.


stmt.addBatch();
(5).


程序中5处应该填入的代码是:()。
A.


stmt.execute();


con.commit();
B.


stmt.execute();


con.close();
C.


stmt.executeBatch();


con.commit();
D.


stmt.executeBatch();


con.close();


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇POSIX方面的知识 下一篇中兴网络工程师面试题

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: