1..运行下面的程序会到得什么结果?
对于int a = 2; int b = (a++) + 3*a;这样的语句,b最终等于多少呢?
答: 11
2.下面程序的结果是什么?
String str1 = “abc”;
String str2 = “abc”;
System.out.println(str1 == str2);
答: true
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);
}
}
答:good-bye
hello
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){
new InitialOrderTest();
new InitialOrderTest();
}
}
答:
静态变量
静态初始化块
变量
初始化块
构造器
变量
初始化块
构造器
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++;// 局部变量
}
}
输出结果: 0
7.给你的数组赋值,而不使用for循环语句,下面的哪一个能做到? (单选) c
1) String s[] = new String[5]{“Zero”, ”One”, ”Two”, ”Three”, ”four”};
2) String s[5] = new String[]{“Zero”, ”One”, ”Two”, ”Three”, ”four”};
3) String s[] = new String[]{“Zero”, ”One”, ”Two”, ”Three”, ”four”};
4) String s[] = new String[]={“Zero”, ”One”, ”Two”, ”Three”, ”four”};
8.以下程序的打印结果是什么?(单选) c
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属性修改了两次:b
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对象在第几行变为持久化状态?(单选)f
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{
int x = 0;
}
class B{
int x =1;
}
class C extends B implements A{
public void pX(){
System.out.println(x);// A.x super.x
}
public static void main(String[] args){
new C().pX();
}
}
12.解答:
SQL基本知识
1)使用SQL查找A表,条件为A表中有但B表中没有的记录,A,B两表关联字段为id
答:
select * from A where not exist select null from b where b.id=id
2)查询user表中name字段,有重复的记录
答:
select *
from User u
where u.user_name in (select
u.user_name
from User u
group by u.user_name having count(*) > 1)