??xml version="1.0" encoding="utf-8" standalone="yes"?>
http://www.oracle.com/technology/tech/java/spring/how-to-jta-spring.html
]]>
8.3.1.3 transient Fields
Variables may be marked transient to indicate that they are not part of
the persistent state of an object.
If an instance of the class Point:
class Point {
int x, y;
transient float rho, theta;
}
were saved to persistent storage by a system service, then only the
fields x and y would be saved. This specification does not specify
details of such services; see the specification of java.io.Serializable
for an example of such a service.
8.3.1.4 volatile Fields
As described in §17, the Java programming language allows threads to
access shared variables. As a rule, to ensure that shared variables are
consistently and reliably updated, a thread should ensure that it has
exclusive use of such variables by obtaining a lock that,
conventionally, enforces mutual exclusion for those shared variables.
The Java programming language provides a second mechanism, volatile
fields, that is more convenient than locking for some purposes.
A field may be declared volatile, in which case the Java memory model
(§17) ensures that all threads see a consistent value for the variable.
If, in the following example, one thread repeatedly calls the method one
(but no more than Integer.MAX_VALUE times in all), and another thread
repeatedly calls the method two:
class Test {
static int i = 0, j = 0;
static void one() { i++; j++; }
static void two() {
System.out.println("i=" + i + " j=" + j);
}
}
then method two could occasionally print a value for j that is greater
than the value of i, because the example includes no synchronization
and, under the rules explained in §17, the shared values of i and j
might be updated out of order.
One way to prevent this out-or-order behavior would be to declare
methods one and two to be synchronized (§8.4.3.6):
class Test {
static int i = 0, j = 0;
static synchronized void one() { i++; j++; }
static synchronized void two() {
System.out.println("i=" + i + " j=" + j);
}
}
This prevents method one and method two from being executed
concurrently, and furthermore guarantees that the shared values of i and
j are both updated before method one returns. Therefore method two never
observes a value for j greater than that for i; indeed, it always
observes the same value for i and j.
Another approach would be to declare i and j to be volatile:
class Test {
static volatile int i = 0, j = 0;
static void one() { i++; j++; }
static void two() {
System.out.println("i=" + i + " j=" + j);
}
}
This allows method one and method two to be executed concurrently, but
guarantees that accesses to the shared values for i and j occur exactly
as many times, and in exactly the same order, as they appear to occur
during execution of the program text by each thread. Therefore, the
shared value for j is never greater than that for i, because each update
to i must be reflected in the shared value for i before the update to j
occurs. It is possible, however, that any given invocation of method two
might observe a value for j that is much greater than the value observed
for i, because method one might be executed many times between the
moment when method two fetches the value of i and the moment when method
two fetches the value of j.
See §17 for more discussion and examples.
A compile-time error occurs if a final variable is also declared volatile.
--
]]>
]]>
a.条g操作只能操作布尔型的,而逻辑操作不仅可以操作布尔?而且可以操作数值型
b.逻辑操作不会(x)产生短\.?
int a = 0;
int b = 0;
if( (a = 3) > 0 || (b = 3) > 0 ) //操后a =3,b=0.
if( (a = 3) > 0 | (b = 3) > 0 ) //操后a =3,b=3.
{对W一点得5?{对W二点得10?
本题考察最最基本的知?但仍然有很多大牛U开发h员(sh)?M语言在开始的部分
都会(x)详细介绍q些基本知识,但除?jin)学习(fn)第一U语a?没有人在学习(fn)新的语言时愿?br />
׃分钟来复?fn)一?
2.下面E序q行?x)发生什么结?如果有错?如何Ҏ(gu)? (15?
interface A{
int x = 0;
}
class B{
int x =1;
}
class C
extends B implements A {
public void pX(){
System.out.println(x);
}
public static void main(String[] args) {
new C().pX();
}
}
}
本题在编译时?x)发生错?错误描述不同的JVM有不同的信息,意思就是未明确的x调用,
两个x都匹?p在同时import java.util和java.sql两个包时直接声明Date一?
本题?sh)要考察Ҏ(gu)口和cȝ最最基本的结构的?jin)?对于父类的变?可以用super.x?br />
明确,而接口的属性默认隐含ؓ(f) public static final.所以可以通过A.x来明?
3.q?Java Server Page ?Servlet 的联pd区别?20?
本题?sh)用多?在答相同Ҏ(gu)应该明确知道jsp~译后是"cservlet"?不是Servlet",
{区别时应该回答?侧重?视图/控制逻辑)".其它可根据情况加减分?知识很简?
但从面试的角度看,被试者不仅要能知道它们的区别,而且要能比较准确地表辑և??br />
后写文档要能让别人看得懂,不生歧?,回答"jsp~译后就是servlet"视ؓ(f)错误,回答
"jsp用于视图,servlet用于控制逻辑"视ؓ(f)错误,应该用侧重于,主要(多数)用于{词?br />
表达.
4.XML文档定义有几UŞ式?它们之间有何本质区别Q?br />
解析XML文档有哪几种方式Q?20?
本题?sh)个{题?
a: 两种形式 dtd,schema
b: 本质区别:schema本n是xml?可以被XML解析器解?q也是从DTD上发展schema?br />
Ҏ(gu)目的)
c: 两种主要方式:dom,sax.{出两种得全?如能{出saxt,或其?在答出dom,sax的基
?如果应试者认为其它方式也可以视ؓ(f)对xml的解析应该允?但没有答出dom,sax?br />
其它方式说成是对XML的解析不得分)应该加分.
5.qsynchronized和java.util.concurrent.locks.Lock的异?Q?15?
主要相同?
Lock能完成synchronized所实现的所有功?(其它不重?
主要不同?
Lock有比synchronized更精的U程语义和更好的性能(在相同点中回{此点也?
synchronized?x)自动释N.而Lock一定要求程序员手工释放.q且必须在finally从句
中释?如果没有{出在finally中释放不得分.如Connection没有在finally中关闭一
?q最基本的资源释N做不?q谈什么多U程~程.
6.EJB规范规定EJB中禁止的操作有哪些?(15?
共有8?{出下列3-4点得满分.
1.不能操作U程和线EAPI(U程API指非U程对象的方法如notify,wait{?
2.不能操作awt
3.不能实现服务器功?br />
4.不能寚w(rn)态属生存?
5.不能使用IO操作直接存取文gpȝ
6.不能加蝲本地?
7.不能this作ؓ(f)变量和返?
8.不能循环调用.
7.请问在Java的线E里有个join()函数Q这个函数有什么用呀Q?br />
是把调用join()的线E连l?join)到当前线E?什么意思呢?是当前U程{待调用join()U程的结?比如:当前U程是主U程,它结的时候要求一个被调用的线Eal束,如果我们不调用a.join();那只能轮询a的状?
while(true){
if(!a.isAlive()) break;
sleep(500);
}
System.exet(1);
如果aU程isAlive,则等500msl箋(hu)下一ơ轮?如果已经不可用则l束,q种while(true)的轮询一是占用大量的CPU旉.另一是有可能在sleep(500);?刚睡1ms?a已l?isAlive()?那就多睡?99ms,费?jin)时?而如?br />
a.join();
System.exit(1);
则一{aU程l束׃(x)退?如果没有其它操作,ȝE就不会(x)占用CPU旉.
8当一个对象被当作参数传递到一个方法后Q此Ҏ(gu)可改变这个对象的属性,q可q回变化后的l果Q那么这里到底是g递还是引用传?
是g递。Java ~程语言只由g递参数。当一个对象实例作Z个参数被传递到Ҏ(gu)中时Q参数的值就是对该对象的引用。对象的内容可以在被调用的方法中改变Q但对象的引用是永远不会(x)改变的?
9作用域public,private,protected,以及(qing)不写时的区别
{:(x)区别如下Q?
作用?当前c?同一package 子孙c?其他package
public √ √ √ √
protected √ √ √ ×
friendly √ √ × ×
private √ × × ×
不写旉认ؓ(f)friendly
10ArrayList和Vector的区?HashMap和Hashtable的区?
{:(x)ArrayList与Vector主要从二斚w来说.
一.同步?Vector是线E安全的Q也是说是同步的,而ArrayList是线E序不安全的Q不是同步的
?数据增长:当需要增长时,Vector默认增长为原来一培,而ArrayList却是原来的一?br />
11一.?rn)态内部类可以有静(rn)态成员,而非?rn)态内部类则不能有?rn)态成员?br />
12?rn)态内部类的非?rn)态成员可以访问外部类的静(rn)态变量,而不可访问外部类的非?rn)态变?br />
13jsp有哪些动?作用分别是什?
{?JSP共有以下6U基本动?
jsp:includeQ在面被请求的时候引入一个文件?
jsp:useBeanQ寻找或者实例化一个JavaBean?
jsp:setPropertyQ设|JavaBean的属性?
jsp:getPropertyQ输出某个JavaBean的属性?
jsp:forwardQ把h转到一个新的页面?
jsp:pluginQ根据浏览器cd为Java插g生成OBJECT或EMBED标记
14remote接口和home接口主要作用
remote接口定义?jin)业务方法,用于EJB客户端调用业务方?
home接口是EJB工厂用于创徏和移除查找EJB实例
15客服端调用EJB对象的几个基本步?
一?讄JNDI服务工厂以及(qing)JNDI服务地址pȝ属?
二?查找Home接口
三?从Home接口调用CreateҎ(gu)创徏Remote接口
四?通过Remote接口调用其业务方?
]]>
Q通常情况下,C++QC语言E序~译之后Q也h同样的特性。)(j)
比如Q我们有如下代码?br />
String A = “atom”;
String B = “atom”;
我们有理p为,A和B指向同一个字W串帔R。即QA==B?br />
注意Q声明字W串变量的代码,不符合上面的规则?br />
String C= new String(“atom”);
String D = new String(“atom”);
q里的C和D的声明是字符串变量的声明Q所以,C != D?br />
]]>
当实现java.io.Serializable接口的实体(c)(j)没有昑ּ地定义一个名?font color="#ff0000">serialVersionUIDQ类型ؓ(f)long的变量时QJava序列化机制会(x)Ҏ(gu)~译的class自动生成一?font color="#ff0000">serialVersionUID作序列化版本比较用,q种情况下,只有同一ơ编译生成的class才会(x)生成相同?font color="#ff0000">serialVersionUID ?/font>
如果我们不希望通过~译来强制划分Y件版本,卛_现序列化接口的实体能够兼容先前版本,未作更改的类Q就需要显式地定义一个名?font color="#ff0000">serialVersionUIDQ类型ؓ(f)long的变量,不修改这个变量值的序列化实体都可以怺q行串行化和反串行化?
源自Qhttp://sharajava.javaeye.com/blog/102886
参数 |
语义 |
deprecation |
使用?jin)过时的cLҎ(gu)时的警告 |
unchecked |
执行?jin)未(g)查的转换时的警告Q例如当使用集合时没有用泛型 (Generics) 来指定集合保存的cd |
fallthrough |
?span lang="EN-US"> Switch E序块直接通往(xin)下一U情况而没?span lang="EN-US"> Break 时的警告 |
path |
在类路径、源文g路径{中有不存在的\径时的警?span lang="EN-US" style="color: black"> |
serial |
当在可序列化的类上缺?span lang="EN-US"> serialVersionUID 定义时的警告 |
finally |
M finally 子句不能正常完成时的警告 |
all |
关于以上所有情늚警告 |
@Override ZooImpl._animal ((AnimalImpl)ZooImpl.getAnimal()).implMethod(); ZooImpl._getAnimal();
public int hashCode() {
...
}
看上面的例子Q如果没有在hashCode中将“C”大写Q在~译时不?x)出现错误,但是在运行时无法像期望的那栯用该?gu)。通过dOverride标签Q编译器?x)提C它是否真正地执行了(jin)重写?br />
在超cd生改变的情况中,q也很有帮助。如果向该方法中d一个新参数Q而且Ҏ(gu)本n也被重命名了(jin)Q那么子cdH然不能~译Q因为它不再重写类的Q何东ѝ?br />
枚D
enum非常像public static final int声明Q后者作为枚丑ր已l用了(jin)很多q。对int所做的最大也是最明显的改q是cd安全――?zhn)不能错误地用枚D的一U类型代替另一U类型,q一点和int不同Q所有的int对编译器来说都是一L(fng)。除L数例外的情况,通常都应该用enum实例替换全部的枚N格的intl构?br />
枚D提供?jin)一些附加的Ҏ(gu)。EnumMap和EnumSetq两个实用类是专门ؓ(f)枚D优化的标准集合实现。如果知道集合只包含枚DcdQ那么应该用这些专门的集合来代替HashMap或HashSet?br />
大部分情况下Q可以用enum对代码中的所有public static final int做插入替换。它们是可比的,q且可以?rn)态导入,所以对它们的引用看h是等同的Q即使是对于内部c(或内部枚丄型)(j)。注意,比较枚Dcd的时候,声明它们的指令表明了(jin)它们的顺序倹{?br />
“隐藏?#8221;?rn)态方?/strong>
两个?rn)态方法出现在所有枚丄型声明中。因为它们是枚D子类上的?rn)态方法,而不是Enum本n的方法,所以它们在java.lang.Enum的javadoc中没有出现?br />
W一个是values()Q返回一个枚丄型所有可能值的数组?br />
W二个是valueOf()Qؓ(f)提供的字W串q回一个枚丄型,该枚丄型必ȝ地匚w源代码声明?br />
Ҏ(gu)
关于枚DcdQ我们最喜欢的一个方面是它可以有Ҏ(gu)。过L可能需要编写一些代码,对public static final intq行转换Q把它从数据库类型{换ؓ(f)JDBC URL。而现在则可以让枚丄型本w带一个整理代码的Ҏ(gu)。下面就是一个例子,包括DatabaseType枚Dcd的抽象方法以?qing)每个枚丑֮例中提供的实玎ͼ?x)
public enum DatabaseType {
ORACLE {
public String getJdbcUrl() {...}
},
MYSQL {
public String getJdbcUrl() {...}
};
public abstract String getJdbcUrl();
}
现在枚Dcd可以直接提供它的实用Ҏ(gu)。例如:(x)
DatabaseType dbType = ...;
String jdbcURL = dbType.getJdbcUrl();
要获取URLQ必预先知道该实用Ҏ(gu)在哪里?br />
可变参数(Vararg)
Log.log(String code, String... args)
协变q回
协变q回的基本用法是用于在已知一个实现的q回cd比API更具体的时候避免进行类型强制{换。在下面q个例子中,有一个返回Animal对象的Zoo接口。我们的实现q回一个AnimalImpl对象Q但是在JDK 1.5之前Q要q回一个Animal对象必d明?
public interface Zoo {
public Animal getAnimal();
}
public class ZooImpl implements Zoo {
public Animal getAnimal(){
return new AnimalImpl();
}
}
协变q回的用替换了(jin)三个反模式:(x)
另一UŞ式是Q在知道实现的实际上是特定的子类的情况下Q在调用E序中执行向下{换:(x)
q三U模式都有它们的问题和局限性。要么是不够整洁Q要么就是暴露了(jin)不必要的实现l节?br />
协变
协变q回模式比较整z、安全ƈ且易于维护,它也不需要类型强制{换或特定的方法或字段Q?br />
public AnimalImpl getAnimal(){
return new AnimalImpl();
}
使用l果Q?br />
ZooImpl.getAnimal().implMethod();
参考:(x)http://www.linuxpk.com/43834.html
]]>
十六q制转成十进?br>Integer.valueOf("FFFF",16).toString()
八进制{成十q制
Integer.valueOf("876",8).toString()
二进制{十进?br>Integer.valueOf("0101",2).toString()