- 浏览: 1151112 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (411)
- Java Foundation (41)
- AI/机器学习/数据挖掘/模式识别/自然语言处理/信息检索 (2)
- 云计算/NoSQL/数据分析 (11)
- Linux (13)
- Open Source (12)
- J2EE (52)
- Data Structures (4)
- other (10)
- Dev Error (41)
- Ajax/JS/JSP/HTML5 (47)
- Oracle (68)
- FLEX (19)
- Tools (19)
- 设计模式 (4)
- Database (12)
- SQL Server (9)
- 例子程序 (4)
- mysql (2)
- Web Services (4)
- 面试 (8)
- 嵌入式/移动开发 (18)
- 软件工程/UML (15)
- C/C++ (7)
- 架构Architecture/分布式Distributed (1)
最新评论
-
a535114641:
LZ你好, 用了这个方法后子页面里的JS方法就全不能用了呀
页面局部刷新的两种方式:form+iframe 和 ajax -
di1984HIT:
学习了,真不错,做个记号啊
Machine Learning -
赵师傅临死前:
我一台老机器,myeclipse9 + FB3.5 可以正常使 ...
myeclipse 10 安装 flash builder 4.6 -
Wu_Jiang:
触发时间在将来的某个时间 但是第一次触发的时间超出了失效时间, ...
Based on configured schedule, the given trigger will never fire. -
cylove007:
找了好久,顶你
Editable Select 可编辑select
q:String s = new String("obj"),创建了几个对象?那Person p = new Person()那?
a:两个。Person p = new Person()肯定只创建了一个了。
java api中对问题中所用String构造方法的解释:
public String(String original)
Initializes a newly created String object so that it represents the same sequence of characters as the argument; in other words, the newly created string is a copy of the argument string. Unless an explicit copy of original is needed, use of this constructor is unnecessary since Strings are immutable.
so,original String 和new出的这个String,总共两个String对象!
String a = new String("foo");
第一次执行时创建了二个, 一个为字面量"foo"(它本身是一个String对象), 一个为new String("foo")(它是通过new创建的, 功能上和字面量"foo"完全一样, 但却是另一个对象).
第二次执行时, 只创建一个, 即new String("foo"), 这是因为: "foo"作为String字面量, 是存在于String Pool里面的, 第二次使用它时, 直接指向原有的String, 而不再创建新的String; 但new String("foo")却每执行一次都创建一个新的,完全一样的String对象.
因此, 结论是: 永远不要使用 String a = new String("foo");这种方式来创建字符串, 而要用String a = "foo";这种方式. 这一点在<Effetive JAVA>第四条中说得很清楚了.
关于String的intern()方法:
When the intern method is invoked, if the pool already contains a string equal to this String object as determined by the equals(Object) method, then the string from the pool is returned. Otherwise, this String object is added to the pool and a reference to this String object is returned.
扩展:
创建了多少个对象?
6个。
String str1 = "a"+"b"+"c";
这个创建了:
1、"a"
2、"b"
3、"c"
4、"ab"
5、"abc"
总计5个
String str2 = new String("a"+"b"+"c");
这个比上面还多一个new创建的对象
时把握几点:
1、每个字符串都是常量,所以"a"、"b"、"c"都是一个个的对象
2、每次操作都会产生新的字符串对象,例如"ab"和"abc"
3、遇到new则申请内存,创建新的对象
q:咋样通过已有表创建新表?
a:
sqlserver中用select * into newtable from oldtable where 1=0
oracle和mysql中用create table newtable as select * from oldtable where 1=0
加where条件是为了过滤掉旧表中的数据;不加的话,旧表中的数据也全部会被copy到新表中
q:简述weblogic的部署;weblogic的热启动是什么?
a:建一个domain;项目直接打成war包放domain里;配置数据源时需要修改其配置文件。
q:
a:输出为0.
解释:
count=count+(count++),为了方便,姑且把这个式子记为A=B+C,假设在计算前,count的值是M
计算机的计算过程应该是这样的:
1.先对B、C的数据分配寄存器,并将B的值M直接赋值到寄存器中(因为这个值对于寄存器来讲是常量);
2.由于C部分是count++,所以将C的值M也存入寄存器中;
3.计算++操作,此时内存中count的值变为M+1,但这个改变对B和C在寄存器中的值并没有影响;
4.计算寄存器中的B+C,的到结果M+M,即2M;
5.将计算结果2M写入到内存中count的存储单元。
所以++操作并不是没有执行,而是被后来的操作覆盖掉了。整个表达式的结果与count+=count没有差别,但计算时间要稍长,不过这个时间差不会被感觉到。
这种表达式在学习语法和计算机体系结构的时候还是可以的,在实际工程中一定不要使用,小心老板炒了你……
扩展:
输出为
i: 0
j: 1
k: 1
l: 3
解释:
Prefix behavior
With the prefix version, the variable is incremented before it is used to evaluate the larger overall expression.
Postfix behavior
With the postfix version, the variable is used to evaluate the larger overall expression and then it is incremented.
http://www.coderanch.com/t/411691/Beginning-Java/java/about
This is a classic pitfall which everybody falls for; if you do a search of JavaRanch you will find it comes up several times a year.
There are two values you need to consider; the value of the variable i and the value of the expression i++. When you start off, the value of i is 0, but the value of i++ is the old value of i, still 0.
You start going into the i = i++; statement; the first things that happen are that i++ is evaluated (as stated previously that is 0) and i is incremented, so it is now 1.
Then what happens is that i is set to the value of whatever is to the right of the =, which we have already seen is 0. The value 1 vanishes into cyber-limbo never to be seen again.
Try changing that statement to i = ++i; and see what happens.
下面的程序,哪个程序有误?
答案是A。
析:
在Java语言规范中讲,复合赋值 E1 op= E2等价于简单赋值E1 = (T)((E1)op(E2)),其中T是E1的类型,除非E1只被计算一次。换句话说,复合赋值表达式自动地将它们所执行的计算的结果转型为其左侧变量的类型。如果结果的类型与该变量的类型相同,那么这个转型不会造成任何影响。然而,如果结果的类型比该变量的类型要宽,那么复合赋值操作符将悄悄地执行一个窄化原始类型转换。
So,针对本题,s=s+1需要强制类型转换,即s=(short)(s+1);对于答案B,s+=1属于复合赋值表达式,会自动地将它们所执行的计算的结果转型为其左侧变量的类型。
扩展:
输出:
-128
-128
j2ee十三种核心技术?三种ejb?
JDBC, JNDI, EJBs, RMI, JSP, Java servlets, XML, JMS, Java IDL, JTS, JTA, JavaMail 和 JAF;
EJB 依照特性的不同,目前区分为三种,分别是 Session Bean ,Entity Bean ,以及 Message Driven Bean
q:曾经采用ThrealLocal模式实现分页;为什么把分页变量放threadlocal里那?这样设计的原因是什么?
a:基于线程安全的考虑
q:自定义一个exception,用spring来做声明式事务管理,在持久化操作时出问题时抛出自定义异常。在一次持久化操作中,自定义异常被抛出(没有用try-catch吞掉它),可是事务没有回滚,为什么?
A:spring官方解答:
http://static.springsource.org/spring/docs/2.5.x/reference/transaction.html#transaction-declarative-rolling-back
Note however that the Spring Framework's transaction infrastructure code will, by default, only mark a transaction for rollback in the case of runtime, unchecked exceptions; that is, when the thrown exception is an instance or subclass of RuntimeException. (Errors will also - by default - result in a rollback.) Checked exceptions that are thrown from a transactional method will not result in the transaction being rolled back.
Exactly which Exception types mark a transaction for rollback can be configured
When the Spring Framework's transaction infrastructure has caught an exception and is consulting any configured rollback rules to determine whether or not to mark the transaction for rollback, the strongest matching rule wins. So in the case of the following configuration, any exception other than an InstrumentNotFoundException would result in the attendant transaction being marked for rollback:说明:问题中已说明“自定义异常被抛出”,异常没有被吞掉;如果没这句说明,这事务未回滚的原因除了因为“spring默认只在捕获unchecked exception时触发事务回滚”外,还可能是因为你用try-catch块将这个unchecked exception捕获了,并且没有在catch后调用spring api对事务进行显式回滚(即:把它吞掉了),没有抛出它!(不管用try-catch捕获service方法的unchecked exception是否符合设计原则,但这确实是可能的一个原因。)
解决的办法:
1 自定义异常定义成RumtimeException的子类(抛出一个unchecked exceptioon是没有意义的,所以不推荐这种做法)
2 在spring的事务拦截定义中为具体要拦截的方法设置其在抛出自定义异常时回滚。这里给出一个TransactionProxyFactoryBean中配置的例子:
关于transaction attribute descriptors that parsed via TransactionAttributeEditor:
http://static.springsource.org/spring/docs/3.0.0.M1/javadoc-api/org/springframework/transaction/interceptor/TransactionAttributeEditor.html
http://forum.springsource.org/showthread.php?t=38515
public class TransactionAttributeEditor
extends java.beans.PropertyEditorSupport
PropertyEditor for TransactionAttribute objects. Accepts a String of form
PROPAGATION_NAME,ISOLATION_NAME,readOnly,timeout_NNNN,+Exception1,-Exception2
where only propagation code is required. For example:
PROPAGATION_MANDATORY,ISOLATION_DEFAULT
The tokens can be in any order. Propagation and isolation codes must use the names of the constants in the TransactionDefinition class. Timeout values are in seconds. If no timeout is specified, the transaction manager will apply a default timeout specific to the particular transaction manager.
A "+" before an exception name substring indicates that transactions should commit even if this exception is thrown; a "-" that they should roll back.
Null or the empty string means that the method is non transactional.
q:hibernate用户信息实体类Userinfo的主键生成策略为uuid;但在保存用户信息时为其指定了Id的值,问这段代码能顺利执行吗?
a:数据被成功插入,并且通过调用setId设置的id值无效,如图就是刚插入的数据:
q;下面语句的输出是什么:
a:输出:
false
false
2
3.1
test
Q:下列代码执行的结果是什么?
析:反编译class文件看到的内容:
jdbc、hibernate、ibatis的区别?
ext缺点?
Q:区别:
StringBuffer StringBuilder
Vector ArrayList
HashTable HashMap
A:
Q:oracle数据库,emp表中总共有14条记录,执行以下sql,结果是什么?why?
A:执行结果见上SQL代码区域中的注释。原因分析见:
http://www.iteye.com/topic/197531
http://wuaner.iteye.com/blog/433836
Q:java中char类型是否可以表示汉字?
A:可以,因为java中char占两个字节。
Q:Math.round(11.5) = ? ; Math.round(-11.5) = ?
A:Math.round(11.5) = 12 ; Math.round(-11.5) = -11 . 详见:
http://wuaner.iteye.com/admin/blogs/1008648
Q:switch能否作用在btye上、long上、String上?
A:在switch(expr1)中,expr1只能是一个整数表达式或者枚举常量(更大字体),整数表达式可以是int基本类型或Integer包装类型,由于,byte,short,char都可以隐含转换为int,所以,这些类型以及这些类型的包装类型也是可以的。显然,long 和 String 类型都不符合 switch 的语法规定,并且不能被隐式转换成int类型,所以,它们不能作用于 swtich 语句中。
Q:是否可以:接口继承接口? 抽象类实现接口? 抽象类继承实体类?
A:都可以。
Q:Class.forName的作用?为什么用?
A:用来加载类。之所以要用它,是因为它可以实现动态加载,为系统提供更大的灵活性,让系统维持轻量级。具体请参阅该PDF文档:
http://www.theserverside.com/news/1365412/Understanding-ClassforName-Java
Q:jsp中动态include和静态include的区别?
A:
Q:servlet的生命周期?
A:
Q:如果系统要使用超大整数(超过long表示范围),请设计一个数据结构来存储这种超大整数,并设计一种算法来实现超大整数加法运算。
A:
Q:
A:A、D、E 。 当初答的时候没tm看清题目!草的,引以为戒!
Q:
A :答案肯定是C、E了。当初答题压根就没注意还有个E选项!以后读英文卷子可得tm细心点!
Q:
A:答案是C。
析:first,set里元素没有顺序,不可以重复,所以第六行往TreeSet里再次加字符串"one"是加不进去的;
second,因为该set里放的是String,所以用的是String的natural ordering(所谓natural ordering,就是那些已经实现了Comparable接口的类,重写了该接口的compareTo()方法,等于是这些类在同类的对象间比较时有了个JDK就定义了的比较方式,这种JDK内定义的比较方方式就称为natural ordering)。附上JDK中String类中compareTo方法解释:
Q:
A. public void run() { write(); }
B. public synchronized void run() { write(); }
C. public static synchronized void run() { write(); }
D. public void run() { synchronized(this) { write(); } }
E. public void run() { synchronized(Letters.class) { write(); } }
F. public void run() { synchronized(System.out) { write(); } }
G. public void run() { synchronized(System.out.class) { write(); } }
A:
析:http://www.coderanch.com/t/417999/java-programmer-SCJP/certification/Synchronizing-thread
http://www.coderanch.com/t/262030/java-programmer-SCJP/certification/book-Threads-Exercise
关于两个正确选项的更详细解释,请参加本博客:
http://wuaner.iteye.com/admin/blogs/998696
Q:下列代码:
A:不会报错,会输入5.
析:java static field from null:
http://stackoverflow.com/questions/6782276/java-static-field-from-null
Q:为什么非主键索引会降低更新速度,提高查询速度?
A:非主键索引需要在数据表本身的存储空间外额外开销存储空间,所以在更新的时候可能不仅要更新数据表本身,还要更新非主键索引,更新内容更多了,所以导致速度降低。反过来,如果数据表中的数据按照主键索引的顺序存储,更新的时候就没有额外的开销。
非主键索引对提高查询速度来讲,主要的方面是:检索的条件(where...)如果命中对应的非主键索引的话,就不需要对数据表做全表扫描,效率肯定是大大提高。
Q:设一个散列表包含hashSize=13个表项,其下标从0到12。采用除留余数法作为散列函数,线性探查法解决冲突.,将下列关键码散列到表中:
10 100 32 45 58 126 3 29 200 400 0
A:
Q:简述TCP/IP三次握手
A:A与B建立TCP连接时:首先A向B发SYN(同步请求),然后B回复SYN+ACK(同步请求应答),最后A回复ACK确认,这样TCP的一次连接就通过这三次握手建立起来了!
http://www.inetdaemon.com/tutorials/internet/tcp/3-way_handshake.shtml
a:两个。Person p = new Person()肯定只创建了一个了。
java api中对问题中所用String构造方法的解释:
public String(String original)
Initializes a newly created String object so that it represents the same sequence of characters as the argument; in other words, the newly created string is a copy of the argument string. Unless an explicit copy of original is needed, use of this constructor is unnecessary since Strings are immutable.
so,original String 和new出的这个String,总共两个String对象!
String a = new String("foo");
第一次执行时创建了二个, 一个为字面量"foo"(它本身是一个String对象), 一个为new String("foo")(它是通过new创建的, 功能上和字面量"foo"完全一样, 但却是另一个对象).
第二次执行时, 只创建一个, 即new String("foo"), 这是因为: "foo"作为String字面量, 是存在于String Pool里面的, 第二次使用它时, 直接指向原有的String, 而不再创建新的String; 但new String("foo")却每执行一次都创建一个新的,完全一样的String对象.
因此, 结论是: 永远不要使用 String a = new String("foo");这种方式来创建字符串, 而要用String a = "foo";这种方式. 这一点在<Effetive JAVA>第四条中说得很清楚了.
关于String的intern()方法:
When the intern method is invoked, if the pool already contains a string equal to this String object as determined by the equals(Object) method, then the string from the pool is returned. Otherwise, this String object is added to the pool and a reference to this String object is returned.
扩展:
引用
String str1 = "a"+"b"+"c"; String str2 = new String("a"+"b"+"c");
创建了多少个对象?
6个。
String str1 = "a"+"b"+"c";
这个创建了:
1、"a"
2、"b"
3、"c"
4、"ab"
5、"abc"
总计5个
String str2 = new String("a"+"b"+"c");
这个比上面还多一个new创建的对象
时把握几点:
1、每个字符串都是常量,所以"a"、"b"、"c"都是一个个的对象
2、每次操作都会产生新的字符串对象,例如"ab"和"abc"
3、遇到new则申请内存,创建新的对象
q:咋样通过已有表创建新表?
a:
引用
sqlserver中用select * into newtable from oldtable where 1=0
oracle和mysql中用create table newtable as select * from oldtable where 1=0
加where条件是为了过滤掉旧表中的数据;不加的话,旧表中的数据也全部会被copy到新表中
q:简述weblogic的部署;weblogic的热启动是什么?
a:建一个domain;项目直接打成war包放domain里;配置数据源时需要修改其配置文件。
q:
int count = 0; for(int i=0; i<100; i++) { count+=count++; } System.out.println("count : " + count);
a:输出为0.
引用
解释:
count=count+(count++),为了方便,姑且把这个式子记为A=B+C,假设在计算前,count的值是M
计算机的计算过程应该是这样的:
1.先对B、C的数据分配寄存器,并将B的值M直接赋值到寄存器中(因为这个值对于寄存器来讲是常量);
2.由于C部分是count++,所以将C的值M也存入寄存器中;
3.计算++操作,此时内存中count的值变为M+1,但这个改变对B和C在寄存器中的值并没有影响;
4.计算寄存器中的B+C,的到结果M+M,即2M;
5.将计算结果2M写入到内存中count的存储单元。
所以++操作并不是没有执行,而是被后来的操作覆盖掉了。整个表达式的结果与count+=count没有差别,但计算时间要稍长,不过这个时间差不会被感觉到。
这种表达式在学习语法和计算机体系结构的时候还是可以的,在实际工程中一定不要使用,小心老板炒了你……
扩展:
引用
int i = 0; i = i++; System.out.println("i: " + i); int j = 0; j = ++j; System.out.println("j: " + j); int k = 0; k = k++ + k++; System.out.println("k: " + k); int l = 0; l = ++l + ++l; System.out.println("l: " + l);
输出为
i: 0
j: 1
k: 1
l: 3
解释:
Prefix behavior
With the prefix version, the variable is incremented before it is used to evaluate the larger overall expression.
Postfix behavior
With the postfix version, the variable is used to evaluate the larger overall expression and then it is incremented.
http://www.coderanch.com/t/411691/Beginning-Java/java/about
This is a classic pitfall which everybody falls for; if you do a search of JavaRanch you will find it comes up several times a year.
There are two values you need to consider; the value of the variable i and the value of the expression i++. When you start off, the value of i is 0, but the value of i++ is the old value of i, still 0.
You start going into the i = i++; statement; the first things that happen are that i++ is evaluated (as stated previously that is 0) and i is incremented, so it is now 1.
Then what happens is that i is set to the value of whatever is to the right of the =, which we have already seen is 0. The value 1 vanishes into cyber-limbo never to be seen again.
Try changing that statement to i = ++i; and see what happens.
下面的程序,哪个程序有误?
A. short s=1; s=s+1; B. short s=1; s+=1;
答案是A。
析:
在Java语言规范中讲,复合赋值 E1 op= E2等价于简单赋值E1 = (T)((E1)op(E2)),其中T是E1的类型,除非E1只被计算一次。换句话说,复合赋值表达式自动地将它们所执行的计算的结果转型为其左侧变量的类型。如果结果的类型与该变量的类型相同,那么这个转型不会造成任何影响。然而,如果结果的类型比该变量的类型要宽,那么复合赋值操作符将悄悄地执行一个窄化原始类型转换。
So,针对本题,s=s+1需要强制类型转换,即s=(short)(s+1);对于答案B,s+=1属于复合赋值表达式,会自动地将它们所执行的计算的结果转型为其左侧变量的类型。
扩展:
byte b = 127; b += 1; System.out.println(b); byte a = 127; a = (byte)(a+1);//写成"a = a+1"无法编译通过,报:"cannot convert from int to byte" System.out.println(a);
输出:
-128
-128
j2ee十三种核心技术?三种ejb?
JDBC, JNDI, EJBs, RMI, JSP, Java servlets, XML, JMS, Java IDL, JTS, JTA, JavaMail 和 JAF;
EJB 依照特性的不同,目前区分为三种,分别是 Session Bean ,Entity Bean ,以及 Message Driven Bean
q:曾经采用ThrealLocal模式实现分页;为什么把分页变量放threadlocal里那?这样设计的原因是什么?
a:基于线程安全的考虑
q:自定义一个exception,用spring来做声明式事务管理,在持久化操作时出问题时抛出自定义异常。在一次持久化操作中,自定义异常被抛出(没有用try-catch吞掉它),可是事务没有回滚,为什么?
A:spring官方解答:
http://static.springsource.org/spring/docs/2.5.x/reference/transaction.html#transaction-declarative-rolling-back
引用
Note however that the Spring Framework's transaction infrastructure code will, by default, only mark a transaction for rollback in the case of runtime, unchecked exceptions; that is, when the thrown exception is an instance or subclass of RuntimeException. (Errors will also - by default - result in a rollback.) Checked exceptions that are thrown from a transactional method will not result in the transaction being rolled back.
Exactly which Exception types mark a transaction for rollback can be configured
When the Spring Framework's transaction infrastructure has caught an exception and is consulting any configured rollback rules to determine whether or not to mark the transaction for rollback, the strongest matching rule wins. So in the case of the following configuration, any exception other than an InstrumentNotFoundException would result in the attendant transaction being marked for rollback:
<tx:advice id="txAdvice"> <tx:attributes> <tx:method name="*" rollback-for="Throwable" no-rollback-for="InstrumentNotFoundException"/> </tx:attributes> </tx:advice>
解决的办法:
1 自定义异常定义成RumtimeException的子类(抛出一个unchecked exceptioon是没有意义的,所以不推荐这种做法)
2 在spring的事务拦截定义中为具体要拦截的方法设置其在抛出自定义异常时回滚。这里给出一个TransactionProxyFactoryBean中配置的例子:
<bean id="baseTxService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true"> <property name="transactionManager" ref="transactionManager" /> <property name="proxyTargetClass"> <value>true</value> </property> <property name="transactionAttributes"> <props> <prop key="update*"> PROPAGATION_REQUIRED,ISOLATION_READ_COMMITTED,-DataBaseException,-BaseException(注:this is a transaction attribute descriptors that parsed via TransactionAttributeEditor) </prop> </props> </property> </bean>
关于transaction attribute descriptors that parsed via TransactionAttributeEditor:
http://static.springsource.org/spring/docs/3.0.0.M1/javadoc-api/org/springframework/transaction/interceptor/TransactionAttributeEditor.html
http://forum.springsource.org/showthread.php?t=38515
引用
public class TransactionAttributeEditor
extends java.beans.PropertyEditorSupport
PropertyEditor for TransactionAttribute objects. Accepts a String of form
PROPAGATION_NAME,ISOLATION_NAME,readOnly,timeout_NNNN,+Exception1,-Exception2
where only propagation code is required. For example:
PROPAGATION_MANDATORY,ISOLATION_DEFAULT
The tokens can be in any order. Propagation and isolation codes must use the names of the constants in the TransactionDefinition class. Timeout values are in seconds. If no timeout is specified, the transaction manager will apply a default timeout specific to the particular transaction manager.
A "+" before an exception name substring indicates that transactions should commit even if this exception is thrown; a "-" that they should roll back.
Null or the empty string means that the method is non transactional.
q:hibernate用户信息实体类Userinfo的主键生成策略为uuid;但在保存用户信息时为其指定了Id的值,问这段代码能顺利执行吗?
private static ApplicationContext context = new ClassPathXmlApplicationContext("resource/xxx/applicationContext.xml"); /** * 能成功插入该条用户数据,但因为userinfo的主键生成策略为uuid,故为其设置的id值无效; * 实际插入数据库的userinfo记录的id值还是由hibernate按照uuid生成策略自动生成的,通过调用setId设置的id值被hibernate忽略 */ public void testHibernateUuid() { UserManagerServiceImpl umsi = (UserManagerServiceImpl)context.getBean("userManagerServiceTarget"); UserInfo ui = new UserInfo(); ui.setId("00000000000000000000000000000000"); ui.setAccountName("acountName000"); ui.setName("name000"); ui.setEmail("000@000.coom"); umsi.userSave(ui); }
a:数据被成功插入,并且通过调用setId设置的id值无效,如图就是刚插入的数据:
q;下面语句的输出是什么:
public static void main(String[] args) { boolean b; int i = 1; float f; System.out.println(b=false); System.out.println(b); System.out.println(i=2); System.out.println(f=3.1f); if(b=true) { System.out.println("test"); } }
a:输出:
false
false
2
3.1
test
Q:下列代码执行的结果是什么?
public class FakeSingleton { private int i = 1; private FakeSingleton instance = new FakeSingleton(); private FakeSingleton() {} public FakeSingleton getInstance() { return instance; } public static void main(String[] args) { FakeSingleton fake = new FakeSingleton(); } }A:会报java.lang.StackOverflowError
析:反编译class文件看到的内容:
public class FakeSingleton { private FakeSingleton() { i = 1; instance = new FakeSingleton(); } public FakeSingleton getInstance() { return instance; } public static void main(String args[]) { FakeSingleton fake = new FakeSingleton(); } private int i; private FakeSingleton instance; }可知:对做了初始化的非静态成员变量(即实例变量 instance variables),这些实例变量的初始化工作是在构造方法中进行的;而该例中,main方法在new FakeSingleton的实例 fake时,其所调用的构造方法又对FakeSingleton的实例变量instance做了new的工作,从而产生递归调用,导致了StackOverflowError。
jdbc、hibernate、ibatis的区别?
引用
jdbc:手动
手动写sql
delete、insert、update要将对象的值一个一个取出传到sql中,不能直接传入一个对象。
select:返回的是一个resultset,要从ResultSet中一行一行、一个字段一个字段的取出,然后封装到一个对象中,不直接返回一个对象。
ibatis的特点:半自动化
sql要手动写
delete、insert、update:直接传入一个对象
select:直接返回一个对象
hibernate:全自动
不写sql,自动封装
delete、insert、update:直接传入一个对象
select:直接返回一个对象
从性能等角度考虑:
jdbc更为灵活,更加有效率,系统运行速度快。但是用起来麻烦,有的时候用了存储过程就不方便数据库移植了。
2 Hibernate,IbatIS 关系数据库框架,开发速度快,更加面向对象,可以移植更换数据库,但影响系统性能。
手动写sql
delete、insert、update要将对象的值一个一个取出传到sql中,不能直接传入一个对象。
select:返回的是一个resultset,要从ResultSet中一行一行、一个字段一个字段的取出,然后封装到一个对象中,不直接返回一个对象。
ibatis的特点:半自动化
sql要手动写
delete、insert、update:直接传入一个对象
select:直接返回一个对象
hibernate:全自动
不写sql,自动封装
delete、insert、update:直接传入一个对象
select:直接返回一个对象
从性能等角度考虑:
jdbc更为灵活,更加有效率,系统运行速度快。但是用起来麻烦,有的时候用了存储过程就不方便数据库移植了。
2 Hibernate,IbatIS 关系数据库框架,开发速度快,更加面向对象,可以移植更换数据库,但影响系统性能。
ext缺点?
引用
加载页面慢
时间一长,浏览器占内存就会疯长
服务器端功能极度削弱,除了数据库操作外,几乎所有功能都到了客户端,还得用javascript来写。
功能全到了客户端,而客户端语言javascript的编写还是有许多的麻烦,真正精通它的人极少。
javascript对于大部分人来说,不易调试
大量存在的javascript代码难以维护
开发速度极慢。
时间一长,浏览器占内存就会疯长
服务器端功能极度削弱,除了数据库操作外,几乎所有功能都到了客户端,还得用javascript来写。
功能全到了客户端,而客户端语言javascript的编写还是有许多的麻烦,真正精通它的人极少。
javascript对于大部分人来说,不易调试
大量存在的javascript代码难以维护
开发速度极慢。
Q:区别:
StringBuffer StringBuilder
Vector ArrayList
HashTable HashMap
A:
引用
StringBuffer(since JDK1.0) StringBuilder(since JDK1.5):
StringBuffer是线程安全的;StringBuilder是非线程安全的;
Vector(since jdk1.0) ArrayList(since jdk1.2):
Vector是线程安全的;ArrayList是非线程安全的;
当需要增长时,Vector默认增长为原来一培,而ArrayList却是原来的一半
HashTable(since JDK1.0) HashMap(since JDK1.2):
HashTable是线程安全的;HashMap是非线程安全的;
HashMap可以将null作为一个条目的key或value(最多只允许一条记录的键为NULL,允许多条记录的值为NULL);HashTable不可以。
析:StringBuffer、Vector和HashTable三个较早的JDK类因为加了synchronized关键字使它们是线程安全的,不可避免的就会存在并发时的性能问题。
StringBuffer是线程安全的;StringBuilder是非线程安全的;
Vector(since jdk1.0) ArrayList(since jdk1.2):
Vector是线程安全的;ArrayList是非线程安全的;
当需要增长时,Vector默认增长为原来一培,而ArrayList却是原来的一半
HashTable(since JDK1.0) HashMap(since JDK1.2):
HashTable是线程安全的;HashMap是非线程安全的;
HashMap可以将null作为一个条目的key或value(最多只允许一条记录的键为NULL,允许多条记录的值为NULL);HashTable不可以。
Q:oracle数据库,emp表中总共有14条记录,执行以下sql,结果是什么?why?
select * from emp where rownum >=0 /** 14 rows selected **/ select * from emp where rownum >0 /** 14 rows selected **/ select * from emp where rownum >=1 /** 14 rows selected **/ select * from emp where rownum >1 /** 0 rows selected **/ select * from emp where rownum >=2 /** 0 rows selected **/ select * from emp where rownum >2 /** 0 rows selected **/ select * from emp where rownum <=10 /** 10 rows selected **/
A:执行结果见上SQL代码区域中的注释。原因分析见:
http://www.iteye.com/topic/197531
http://wuaner.iteye.com/blog/433836
Q:java中char类型是否可以表示汉字?
A:可以,因为java中char占两个字节。
Q:Math.round(11.5) = ? ; Math.round(-11.5) = ?
A:Math.round(11.5) = 12 ; Math.round(-11.5) = -11 . 详见:
http://wuaner.iteye.com/admin/blogs/1008648
Q:switch能否作用在btye上、long上、String上?
A:在switch(expr1)中,expr1只能是一个整数表达式或者枚举常量(更大字体),整数表达式可以是int基本类型或Integer包装类型,由于,byte,short,char都可以隐含转换为int,所以,这些类型以及这些类型的包装类型也是可以的。显然,long 和 String 类型都不符合 switch 的语法规定,并且不能被隐式转换成int类型,所以,它们不能作用于 swtich 语句中。
Q:是否可以:接口继承接口? 抽象类实现接口? 抽象类继承实体类?
A:都可以。
Q:Class.forName的作用?为什么用?
A:用来加载类。之所以要用它,是因为它可以实现动态加载,为系统提供更大的灵活性,让系统维持轻量级。具体请参阅该PDF文档:
http://www.theserverside.com/news/1365412/Understanding-ClassforName-Java
Q:jsp中动态include和静态include的区别?
A:
Q:servlet的生命周期?
A:
Q:如果系统要使用超大整数(超过long表示范围),请设计一个数据结构来存储这种超大整数,并设计一种算法来实现超大整数加法运算。
A:
Q:
引用
What all gets printed when the following gets compiled and run. Select the three correct answers.
B 1
C 2
D 3
E 4
public class test { public static void main(String args[]) { int i=1, j=1; try { i++; j--; if(i/j > 1) i++; } catch(ArithmeticException e) { System.out.println(0); } catch(ArrayIndexOutOfBoundsException e) { System.out.println(1); } catch(Exception e) { System.out.println(2); } finally { System.out.println(3); } System.out.println(4); } }A 0
B 1
C 2
D 3
E 4
A:A、D、E 。 当初答的时候没tm看清题目!草的,引以为戒!
Q:
引用
which are true?
A. static inner class requires a static initializer
B. A static inner class requires an instance of the enclosing class
C. A static inner class has no reference to an instance of the enclosing class
D. A static inner class has accesss to the non-static member of the other class
E. static members of a static inner class can be referenced using the class name of the static inner class
A. static inner class requires a static initializer
B. A static inner class requires an instance of the enclosing class
C. A static inner class has no reference to an instance of the enclosing class
D. A static inner class has accesss to the non-static member of the other class
E. static members of a static inner class can be referenced using the class name of the static inner class
A :答案肯定是C、E了。当初答题压根就没注意还有个E选项!以后读英文卷子可得tm细心点!
Q:
引用
Given:
A.Compilation fails.
B.one two three four
C.four one three two
D.An exception is thrown at runtime.
E.The print order is not guaranteed.
TreeSet map = new TreeSet(); //1 map.add("one"); //2 map.add("two"); //3 map.add("three");//4 map.add("four);//5 map.add("one");//6 Iterator it = map.iterator();//7 while (it.hasNext() ) {//8 System.out.print( it.next() + " " );//9 }What is the result?
A.Compilation fails.
B.one two three four
C.four one three two
D.An exception is thrown at runtime.
E.The print order is not guaranteed.
A:答案是C。
析:first,set里元素没有顺序,不可以重复,所以第六行往TreeSet里再次加字符串"one"是加不进去的;
second,因为该set里放的是String,所以用的是String的natural ordering(所谓natural ordering,就是那些已经实现了Comparable接口的类,重写了该接口的compareTo()方法,等于是这些类在同类的对象间比较时有了个JDK就定义了的比较方式,这种JDK内定义的比较方方式就称为natural ordering)。附上JDK中String类中compareTo方法解释:
引用
public int compareTo(String anotherString)
Compares two strings lexicographically. The comparison is based on the Unicode value of each character in the strings. The character sequence represented by this String object is compared lexicographically to the character sequence represented by the argument string. The result is a negative integer if this String object lexicographically precedes the argument string. The result is a positive integer if this String object lexicographically follows the argument string. The result is zero if the strings are equal; compareTo returns 0 exactly when the equals(Object) method would return true.
This is the definition of lexicographic ordering. If two strings are different, then either they have different characters at some index that is a valid index for both strings, or their lengths are different, or both. If they have different characters at one or more index positions, let k be the smallest such index; then the string whose character at position k has the smaller value, as determined by using the < operator, lexicographically precedes the other string. In this case, compareTo returns the difference of the two character values at position k in the two string -- that is, the value:
this.charAt(k)-anotherString.charAt(k)
If there is no index position at which they differ, then the shorter string lexicographically precedes the longer string. In this case, compareTo returns the difference of the lengths of the strings -- that is, the value:
this.length()-anotherString.length()
Compares two strings lexicographically. The comparison is based on the Unicode value of each character in the strings. The character sequence represented by this String object is compared lexicographically to the character sequence represented by the argument string. The result is a negative integer if this String object lexicographically precedes the argument string. The result is a positive integer if this String object lexicographically follows the argument string. The result is zero if the strings are equal; compareTo returns 0 exactly when the equals(Object) method would return true.
This is the definition of lexicographic ordering. If two strings are different, then either they have different characters at some index that is a valid index for both strings, or their lengths are different, or both. If they have different characters at one or more index positions, let k be the smallest such index; then the string whose character at position k has the smaller value, as determined by using the < operator, lexicographically precedes the other string. In this case, compareTo returns the difference of the two character values at position k in the two string -- that is, the value:
this.charAt(k)-anotherString.charAt(k)
If there is no index position at which they differ, then the shorter string lexicographically precedes the longer string. In this case, compareTo returns the difference of the lengths of the strings -- that is, the value:
this.length()-anotherString.length()
Q:
引用
public class Letters extends Thread { private String name; public Letters(String name) { this.name = name; } public void write() { System.out.print(name); System.out.print(name); } public static void main(String[] args) { new Letters("X").start(); new Letters("Y").start(); } }Question: We want to guarantee that the output can be either XXYY or YYXX, but never XYXY or any other combination. Which of the following method definitions could be added to the Letters class to make this guarantee? (Choose all that apply.)
A. public void run() { write(); }
B. public synchronized void run() { write(); }
C. public static synchronized void run() { write(); }
D. public void run() { synchronized(this) { write(); } }
E. public void run() { synchronized(Letters.class) { write(); } }
F. public void run() { synchronized(System.out) { write(); } }
G. public void run() { synchronized(System.out.class) { write(); } }
A:
引用
答案是E、F。
public void run() { write(); } //不能保证结果如题目要求般输出 public synchronized void run() { write(); } //不能保证结果如题目要求般输出 public static synchronized void run() { write(); } //编译错误:the static method cannot hide instance method from Thread public void run() { synchronized(this) { write(); } } //不能保证结果如题目要求般输出 public void run() { synchronized(Letters.class) { write(); } } //OK public void run() { synchronized(System.out) { write(); } } //OK public void run() { synchronized(System.out.class) { write(); } } //编译错误:System.out cannot be resolved to a type
析:http://www.coderanch.com/t/417999/java-programmer-SCJP/certification/Synchronizing-thread
引用
E and F are correct. E and F both cause both threads to lock on the same object, which will prevent the threads from running simultaneously, and guarantee XXYY or YYXX. It's a bit unusual to lock on an object like System.out, but it's perfectly legal, and both threads are locking on the same object.
A class literal must start with a class name. System.out is a field not a class, so System.out.class is not a valid class literal.
A class literal must start with a class name. System.out is a field not a class, so System.out.class is not a valid class literal.
http://www.coderanch.com/t/262030/java-programmer-SCJP/certification/book-Threads-Exercise
关于两个正确选项的更详细解释,请参加本博客:
http://wuaner.iteye.com/admin/blogs/998696
Q:下列代码:
public class Test { public static int a = 5; public static void main(String[] args) { Test test = new Test(); test = null; System.out.println(test.a); } }给出程序的执行结果,如果程序有错,请说明错误原因。
A:不会报错,会输入5.
析:java static field from null:
http://stackoverflow.com/questions/6782276/java-static-field-from-null
Q:为什么非主键索引会降低更新速度,提高查询速度?
A:非主键索引需要在数据表本身的存储空间外额外开销存储空间,所以在更新的时候可能不仅要更新数据表本身,还要更新非主键索引,更新内容更多了,所以导致速度降低。反过来,如果数据表中的数据按照主键索引的顺序存储,更新的时候就没有额外的开销。
非主键索引对提高查询速度来讲,主要的方面是:检索的条件(where...)如果命中对应的非主键索引的话,就不需要对数据表做全表扫描,效率肯定是大大提高。
Q:设一个散列表包含hashSize=13个表项,其下标从0到12。采用除留余数法作为散列函数,线性探查法解决冲突.,将下列关键码散列到表中:
10 100 32 45 58 126 3 29 200 400 0
A:
下标 H(key) | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
关键码 key | 0 | 3 | 29 | 200 | 32 | 45 | 58 | 100 | 10 | 126 | 400 |
Q:简述TCP/IP三次握手
A:A与B建立TCP连接时:首先A向B发SYN(同步请求),然后B回复SYN+ACK(同步请求应答),最后A回复ACK确认,这样TCP的一次连接就通过这三次握手建立起来了!
http://www.inetdaemon.com/tutorials/internet/tcp/3-way_handshake.shtml
发表评论
-
Top 20 Core Java Interview questions answers asked in Investment Bank
2012-09-16 22:26 1046Very useful http://javarevisit ... -
SCJP
2011-04-20 03:58 1244http://www.javaprepare.com/ques ... -
SCJP 2008 真题解析(面试前时常温一遍)
2010-10-27 14:29 1218感谢作者对08 SCJP试题的解析! http://mgc. ... -
你能通过下面的3道java面试题吗?
2010-04-15 17:21 1274http://adapterofcoms.iteye.com/ ... -
变态java面试题一览
2009-11-23 10:46 1900http://blogger.org.cn/blog/more ... -
一个java程序员的面试
2009-08-26 01:07 1273面试官:熟悉哪种语言? 应聘者:java。 面试官:知道什 ... -
程序员Java面试中的陷阱
2009-08-26 00:41 1270程序员Java面试中的陷阱 ...
相关推荐
【描述】"All lists of files I prepare for my interview of java programmer."表明这组资料是为Java程序员面试而精心整理的,旨在帮助求职者全面了解并掌握Java编程的核心概念和技术,以应对面试中的各种挑战。...
在Android开发领域,虚拟APK(Virtual APK)技术是一种实现应用插件化的方案,它能够帮助开发者将一个大型的应用拆分成多个小型插件,从而实现动态加载和更新。本资源"didid virtualApk框架使用以及遇到的一些问题...
myinterview 记录我的面试过程,技术栈:python、golang、MySQL、redis、大数据、数据仓库、Linux、计算机网络、数据中台。 目录 python面试题; golang面试题; 数据库MySQL和redis; 计算机系统linux; 计算机网络...
https://github.com/mission-peace/interview/wiki Like my facebook page for latest updates on my youtube channel https://www.facebook.com/tusharroy25 Contribution Please contribute to this repository...
9. 题目:Your words have made me more ________ of my interview. 解析:这道题考察形容词在表达心理状态变化时的用法。别人的鼓励让说话者对自己的面试更有信心,因此正确答案是D. confident(自信的)。 10. ...
My solutions to coding interview problems on Leetcode, Alg
标题 "my live work / interview / renshebu / gongxinbu" 提示我们这是一个与个人工作、面试、人事部和公信部相关的文件集合。虽然描述是空的,但我们可以根据标签 "源码" 和 "工具" 来推测这个压缩包可能包含了...
【标题】"myandroid interview" 涉及的IT知识点主要涵盖以下几个方面: 1. **Android应用与框架开发**: 王志斌在诚迈科技(南京)有限公司的工作经验中提到了Android平台的应用与框架开发。这涉及到对Android SDK的...
系统设计面试题集是一本专注于计算机科学与工程领域中系统设计相关问题的参考书,它是由Antonio Gulli所著,并于2016年出版。这本书是作者关于算法、问题解决以及C++编程25章系列著作中的第九章,致力于介绍系统设计...
print(getattr(my_function, '__name__')) # 输出:my_function ``` #### 6. 字典推导式 字典推导式是一种简洁的方式,用于根据现有的序列或其他可迭代对象构建新的字典。其语法形式为 `{key_expression: value_...
I am honored to have this opportunity for an interview, and I hope to present myself well today, with confidence that I can excel in this position. Let me briefly introduce myself. At the age of 26, ...
【标题】"my-interview:前端面试知识"涵盖了前端开发者在面试过程中可能遇到的各种关键知识点。这个压缩包可能包含了一份全面的前端面试准备指南,旨在帮助求职者掌握JavaScript这一核心前端技术,以及其他相关的...
my interview. 剑指offer顺序按照的顺序!!! 会不定期的刷!!! 增加新的模块(面试/笔试) 每天1~2道题,看看我能坚持多久!!! 2019.3.26 打卡 2019.3.27 打卡 2019.3.28 打卡 (小公司笔试6道算法题) 2019.3.29 ...
my interview, come on!! ##深度优先搜索 ####dfs_codeforce_659E_New_Reform 题意:有n座城市,城市之间有无向边,现在要把所有的边变成有向的边,使得入度为0的城市尽可能的少。 解答:如果是无向边构成的图,可以...