1. 运行下面的程序会到得什么结果?
对于inta = 2; int b = (a++) + 3*a;这样的语句,b最终等于多少呢?
答:
2. 下面程序的结果是什么?
String str1 = “abc”;
String str2 = “abc”;
System.out.println(str1 == str2);
答:
3. 运行下面的程序会得到什么结果?
Class Tester{
int var;
Tester(double var){
this.var= (int)var;
}
Tester(int var){
this(“hello”);
}
Tester(String s){
this();
System.out.println(s);
}
Tester(){
System.out.println(“good-bye”);
}
public static void main(String[] args){
Tester t = new Tester(5);
}
}
答:
4. 运行下面的程序会得到什么结果?
public class InitialOrderTest{
public static String staticField = “静态变量”;
public String field = “变量”;
static{
System.out.println(staticField);
System.out.println(“静态初始化块”);
}
{
System.out.println(field);
Ssytem.out.println(“初始化块”);
}
public InitialOrderTest(){
System.out.println(“构造器”);
}
public static void main(String[] args){
newInitialOrderTest();
}
}
答:
5. 运行下面的程序会得到什么结果?
public class ThreadTest implements Runnable{
public synchronized void run(){
for(int i=0; i<10; i++){
System.out.println(“”+i);
}
}
public static void main(String[] args){
Runnable r1 =new ThreadTest();
Runnable r2 =new ThreadTest();
Thread t1 =new Thread(r1);
Thread t2 =new Thread(r2);
t1.start();
t2.start();
}
}
输出结果:
6. 运行下面的程序会得到什么结果?
public class X{
private static int a;
public static void main(String[] args){
modify(a);
System.out.println(a);
}
public static void modify(int a){
a++;
}
}
输出结果:
7. 给你的数组赋值,而不使用for循环语句,下面的哪一个能做到? (单选)
1) Strings[] = new String[5]{“Zero”, ”One”, ”Two”, ”Three”, ”four”};
2) Strings[5] = new String[]{“Zero”, ”One”, ”Two”, ”Three”, ”four”};
3) Strings[] = new String[]{“Zero”, ”One”, ”Two”, ”Three”, ”four”};
4) Strings[] = new String[]={“Zero”, ”One”, ”Two”, ”Three”, ”four”};
8. 以下程序的打印结果是什么?(单选)
1. tx = session.beginTransaction();
2. Customer c1 =(Customer)session.load(Customer.class, new Long(1));
3. Customer c2 =(Customer)session.load(Customer.class, new Long(1));
4. System.out.println(c1 == c2);
5. tx.commit();
6. session.close();
A. 运行出错, 抛出异常
B. 打印false
C. 打印true
9. 以下程序代码对Customer的name属性修改了两次:
1. tx= session.beginTransaction();
2. Customer customer = (Customer)session.load(Customer.class, new Long(1));
3. customer.setName(”Jack”);
4. customer.setName(”Mike”);
5. tx.commit();
执行以上程序,Hibernate需要向数据库提交几条update语句?(单选)
A. 0 B. 1 C. 2 D. 3
10. 对于以下程序,Customer对象在第几行变为持久化状态?(单选)
Customer customer = new Customer(); //line1
customer.setName(”Tom”); //line2
Session session1 =sessionFactory.openSession(); //line3
Transaction tx1 =session1.beginTransaction(); //line4
session1.save(customer); //line5
tx1.commit(); //line6
session1.close(); //line7
A. line1 B. line2 C. line3 D. line4 E. line5 F. line6 G. line7
11. 下面程序运行会发生什么结果?如果有错误,如何改正?
interface A{
intx = 0;
}
class B{
intx =1;
}
class C extends B implements A{
public void pX(){
System.out.println(x);
}
public static void main(String[] args){
newC().pX();
}
}
12. 解答:
SQL基本知识
1) 使用SQL查找A表,条件为A表中有但B表中没有的记录,A,B两表关联字段为id
解答:
2) 查询user表中name字段,有重复的记录
解答: