`
fuyun369
  • 浏览: 30413 次
  • 性别: Icon_minigender_1
  • 来自: 江苏
社区版块
存档分类
最新评论

第一阶段的J2SE学习考试题(JAVA基础、JDBC)

阅读更多
第一阶段的J2SE学习考试题(JAVA基础、JDBC)
        第一阶段的J2SE学习考试题, 试试看你能得多少分?

========以下为中文测试题,每题2分,总分40分,40分钟完成==========
1 e
下面的语句哪一行在编译时没有警告和编译错误
a) float f=1.3;
b) char c=”a”;
c) byte b=257;
d) boolean b=null;
e) int i=10;

2 a
下面的代码编译后会出现什么问题
public class MyClass {

public static void main(String arguments[]) {
amethod(arguments);
}

public void amethod(String[] arguments) {
System.out.println(arguments);
System.out.println(arguments[1]);
}
}
a) 错误,不能静态引用amethod方法
b) 错误,main方法不正确
c) 错误,数组必须包含参数
d) Amethod必须声明为String类型

3 a
下面的哪一组代码会出现编译错误
a)
import java.awt.*;
package Mypackage;
class Myclass {}

b)
package MyPackage;
import java.awt.*;
class MyClass{}

c)
/*This is a comment */
package MyPackage;
import java.awt.*;
class MyClass{}

4 A
byte类型的大小是
a) -128 ~ 127
b) -28-1 ~28
c) -255 ~ 256
d)不同的操作系统Java虚拟机分配不同的大小

5 d
下面的代码在输入下面的命令行后会输出什么内容
命令行:java myprog good morning
代码:
public class myprog{
public static void main(String argv[]) {
System.out.println(argv[2]);
}
}
a) myprog
b) good
c) morning
d) Exception raised: “java.lang.ArrayIndexOutOfBoundsException: 2″

6 b
下面哪个不是Java的关键字或者保留字
a) if
b) then
c) goto
d) while
e) case

7 b,c,d,e
下面哪些是合法的变量名 (多选)
a) 2variable
b) variable2
c) _whatavariable
d) _3_
e) $anothervar
e) #myvar

8 d
试图编译运行下面的代码会发生什么情况
public class MyClass{
static int i;
public static void main(String argv[]){
System.out.println(i);
}
}

a)错误,变量i没有被初始化
b) null
c) 1
d) 0

9 c
试图编译运行下面的代码会发生什么情况
public class Q {
public static void main(String argv[]){
int anar[]=new int[]{1,2,3};
System.out.println(anar[1]);
}
}
a) 1
b) Error anar 被引用前没有初始化
3) 2
4) Error: 数组大小没有定义
—————————————————————————————————————
10 c
试图编译运行下面的代码会发生什么情况
public class Q {
public static void main(String argv[]){
int anar[]=new int[5];
System.out.println(anar[0]);
}
}
a) Error: anar is referenced before it is initialized
b) null
c) 0
d) 5

11 a
试图编译运行下面的代码会发生什么情况
abstract class MineBase {
abstract void amethod();
static int i;
}

public class Mine extends MineBase {
public static void main(String argv[]) {
int[] ar=new int[5];
for(i=0;i < ar.length;i++)
System.out.println(ar[i]);
}
}
a) 5个0的序列会被输出
b) Error: ar 在使用前要初始化
c) Error Mine 必须被声明为 abstract
d) Error 数组越界

12 c
试图编译运行下面的代码会输出什么样的结果
int i=1;
switch (i) {
case 0:
System.out.println(”zero”);
break;
case 1:
System.out.println(”one”);
case 2:
System.out.println(”two”);
default:
System.out.println(”default”);
}

a) one
b) one, default
c) one, two, default
d) default

13 b
试图编译运行下面的代码会输出什么样的结果
int i=9;
switch (i) {
default:
System.out.println(”default”);
case 0:
System.out.println(”zero”);
break;
case 1:
System.out.println(”one”);
case 2:
System.out.println(”two”);
}
a) default
b) default, zero
c) error default没有定义
d) 无输出

14 b,c
下面的哪些组代码没有编译错误(多选)
a)
int i=0;
if(i) {
System.out.println(”Hello”);
}

b)
boolean b=true;
boolean b2=true;
if(b==b2) {
System.out.println(”So true”);
}

c)
int i=1;
int j=2;
if(i==1|| j==2)
System.out.println(”OK”);

d)
int i=1;
int j=2;
if(i==1 &| j==2)
System.out.println(”OK”);

15 c
如果在当前目录下不存在Hello.txt 文件,试图编译和运行下面代码会输出什么
import java.io.*;
public class Mine {
public static void main(String argv[]){
Mine m=new Mine();
System.out.println(m.amethod());
}

public int amethod() {
try {
FileInputStream dis=new FileInputStream(”Hello.txt”);
}catch (FileNotFoundException fne) {
System.out.println(”No such file found”);
return -1;
}catch(IOException ioe) {

} finally{
System.out.println(”Doing finally”);
}
return 0;
}
}

a) No such file found
b) No such file found ,-1
c) No such file found, Doing finally, -1
d) 0

16 b,c
在下面的注释处插入哪些部分代码是合法的(多选)
class Base{
public void amethod(int i) { }
}

public class Scope extends Base{
public static void main(String argv[]){

}
//在这里定义一个方法
}

a) void amethod(int i) throws Exception {}
b) void amethod(long i)throws Exception {}
c) void amethod(long i){}
d) public void amethod(int i) throws Exception {}
17 a
下面哪行代码输出4.0
a) System.out.println(Math.floor(4.7));
b) System.out.println(Math.round(4.7));
c) System.out.println(Math.ceil(4.7));
d) System.out.println(Math.min(4.7));

18 b
如果运行下面的代码会输出什么内容
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:没有匹配的方法 substring(int,char)

19 c
给出下面的代码在注释部分放置什么样的代码会输出“Equal”
public class EqTest{
public static void main(String argv[]){
EqTest e=new EqTest();
}

EqTest(){
String s=”Java”;
String s2=”java”;

//place test here
{

System.out.println(”Equal”);
}else {
System.out.println(”Not equal”);
}
}
}
a) if(s==s2)
b) if(s.equals(s2)
c) if(s.equalsIgnoreCase(s2))
d)if(s.noCaseMatch(s2))

20 c
给出下面的代码,怎样调用Base的构造方法会输出”base constructor”
class Base{
Base(int i){
System.out.println(”base constructor”);
}

Base(){
}
}

public class Sup extends Base{
public static void main(String argv[]){
Sup s = new Sup();
//One
}
Sup() {
//Two
}

public void derived() {
//Three
}
}
a) //One 后放置Base(10);
b) //One 后放置 super(10);
c) //Two 后放置 super(10);
d) //Three 后放置super(10);

=============== 以下为英文测试题,每题4分,总分36分,40分钟完成 ==============

1. c
Which of the following are valid definitions of an application’s main( method?
A. public static void main();
B. public static void main( String args );
C. public static void main( String[] args );
D. public static void main( Graphics g) ;
E. public static boolean main( String args[] );

2. e
Which of the following are Java keywords?
A. array
B. Boolean
C. Integer
D. protect
E. super

3. c,e
After the declaration:
char[] c = new char[100];
what is the value of c[50]?
A. 50
B. 49
C. ‘\u0000′
D. ‘\u0020′
E.” ”
F. cannot be determined
G. always null until a value is assigned

4. a
After the declaration:
int x;
the range of x is:
A. -2^31 to 2^31-1
B. -2^16 to 2^16 - 1
C. -2^32 to 2^32
D. -2^16 to 2^16
E. cannot be determined; it depends on the machine

5. a,b,c,e
Which identifiers are valid?
A. _xpoints
B. r2d2
C. bBb$
D. set-flow
E. thisisCrazy

6. d
If you compile and execute an application with the following code in its main() method:
String s = new String( “Computer” );
if( s == “Computer” )
System.out.println( “Equal A” );
if( s.equals( “Computer” ) )
System.out.println( “Equal B” );
A. It will not compile because the String class does not support the == operator.
B. It will compile and run, but nothing is printed.
C. “Equal A” is the only thing that is printed.
D. “Equal B” is the only thing that is printed.
E.Both “Equal A” and “Equal B” are printed.
7. b, e
Given the variable declarations below:
byte myByte;
int myInt;
long myLong;
char myChar;
float myFloat;
double myDouble;
Which one of the following assignments would need an explicit cast?
A. myInt = myByte;
B. myInt = myLong;
C. myByte = 3;
D. myInt = myChar;
E. myFloat = myDouble;
F. myFloat = 3;
G. myDouble = 3.0;

8. c,d,e,g
Given the variables defined below:
int one = 1;
int two = 2;
char initial = ‘2′;
boolean flag = true;

Which of the following are valid?
A. if( one ){}
B.if( one = two ){}
C. if( one == two ){}
D.if( flag ){}
E. switch( one ){}
F. switch( flag ){}
G.switch( initial ){} 

9. b
If val = 1 in the code below:
 
switch( val )
{ case 1: System.out.print( “” );
case 2:
case 3: System.out.print( “Q” );
break;
case 4: System.out.print( “R” );
default: System.out.print( “S” );
}
Which values would be printed?
A. P
B. Q
C. R
D. S
=================以下为问答题,每题5分,总分25分,25分钟完成=================

1。
class StaticStuff {
static int x=10;
static {
x+=5;
}

public static void main(String args[]) {
System.out.println(”x=” + x);
}

static {
x/=3;
}
}
打印结果是什么?为什么?
x=5
因为x初始值是10, (10+5)/3 = 5

2。
说说HashMap与Hashtable有什么异同?ArrayList与LinkedList有什么异同?

HashMap与Hashtable的异同:
1. HashTable的方法是线程同步的,HashMap不是线程同步
2. HashTable不允许null值(key和value都不可以),HashMap允许null值(key和value都可以)。
3. HashTable有一个contains(Object value),功能和containsValue(Object value)功能一样。
4. HashTable使用Enumeration,HashMap使用Iterator。

ArrayList与LinkedList的异同:
1.ArrayList是实现了基于动态数组的数据结构,LinkedList基于链表的数据结构。
2.对于随机访问get和set,ArrayList觉得优于LinkedList,因为LinkedList要移动指针。
3.对于新增和删除操作add和remove,LinedList比较占优势,因为ArrayList要移动数据。
3。
java程序中有哪些办法来创建线程?它们各有什么特点?

1. 继承java.lang.Thread类,并且覆盖run()方法。
2. 实现java.lang.Runnable接口,这个接口只有一个待实现的方法——run()方法

Thread是类只能被继承,而Runnable是接口
Java只支持一个继承,所以你的类如果还要继承自其它的类,就不能用Thread了,就可以用runnalbe接口了。
4。
java语言提供了哪些基本数据类型?分别介绍它们的字长以及能参与的运算。

占用字节 大小范围
byte(字节型) 1 -128~127
short(短整型) 2 -32768~32767
int(整型) 4 -2147483648~2147483647
long(长整型) 8 -9223372036854775808 ~ 9223372036854775807
float(浮点型) 4 -3.4E38~3.4E38
double(双精度型) 8 -1.7E308~1.7E308
char(字符型) 2 从字符型对应的整型数来划分,其表示范围是0~65535
boolean(布尔型) 1 true或false

5。
阐述面向对象编程的主要特点。

抽象, 继承,封装,多态性

==================以下为编程题,每题30分,总分90分,120分钟完成================

1
编写一个类MyStr,利用字符数组来实现一个字符串的功能。
public class MyStr {

//存放字符串的数组
char[] str;

//构造函数
public MyStr( );
public MyStr(String s);

//取字符串的长度
public int length( );

//拷贝字符串
public MyStr clone( );

//比较两个字符串是否相等
public boolean equals(MyStr s);

//按照索引取字符串中的字符
public char charAt(int index);

//将MyStr对象转换成String类型
public String toString( );
}

2
编写一个类MyVector,利用对象数组来实现一个可变长度的向量
public class MyVector {

//存放对象的数组
Object[] data;

//构造函数
public MyVector( );
public MyVector(int size);

//往向量中添加一个对象
public void add(Object o);

//取向量中对象的个数
public int size( );

//复制出一个新的向量
public MyVector clone( );

//从向量中删除一个对象,返回值为刚删除的该对象
public Object remove( );
}

3。
用 JDBC 查询学生成绩单.
数据库中表的格式如下:

–学生表:包含学号,学生姓名
create table students(stu_id int, name varchar(20));

–课程表:包含课程号,课程名称
create table subject(sub_id int, title varchar(20));

–得分表:包含学号,课程号,分数
create table score(stu_id int, sub_id int, score int);

要求查出学生姓名,课程名称,与分数。要求用图形界面显示查询结果。
分享到:
评论
1 楼 shelaine 2009-02-16  
原版的!差一个东西!要不然就是绝对的完美!

相关推荐

Global site tag (gtag.js) - Google Analytics