[第一部分:选择题]
QUESTION NO: 1
1、public class Test {
public static void changeStr(String str){
str="welcome";
}
public static void main(String[] args) {
String str="1234";
changeStr(str);
System.out.println(str);
}
}
Please write the output result :
QUESTION NO:2
1. public class Test {
2. static boolean foo(char c) {
3. System.out.print(c);
4. return true;
5. }
6. public static void main( String[] argv ) {
7. int i =0;
8. for ( foo(’A’); foo(’B’)&&(i<2); foo(’C’)){
9. i++ ;
10. foo(’D’);
12. }
13. }
14. }
What is the result?
A. ABDCBDCB
B. ABCDABCD
C. Compilation fails.
D. An exception is thrown at runtime.
QUESTION NO: 3
1. class A {
2. protected int method1(int a, int b) { return 0; }
3. }
Which two are valid in a class that extends class A? (Choose two)
A. public int method1(int a, int b) { return 0; }
B. private int method1(int a, int b) { return 0; }
C. private int method1(int a, long b) { return 0; }
D. public short method1(int a, int b) { return 0; }
E. static protected int method1(int a, int b) { return 0; }
QUESTION NO: 4
1. public class Outer{
2. public void someOuterMethod() {
3. // Line 3
4. }
5. public class Inner{}
6. public static void main( String[]argv ) {
7. Outer o = new Outer();
8. // Line 8
9. }
10. }
Which instantiates an instance of Inner?
A. new Inner(); // At line 3
B. new Inner(); // At line 8
C. new o.Inner(); // At line 8
D. new Outer.Inner(); // At line 8//new Outer().new Inner()
QUESTION NO: 5
Which method is used by a servlet to place its session ID in a URL that is written to the servlet’s response output stream?
A. The encodeURL method of the HttpServletRequest interface.
B. The encodeURL method of the HttpServletResponse interface.
C. The rewriteURL method of the HttpServletRequest interface.
D. The rewriteURL method of the HttpServletResponse interface.
QUESTION NO: 6
Which of the following statements regarding the lifecycle of a session bean are correct?
1. java.lang.IllegalStateException is thrown if SessionContext.getEJBObject() is invoked when a stateful session bean instance is passivated.
2. SessionContext.getRollbackOnly() does not throw an exception when a session bean with bean-managed transaction demarcation is activated.
3. An exception is not thrown when SessionContext.getUserTransaction() is called in the afterBegin method of a bean with container-managed transactions.
4. JNDI access to java:comp/env is permitted in all the SessionSynchronization methods of a stateful session bean with container-managed transaction demarcation.
5. Accessing resource managers in the SessionSynchronization.afterBegin method of a stateful session bean with bean-managed transaction does not throw an exception.
[第二部分:概念题]
1. 描述Struts体系结构?对应各个部分的开发工作主要包括哪些?
2. XML包括哪些解释技术,区别是什么?
3. JSP有哪些内置对象和动作?它们的作用分别是什么?
4、SQL问答题
SELECT * FROM TABLE
和
SELECT * FROM TABLE
WHERE NAME LIKE '%%' AND ADDR LIKE '%%'
AND (1_ADDR LIKE '%%' OR 2_ADDR LIKE '%%'
OR 3_ADDR LIKE '%%' OR 4_ADDR LIKE '%%' )
的检索结果为何不同?
5、SQL问答题
表结构:
1、 表名:g_cardapply
字段(字段名/类型/长度):
g_applyno varchar 8;//申请单号(关键字)
g_applydate bigint 8;//申请日期
g_state varchar 2;//申请状态
2、 表名:g_cardapplydetail
字段(字段名/类型/长度):
g_applyno varchar 8;//申请单号(关键字)
g_name varchar 30;//申请人姓名
g_idcard varchar 18;//申请人身份证号
g_state varchar 2;//申请状态
其中,两个表的关联字段为申请单号。
题目:
1、 查询身份证号码为440401430103082的申请日期
2、 查询同一个身份证号码有两条以上记录的身份证号码及记录个数
3、 将身份证号码为440401430103082的记录在两个表中的申请状态均改为07
4、 删除g_cardapplydetail表中所有姓李的记录
[JAVA题库:5道JAVA题]
Module 1 – Getting Started
Q1.What will happen when you compile and run the following code?
(4)
public class MyClass{
static int i;
public static void main(String argv[]){
System.out.println(i);
}
}
1) Error Variable i may not have been initialized
2) null
3) 1
4) 0
Q2.Which of the following will compile without error (2)(3)
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 MyClass{}
Q3.What will happen if you try to compile and run the following code (1)
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]);
}
}
1) error Can't make static reference to void amethod.
2) error method main not correct
3) error array must include parameter
4) amethod must be declared with String
Q4.Given the following code(2)
public class Sytch{
int x=2000;
public static void main(String argv[]){
System.out.println("Ms "+argv[1]+"Please pay $"+x);
}
What will happen if you attempt to compile and run this code with the command line
java Sytch Jones Diggle
1) Compilation and output of Ms Diggle Please pay $2000
2) Compile time error
3) Compilation and output of Ms Jones Please pay $2000
4) Compilation but runtime error
Q5.You have a public class called myclass with the main method defined as follows(4)
public static void main(String parm[]){
System.out.println(parm[0]);
}
If you attempt to compile the class and run the program as follows
java myclass hello
What will happen?
1) Compile time error, main is not correctly defined
2) Run time error, main is not correctly defined
3) Compilation and output of java
4) Compilation and output of hello
[JAVA题库:考考你]
1、Examine the following code which includes an inner class:
public final class Test4{
class Inner{
void test(){
if (Test4.this.flag);{
sample();
}
}
}
private boolean flag=false;
public void sample(){
System.out.println("Sample");
}
public Test4(){
(new Inner()).test();
}
public static void main(String args[]){
new Test4();
}
}
What is the result:
A.Print out “Sample”
B.Program produces no output but termiantes correctly.
C. Program does not terminate.
D.The program will not compile
答案:A
2、What will happen when you attempt to compile and run the following code?
class Base {
int i = 99;
public void amethod() {
System.out.println("Base.amethod()");
}
Base() {
amethod();
}
}
public class Derived extends Base{
int i = -1;
public static void main(String argv[]) {
Base b = new Derived();
System.out.println(b.i);
b.amethod();
}
public void amethod() {
System.out.println("Derived.amethod()");
}
}
A. Derived.amethod()
-1
Derived.amethod()
B. Derived.amethod()
99
Derived.amethod()
C. 99
Derived.amethod()
D.
Compile time error
答案:B
3、public class Test{
public static void main(String[] args){
StringBuffer a=new StringBuffer("A");
StringBuffer b=new StringBuffer("B");
operate(a,b);
System.out.pintln(a+","+b);
}
public static void operate(StringBuffer x, StringBuffer y){
x.append(y);
y=x;
}
}
what is the output?
答案:"AB,B"
4、public class Test{
public static void stringReplace(String text){
text=text.replace('j','l');
}
public static void bufferReplace(StringBuffer text){
text=text.append("c");
}
public static void main(String args[]){
String textString=new String("java");
StringBuffer textBuffer=new StringBuffer("java");
stringReplace(textString);
bufferReplace(textBuffer);
System.out.println(textString+textBuffer);
}
}
what is the output?
答案:"javajavac"
5、public class Test{
static void leftshift(int i, int j){
i<<=j;
}
public static void main(String args[]){
int i=4, j=2;
leftshift(i,j);
System.out.println(i);
}
}
what is the result?
答案:4
Java编程练习题库
【1】编译运行如下程序的结果是什么 ?
class InvalidIndexException extends Exception{
private int i;
InvalidIndexException(int a){
i=a;
}
public String toString(){
return i+" is out of boundary--0 < i < 8";
}
}
public class Weekdays{
public static void main(String args[]){
try{
for (int i=1; i < 9; i++) System.out.println(i+"---"+giveName(i));
}catch(InvalidIndexException e){
System.out.println(e.toString());
}finally{ System.out.println("These days makes up a week.");}
}
public static String giveName(int d) {
String name;
switch(d){
case 1: name="Monday"; break;
case 2: name="Tuesday"; break;
case 3: name="Wednesday"; break;
case 4: name="Thursday"; break;
case 5: name="Friday"; break;
case 6: name="Saturday"; break;
case 7: name="Sunday"; break;
default: throw new InvalidIndexException(d);
}
return name;
}
}
(A) 1---Monday
2---Tuesday
3---Wednesday
4---Thursday
5---Friday
6---Saturday
7---Sunday
These days makes up a week.
(B) 1---Monday
2---Tuesday
3---Wednesday
4---Thursday
5---Friday
6---Saturday
7---Sunday
8 is out of boundary--0 < i < 8
These days makes up a week.
(C) 1---Monday
2---Tuesday
3---Wednesday
4---Thursday
5---Friday
6---Saturday
7---Sunday
(D) 编 译 不 能 通 过。
答 案:(B)
【2】 有 如 下 一 段Java 程 序:
import java.io.*;
public class Quiz1{
public static void main(String arg[]){
int i;
System.out.print("Go ");
try{
System.out.print("in ");
i=System.in.read();
if (i=='0') {throw new MyException();}
System.out.print("this ");
}
catch(IOException e){}
catch(MyException e){
System.out.print("that ");
}
System.out.print("way.\n");
}
}
class MyException extends Exception{}
运 行 该 程 序 后 输 入 字 符'0', 请 问 运 行 结 果 为 何 ?
(A)Go in this way
(B)Go in that this way
(C)Go in that
(D)Go in that way
答 案:(D)
【3】 下 面 程 序 的 输 出 是 什 么 ?
public class Quiz2{
public static void main(String args[]){
try {throw new MyException();
}catch(Exception e){
System.out.println("It's caught!");
}finally{
System.out.println("It's finally caught!");
}
}
}
class MyException extends Exception{}
(A)It's finally caught!
(B)It's caught!
(C)It's caught!
It's finally caught!
(D)无 输 出
答 案:(C)
【4】 下 面 的 程 序 是 一 个 嵌 套 例 外 处 理 的 例 子, 请 选 择 其 运 行 结 果:
public class Quiz3{
public static void main(String args[]){
try{
try{
int i;
int j=0;
i=1/j;
}catch(Exception e){
System.out.print("Caught ");
throw e;
}finally{
System.out.print("Inside ");
}
}catch(Exception e){
System.out.print("Caught ");
}finally{
System.out.print("Outside\n");
}
}
}
(A)Caught Outside
(B)Caught Inside
(C)Caught Caught Outside
(D)Caught Inside Caught Outside
答 案:(D)
【5】Java 运 行 时 例 外 是 在 运 行Java 程 序 时 由Java 运 行 时 系 统 负 责 抛 出 的 一 系 列 例 外。 本 章 例 程 中 所 提 到 的 许 多 例 外 就 是Java 运 行 时 例 外( 详 见 例8.2 等)。 请 详 细 阅 读 例 程, 选 择 对 于 如 下 的 程 序, 系 统 将 抛 出 哪 个 运 行 时 例 外。
class Quiz4{
int a[]=new int[10];
a[10]=0;
}
(A)ArithmeticException
(B)ArrayIndexOutOfBoundsException
(C)NegativeArraySizeException
(D)IllegalArgumentException
答 案:(B)
【6】 为 了 编 程 需 要, 现 需 自 己 编 写 一 个 例 外 类。 一 般 说 来, 下 面 声 明 哪 个 最 为 合 适 ?
(A)class myClass extentds Exception{...
(B)class myException extends Error{...
(C)class myException extends RuntimeException{...
(D)class myException extends Exception{...
答 案:(D)