杂记1

1.拦截器和过滤器的区别:
很多人都了解过滤器也听说过拦截器,但是要是区分它们的不同点还真是真的说不清楚,一下可以简要的说明:
1、拦截器是基于java的反射机制的,而过滤器是基于函数回调
2、拦截器不依赖与servlet容器,而过滤器依赖与servlet容器
3、拦截器只能对action请求起作用,而过滤器则可以对几乎所有的请求起作用
4、拦截器可以访问action上下文、值栈里的对象,而过滤器不能
5、在action的生命周期中,拦截器可以多次被调用,而过滤器只能在容器初始化时被调用一次

2.The different between struts and struts2

说出java中的Immutable类有哪些?
String,基本类型的包装类,BigInteger and BigDecimal都是不变类


3.The different between String and StringBuffer

4.父类的私有构造子类能调用吗 不能

抽象类与接口的区别


how to sort the arrayList of Object?
Collections.sort(list)
===========
按年月日yyyy-mm-dd输出当前时间:
Calendar cal = Calendar.getInstance();
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(formatter.format(new Date()));
System.out.println(formatter.format(cal.getTime()));//the same result as below

字符串逆序
String str="abc";
StringBuffer str2=new StringBuffer(str);
str2.reverse();
System.out.println(str2);


4.尽量多写出IO类

5.字符串中indexOf,chatAt,parseInt方法的使用


二叉树的定义和特性

servlet在什么时候调用 destroy方法?
destroy方法在容器移除servlet时执行,同样只执行一次。这个方法会在所有的线程的service()方法执行完成或者超时后执行,调用这个方法后,
容器不会再调用这个servlet的方法,也就是说容器不再把请求发送给这个servlet。这个方法给servlet释放占用的资源的机会,通常用来执行一些清理任务。
上面的是jdk API文档中定义,我这儿有个英文版的
Called by the servlet container to indicate to a servlet that the servlet is being taken out of service.
This method is only called once all threads within the servlet's service method have exited or after a timeout period has passed.
After the servlet container calls this method, it will not call the service method again on this servlet.
这个方法只有在servlet的service方法内的所有线程都退出的时候,或在超时的时候才会被调用。


=====
JDBC使用模板:
Class.forName( "oracle.jdbc.driver.OracleDriver" );
Connection cn = DriverManager.getConnection( "jdbc:oracle:thin:@MyDbComputerNameOrIP:1521:ORCL", userName, password );
Statement s = c.createStatement();
ResultSet r = s.executeQuery( );
while(r.next()) { }
===================
1. I can use hibernate to execute the native SQL.
如果我要利用具体数据库的特性,例如在oracle加提示或connect关键字,这个直接执行sql就很有用了。
这个也提供了从基于应用的SQL/JDBC迁移到Hibernate的清晰的方式。
Hibernate3 allows you to specify handwritten SQL, including stored procedures, for all create, update, delete, and load operations.
session.createSQLQuery(sql字符串)
These will return a List of Object arrays (Object[])
sess.createSQLQuery("SELECT * FROM CATS")
.addScalar("ID", Hibernate.LONG)
.addScalar("NAME", Hibernate.STRING)
.addScalar("BIRTHDATE", Hibernate.DATE)

This also means that only these three columns will be returned, even though the query is using * and could return more than the three listed columns.

假设Cat被映射为拥有ID,NAME和BIRTHDATE三个字段的类,以上的两个查询都返回一个List,每个元素都是一个Cat实体。

sess.createSQLQuery("SELECT ID, NAME, BIRTHDATE, DOG_ID FROM CATS").addEntity(Cat.class);


2.
通过一些现象,可以反映出隔离级别的效果。这些现象有:
更新丢失(lost update):当系统允许两个事务同时更新同一数据是,发生更新丢失。

脏读(dirty read):当一个事务读取另一个事务尚未提交的修改时,产生脏读。

非重复读(nonrepeatable read):同一查询在同一事务中多次进行,由于其他提交事务所做的修改或删除,每次返回不同的结果集,此时发生非重复读。
幻像(phantomread):同一查询在同一事务中多次进行,由于其他提交事务所做的插入操作,每次返回不同的结果集,此时发生幻像读。


read committed:

l 这是ORACLE缺省的事务隔离级别。

l 事务中的每一条语句都遵从语句级的读一致性。

l 保证不会脏读;但可能出现非重复读和幻像。

---
Oracle的SQL语句里面有没有类似mysql里Auto_Increment的语句?
没有auto_increment
要实现只能用sequence+trigger

--Oracle自动增长字段 --
一 建立表 create table ZH_TEST ( ID NUMBER not null, NAME VARCHAR2(20) )
--二 建立sequence
create sequence ZH_AUTOINC minvalue 1 start with 1 increment by 1 nocache;
--三 建立触发器
create or replace trigger INSERT_FOR_AUTOINC
before insert on ZH_TEST
for each row
declare
-- local variables here
begin
select ZH_AUTOINC.nextval into:new.ID from dual;
end insert_for_autoinc;
--四 用insert语句测试
insert into ZH_TEST(NAME) values ('z5');

这样你就可以不用每次插入数据的时候,都指定ID值为ZH_AUTOINC.nextval了
---
java Class.forName的作用:
调用该方法返回一个以字符串指定类名的类的对象。
==========

public class Test {
public static void main(String[] args) {
try{
System.out.println("a");
throw new RuntimeException();
}
finally{System.out.println("x");}
}
}
============================================

public static byte function() {
short i = 1;
int j = 1111111110;
return (byte)(j/i);

}
返回的不是正确的数据,数据被截断了,但是编译器不报错
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值