Java Test One

一、 是非题5题(每题3分)
1、 对象的特征是对象有状态、行为、标识ID ( )

2、 GenericServlet是一个与协议相关的Servlet类。( )
3、 Java中的this指的是当前类。 ( )
4、Java数据库连接用的是JDBC。 ( )
5、接口是一个纯的抽象类,可以包含私有方法。 ( )
二、 填空题(每空2分)
6、从对象到类是一个( )的过程。

7、J2EE Web层组件指( )、( )和可选的( )
8、在使用Statement类的对象向数据库发送SQL语句时,如果发送的时select语句应该调用( )方法,如果发送的是insert/update/delete语句一个调用()方法。
9、在J2EE Web应用中使用MVC设计模式, JSP充当( ),Servlet充当( ),可选的JavaBean充当( )。
10、使用JDBC访问数据库中的存储过程,应该使用( )
11、ServletSocket所做的工作是:( )
三、 程序题(每题2分,有单选和多选)
1.下面的程序中哪些可以输出Hello World
a. public class Hello{
static{
System.out.println(“Hello World”);
}
}
b.pulic class Hello{
public static void main(String[] arg){
System.out.println(“Hello World”);
}
}
c.pulic class Hello{
public void static main(String[] arg){
System.out.println(“Hello World”);
}
}
d.pulic class Hello{
static public void main(String[] arg){
System.out.println(“Hello World”);
}
}
答案: 

2. public class Test{
public static void main (String args[]){
int x=1,sum=0;
while(x<=10){
sum+=x;
x++;
}
System.out.println(“sum=”+sum);
}
}
输出是:

3、给出下列声明:
String s1=new String(“Hello”);
String s2=new String(“there”);
String s3=new String();
Which of the following are legal operations?
A、s3=s1+s2;
B、s3=s1-s2;
C、s3=s1&s2;
D、s3=s1&&s2;


4.A byte can be of what size
1)-128 to 127
2)(-2 power 8)-1 to 2 power 8
3)-255 to 256
4)depends on the particular implementation of the java virtual machine


5.
哪些是Java关键字?
1)if
2)THEN
3)const
4)try

6.哪些是合法的变量名?
1)2variable
2)variable2
3)_whatavariable
4)_3_
5)$another


7.
编译和执行下例代码会出现什么情况?
public class MyClass{
   static int i;
      public static void main(String argv[]){
        System.out.println(i);
      }
}

1) Error varable i may not have been initialized
2) null
3) 1
4) 0


8. 
编译和执行下例代码会出现什么情况?
public class Q{
    public static void main(String argv[]){
      int anar[]=new int[]{1,2,3};
      System.out.println(anar[1]);
   }
}

1)1
2)Error: anar is referenced before it is initialized
3)2
4)Error : size of array must be defined


9. 
编译和执行下例代码会输出什么?
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”);
1) one
2) one,default
3) one,two,default
4) default


10. class Student{
    private String name;
    private byte age;
      public Student(String name, byte age){
         this.age = age;
         this.name = name;
      }
//
完成代码
}
public class Test{
     public static void main(String[] arg){
     Student stu1 = new Student(“Alice”, 23); //此句有错,请将正确的语句写在下面
     Student stu1 = 
     System.out.println(stu1);
     }
}
要求:完成Student类的代码,在控制台输出:Student Alice is 23 years old.

11根据JavaBean规范,完成下面的JavaBean?
public class Student{
      private String name;
      private byte age;
      private boolean married;


}

12、哪二种声明防止方法覆盖?
A、final void methoda() {}
B、void final methoda() {}
C、static void methoda() {}
D、static final void methoda() {}
E、final abstract void methoda() {}


13
、修改show方法使得该JSP可以正确运行

14、下面哪些关于JSP的陈述是正确的:
1) 获得客户端提交的数据使用request对象
2) 向客户端输出可以使用表达式,也可以使用out对象
3) JSP指令用于设置容器的状态,同时产生输出
4) 在使用include指令处理页面模块化时,当被包含的页面发生变化时,会自动表现出来。


15
、在web应用中处理会话有以下四种方式
1)( )
2)( )
3)( ) 
4)( )


16.
编译下例代码哪些没有错误?
1)
import java.awt.*;
package Mypackage;
class Myclass{}

2)
package Mypackage;
import java.awt.*;
class Myclass{}

3)
/* This is a comment */
package Mypackage;
import java.awt.*;
class Mycalss{}


17. 
编译和执行下例代码会输出什么?
public class Q 
public static void main(String argv[]){
int anar[]=new int[5];
System.out.println(anar[0]);
}
}

1) Eror:anar is referenced before it is initialized
2) null
3) 0
4) 5


18. 
编译和执行下例代码会输出什么?
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]);
      }
}
1) a sequence of 5 0’s will be printed
2) Error:ar is used before it is initialized
3) Error Mine must be declared abstract
4) IndexOutOfBoundes Error

19、编译和执行下例代码会输出什么?
public class Borley extends Thread{
    public static void main(String argv[]){
    Borley b = new Borley();
    b.start();
   }
   public void run(){ 
      System.out.println("Running");
   }
}

1) Compilation and run but no output 
2) Compilation and run with the output "Running" 
3) Compile time error with complaint of no Thread target 
4) Compile time error with complaint of no access to Thread package


20
、哪些能停止一个线程运行?
1) The program exits via a call to System.exit(0);
2) Another thread is given a higher priority
3) A call to the thread’s stop method
4)A call to the halt method of the Thread class


21
、在Servlet生命周期中的哪些方法只被执行一次
1) init
2) service
3) destroy
4) doGet/doPost

四、简答题
22、说明一个Web应用的部署结构,各种组件如何部署?(5)

23、说说JSP、servlet的生命周期以及二者之间的对应关系(8)


24
、如何使用JDBC访问数据库,编程的步骤是什么、给出相应的案例代码?(8)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值