锘??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.鏉′歡鎿嶄綔鍙兘鎿嶄綔甯冨皵鍨嬬殑,鑰岄昏緫鎿嶄綔涓嶄粎鍙互鎿嶄綔甯冨皵鍨?鑰屼笖鍙互鎿嶄綔鏁板煎瀷
b.閫昏緫鎿嶄綔涓嶄細浜х敓鐭礬.濡?
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.
絳斿絎竴鐐瑰緱5鍒?絳斿絎簩鐐瑰緱10鍒?
鏈鑰冨療鏈鏈鍩烘湰鐨勭煡璇?浣嗕粛鐒舵湁寰堝澶х墰綰у紑鍙戜漢鍛樹笅椹?浠諱綍璇█鍦ㄥ紑濮嬬殑閮ㄥ垎
閮戒細璇︾粏浠嬬粛榪欎簺鍩烘湰鐭ヨ瘑,浣嗛櫎浜嗗涔犵涓縐嶈璦鏃?娌℃湁浜哄湪瀛︿範鏂扮殑璇█鏃舵効鎰?br />
鑺變簲鍒嗛挓鏉ュ涔犱竴涓?
2.涓嬮潰紼嬪簭榪愯浼氬彂鐢熶粈涔堢粨鏋?濡傛灉鏈夐敊璇?濡備綍鏀規? (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();
}
}
}
鏈鍦ㄧ紪璇戞椂浼氬彂鐢熼敊璇?閿欒鎻忚堪涓嶅悓鐨凧VM鏈変笉鍚岀殑淇℃伅,鎰忔濆氨鏄湭鏄庣‘鐨剎璋冪敤,
涓や釜x閮藉尮閰?灝辮薄鍦ㄥ悓鏃秈mport java.util鍜宩ava.sql涓や釜鍖呮椂鐩存帴澹版槑Date涓鏍?
鏈涓昏鑰冨療瀵規帴鍙e拰綾葷殑鏈鏈鍩烘湰鐨勭粨鏋勭殑浜嗚В.瀵逛簬鐖剁被鐨勫彉閲?鍙互鐢╯uper.x鏉?br />
鏄庣‘,鑰屾帴鍙g殑灞炴ч粯璁ら殣鍚負 public static final.鎵浠ュ彲浠ラ氳繃A.x鏉ユ槑紜?
3.綆榪?Java Server Page 鍜?Servlet 鐨勮仈緋誨拰鍖哄埆銆?20鍒?
鏈涓嶇敤澶氳,鍦ㄧ瓟鐩稿悓鐐規椂搴旇鏄庣‘鐭ラ亾jsp緙栬瘧鍚庢槸"綾籹ervlet"鑰?涓嶆槸Servlet",
絳斿尯鍒椂搴旇鍥炵瓟鍑?渚ч噸浜?瑙嗗浘/鎺у埗閫昏緫)".鍏跺畠鍙牴鎹儏鍐靛姞鍑忓垎鍊?鐭ヨ瘑寰堢畝鍗?
浣嗕粠闈㈣瘯鐨勮搴︾湅,琚瘯鑰呬笉浠呰鑳界煡閬撳畠浠殑鍖哄埆,鑰屼笖瑕佽兘姣旇緝鍑嗙‘鍦拌〃杈懼嚭鏉?浠?br />
鍚庡啓鏂囨。瑕佽兘璁╁埆浜虹湅寰楁噦,涓嶄駭鐢熸涔?,鍥炵瓟"jsp緙栬瘧鍚庡氨鏄痵ervlet"瑙嗕負閿欒,鍥炵瓟
"jsp鐢ㄤ簬瑙嗗浘,servlet鐢ㄤ簬鎺у埗閫昏緫"瑙嗕負閿欒,搴旇鐢ㄤ晶閲嶄簬,涓昏(澶氭暟)鐢ㄤ簬絳夎瘝璇?br />
琛ㄨ揪.
4.XML鏂囨。瀹氫箟鏈夊嚑縐嶅艦寮忥紵瀹冧滑涔嬮棿鏈変綍鏈川鍖哄埆錛?br />
瑙f瀽XML鏂囨。鏈夊摢鍑犵鏂瑰紡錛?20鍒?
鏈涓変釜絳旈鐐?
a: 涓ょ褰㈠紡 dtd,schema
b: 鏈川鍖哄埆:schema鏈韓鏄痻ml鐨?鍙互琚玐ML瑙f瀽鍣ㄨВ鏋?榪欎篃鏄粠DTD涓婂彂灞晄chema鐨?br />
鏍規湰鐩殑)
c: 涓ょ涓昏鏂瑰紡:dom,sax.絳斿嚭涓ょ寰楀叏鍒?濡傝兘絳斿嚭saxt,鎴栧叾瀹?鍦ㄧ瓟鍑篸om,sax鐨勫熀
紜涓?濡傛灉搴旇瘯鑰呰涓哄叾瀹冩柟寮忎篃鍙互瑙嗕負瀵箈ml鐨勮В鏋愬簲璇ュ厑璁?浣嗘病鏈夌瓟鍑篸om,sax鎶?br />
鍏跺畠鏂瑰紡璇存垚鏄XML鐨勮В鏋愪笉寰楀垎)搴旇鍔犲垎.
5.綆榪皊ynchronized鍜宩ava.util.concurrent.locks.Lock鐨勫紓鍚?錛?15鍒?
涓昏鐩稿悓鐐?
Lock鑳藉畬鎴恠ynchronized鎵瀹炵幇鐨勬墍鏈夊姛鑳?(鍏跺畠涓嶉噸瑕?
涓昏涓嶅悓鐐?
Lock鏈夋瘮synchronized鏇寸簿紜殑綰跨▼璇箟鍜屾洿濂界殑鎬ц兘(鍦ㄧ浉鍚岀偣涓洖絳旀鐐逛篃琛?
synchronized浼氳嚜鍔ㄩ噴鏀鵑攣.鑰孡ock涓瀹氳姹傜▼搴忓憳鎵嬪伐閲婃斁.騫朵笖蹇呴』鍦╢inally浠庡彞
涓噴鏀?濡傛灉娌℃湁絳斿嚭鍦╢inally涓噴鏀句笉寰楀垎.灝卞Connection娌℃湁鍦╢inally涓叧闂竴
鏍?榪炴渶鍩烘湰鐨勮祫婧愰噴鏀鵑兘鍋氫笉濂?榪樿皥浠涔堝綰跨▼緙栫▼.
6.EJB瑙勮寖瑙勫畾EJB涓姝㈢殑鎿嶄綔鏈夊摢浜涳紵(15鍒?
鍏辨湁8鐐?絳斿嚭涓嬪垪3-4鐐瑰緱婊″垎.
1.涓嶈兘鎿嶄綔綰跨▼鍜岀嚎紼婣PI(綰跨▼API鎸囬潪綰跨▼瀵硅薄鐨勬柟娉曞notify,wait絳?
2.涓嶈兘鎿嶄綔awt
3.涓嶈兘瀹炵幇鏈嶅姟鍣ㄥ姛鑳?br />
4.涓嶈兘瀵歸潤鎬佸睘鐢熷瓨鍙?
5.涓嶈兘浣跨敤IO鎿嶄綔鐩存帴瀛樺彇鏂囦歡緋葷粺
6.涓嶈兘鍔犺澆鏈湴搴?
7.涓嶈兘灝唗his浣滀負鍙橀噺鍜岃繑鍥?
8.涓嶈兘寰幆璋冪敤.
7.璇烽棶鍦↗ava鐨勭嚎紼嬮噷鏈変釜join()鍑芥暟錛岃繖涓嚱鏁版湁浠涔堢敤鍛錛?br />
鏄妸璋冪敤join()鐨勭嚎紼嬭繛緇?join)鍒板綋鍓嶇嚎紼?浠涔堟剰鎬濆憿?灝辨槸褰撳墠綰跨▼絳夊緟璋冪敤join()綰跨▼鐨勭粨鏉?姣斿:褰撳墠綰跨▼鏄富綰跨▼,瀹冪粨鐨勬椂鍊欒姹備竴涓璋冪敤鐨勭嚎紼媋緇撴潫,濡傛灉鎴戜滑涓嶈皟鐢╝.join();閭e彧鑳借疆璇鐨勭姸鎬?
while(true){
if(!a.isAlive()) break;
sleep(500);
}
System.exet(1);
濡傛灉a綰跨▼isAlive,鍒欑瓑500ms緇х畫涓嬩竴嬈¤疆宸?濡傛灉宸茬粡涓嶅彲鐢ㄥ垯緇撴潫,榪欑while(true)鐨勮疆璇竴鏄崰鐢ㄥぇ閲忕殑CPU鏃墮棿.鍙︿竴鏄湁鍙兘鍦╯leep(500);鏃?鍒氱潯1ms鏃?a灝卞凡緇?isAlive()浜?閭e氨澶氱潯浜?99ms,嫻垂浜嗘椂闂?鑰屽鏋?br />
a.join();
System.exit(1);
鍒欎竴絳塧綰跨▼緇撴潫灝變細閫鍑?濡傛灉娌℃湁鍏跺畠鎿嶄綔,涓葷嚎紼嬪氨涓嶄細鍗犵敤CPU鏃墮棿.
8褰撲竴涓璞¤褰撲綔鍙傛暟浼犻掑埌涓涓柟娉曞悗錛屾鏂規硶鍙敼鍙樿繖涓璞$殑灞炴э紝騫跺彲榪斿洖鍙樺寲鍚庣殑緇撴灉錛岄偅涔堣繖閲屽埌搴曟槸鍊間紶閫掕繕鏄紩鐢ㄤ紶閫?
銆銆鏄間紶閫掋侸ava 緙栫▼璇█鍙敱鍊間紶閫掑弬鏁般傚綋涓涓璞″疄渚嬩綔涓轟竴涓弬鏁拌浼犻掑埌鏂規硶涓椂錛屽弬鏁扮殑鍊煎氨鏄璇ュ璞$殑寮曠敤銆傚璞$殑鍐呭鍙互鍦ㄨ璋冪敤鐨勬柟娉曚腑鏀瑰彉錛屼絾瀵硅薄鐨勫紩鐢ㄦ槸姘歌繙涓嶄細鏀瑰彉鐨勩?
9浣滅敤鍩焢ublic,private,protected,浠ュ強涓嶅啓鏃剁殑鍖哄埆
絳旓細鍖哄埆濡備笅錛?
浣滅敤鍩?褰撳墠綾?鍚屼竴package 瀛愬瓩綾?鍏朵粬package
public √ √ √ √
protected √ √ √ ×
friendly √ √ × ×
private √ × × ×
涓嶅啓鏃墮粯璁や負friendly
10ArrayList鍜孷ector鐨勫尯鍒?HashMap鍜孒ashtable鐨勫尯鍒?
絳旓細灝盇rrayList涓嶸ector涓昏浠庝簩鏂歸潰鏉ヨ.
涓.鍚屾鎬?Vector鏄嚎紼嬪畨鍏ㄧ殑錛屼篃灝辨槸璇存槸鍚屾鐨勶紝鑰孉rrayList鏄嚎紼嬪簭涓嶅畨鍏ㄧ殑錛屼笉鏄悓姝ョ殑
浜?鏁版嵁澧為暱:褰撻渶瑕佸闀挎椂,Vector榛樿澧為暱涓哄師鏉ヤ竴鍩癸紝鑰孉rrayList鍗存槸鍘熸潵鐨勪竴鍗?br />
11涓.闈欐佸唴閮ㄧ被鍙互鏈夐潤鎬佹垚鍛橈紝鑰岄潪闈欐佸唴閮ㄧ被鍒欎笉鑳芥湁闈欐佹垚鍛樸?br />
12闈欐佸唴閮ㄧ被鐨勯潪闈欐佹垚鍛樺彲浠ヨ闂閮ㄧ被鐨勯潤鎬佸彉閲忥紝鑰屼笉鍙闂閮ㄧ被鐨勯潪闈欐佸彉閲?br />
13jsp鏈夊摢浜涘姩浣?浣滅敤鍒嗗埆鏄粈涔?
絳?JSP鍏辨湁浠ヤ笅6縐嶅熀鏈姩浣?
jsp:include錛氬湪欏甸潰琚姹傜殑鏃跺欏紩鍏ヤ竴涓枃浠躲?
jsp:useBean錛氬鎵炬垨鑰呭疄渚嬪寲涓涓狫avaBean銆?
jsp:setProperty錛氳緗甁avaBean鐨勫睘鎬с?
jsp:getProperty錛氳緭鍑烘煇涓狫avaBean鐨勫睘鎬с?
jsp:forward錛氭妸璇鋒眰杞埌涓涓柊鐨勯〉闈€?
jsp:plugin錛氭牴鎹祻瑙堝櫒綾誨瀷涓篔ava鎻掍歡鐢熸垚OBJECT鎴朎MBED鏍囪
14remote鎺ュ彛鍜宧ome鎺ュ彛涓昏浣滅敤
remote鎺ュ彛瀹氫箟浜嗕笟鍔℃柟娉曪紝鐢ㄤ簬EJB瀹㈡埛绔皟鐢ㄤ笟鍔℃柟娉?
home鎺ュ彛鏄疎JB宸ュ巶鐢ㄤ簬鍒涘緩鍜岀Щ闄ゆ煡鎵綞JB瀹炰緥
15瀹㈡湇绔皟鐢‥JB瀵硅薄鐨勫嚑涓熀鏈楠?
涓銆?璁劇疆JNDI鏈嶅姟宸ュ巶浠ュ強JNDI鏈嶅姟鍦板潃緋葷粺灞炴?
浜屻?鏌ユ壘Home鎺ュ彛
涓夈?浠嶩ome鎺ュ彛璋冪敤Create鏂規硶鍒涘緩Remote鎺ュ彛
鍥涖?閫氳繃Remote鎺ュ彛璋冪敤鍏朵笟鍔℃柟娉?
]]>
錛堥氬父鎯呭喌涓嬶紝C++錛孋璇█紼嬪簭緙栬瘧涔嬪悗錛屼篃鍏鋒湁鍚屾牱鐨勭壒鎬с傦級
姣斿錛屾垜浠湁濡備笅浠g爜銆?br />
String A = “atom”;
String B = “atom”;
鎴戜滑鏈夌悊鐢辮涓猴紝A鍜孊鎸囧悜鍚屼竴涓瓧絎︿覆甯擱噺銆傚嵆錛孉==B銆?br />
娉ㄦ剰錛屽0鏄庡瓧絎︿覆鍙橀噺鐨勪唬鐮侊紝涓嶇鍚堜笂闈㈢殑瑙勫垯銆?br />
String C= new String(“atom”);
String D = new String(“atom”);
榪欓噷鐨凜鍜孌鐨勫0鏄庢槸瀛楃涓插彉閲忕殑澹版槑錛屾墍浠ワ紝C != D銆?br />
]]>
褰撳疄鐜癹ava.io.Serializable鎺ュ彛鐨勫疄浣擄紙綾伙級娌℃湁鏄懼紡鍦板畾涔変竴涓悕涓?font color="#ff0000">serialVersionUID錛岀被鍨嬩負long鐨勫彉閲忔椂錛孞ava搴忓垪鍖栨満鍒朵細鏍規嵁緙栬瘧鐨刢lass鑷姩鐢熸垚涓涓?font color="#ff0000">serialVersionUID浣滃簭鍒楀寲鐗堟湰姣旇緝鐢紝榪欑鎯呭喌涓嬶紝鍙湁鍚屼竴嬈$紪璇戠敓鎴愮殑class鎵嶄細鐢熸垚鐩稿悓鐨?font color="#ff0000">serialVersionUID 銆?/font>
濡傛灉鎴戜滑涓嶅笇鏈涢氳繃緙栬瘧鏉ュ己鍒跺垝鍒嗚蔣浠剁増鏈紝鍗沖疄鐜板簭鍒楀寲鎺ュ彛鐨勫疄浣撹兘澶熷吋瀹瑰厛鍓嶇増鏈紝鏈綔鏇存敼鐨勭被錛屽氨闇瑕佹樉寮忓湴瀹氫箟涓涓悕涓?font color="#ff0000">serialVersionUID錛岀被鍨嬩負long鐨勫彉閲忥紝涓嶄慨鏀硅繖涓彉閲忓肩殑搴忓垪鍖栧疄浣撻兘鍙互鐩鎬簰榪涜涓茶鍖栧拰鍙嶄覆琛屽寲銆?
婧愯嚜錛歨ttp://sharajava.javaeye.com/blog/102886
鍙傛暟 |
璇箟 |
deprecation |
浣跨敤浜嗚繃鏃剁殑綾繪垨鏂規硶鏃剁殑璀﹀憡 |
unchecked |
鎵ц浜嗘湭媯鏌ョ殑杞崲鏃剁殑璀﹀憡錛屼緥濡傚綋浣跨敤闆嗗悎鏃舵病鏈夌敤娉涘瀷 (Generics) 鏉ユ寚瀹氶泦鍚堜繚瀛樼殑綾誨瀷 |
fallthrough |
褰?span lang="EN-US"> Switch 紼嬪簭鍧楃洿鎺ラ氬線涓嬩竴縐嶆儏鍐佃屾病鏈?span lang="EN-US"> Break 鏃剁殑璀﹀憡 |
path |
鍦ㄧ被璺緞銆佹簮鏂囦歡璺緞絳変腑鏈変笉瀛樺湪鐨勮礬寰勬椂鐨勮鍛?span lang="EN-US" style="color: black"> |
serial |
褰撳湪鍙簭鍒楀寲鐨勭被涓婄己灝?span lang="EN-US"> serialVersionUID 瀹氫箟鏃剁殑璀﹀憡 |
finally |
浠諱綍 finally 瀛愬彞涓嶈兘姝e父瀹屾垚鏃剁殑璀﹀憡 |
all |
鍏充簬浠ヤ笂鎵鏈夋儏鍐電殑璀﹀憡 |
Override
@Override
銆銆public int hashCode() {
銆銆...
銆銆}
public enum DatabaseType {
銆銆ORACLE {
銆銆public String getJdbcUrl() {...}
銆銆},
銆銆MYSQL {
銆銆public String getJdbcUrl() {...}
銆銆};
銆銆public abstract String getJdbcUrl();
銆銆}
public interface Zoo {
銆銆public Animal getAnimal();
銆銆}
銆銆public class ZooImpl implements Zoo {
銆銆public Animal getAnimal(){
銆銆return new AnimalImpl();
銆銆}
銆銆}
銆銆鍗忓彉榪斿洖鐨勪嬌鐢ㄦ浛鎹簡涓変釜鍙嶆ā寮忥細
ZooImpl._animal
鍙︿竴縐嶅艦寮忔槸錛屽湪鐭ラ亾瀹炵幇鐨勫疄闄呬笂鏄壒瀹氱殑瀛愮被鐨勬儏鍐典笅錛屽湪璋冪敤紼嬪簭涓墽琛屽悜涓嬭漿鎹細
((AnimalImpl)ZooImpl.getAnimal()).implMethod();
銆銆
ZooImpl._getAnimal();
銆銆榪欎笁縐嶆ā寮忛兘鏈夊畠浠殑闂鍜屽眬闄愭с傝涔堟槸涓嶅鏁存磥錛岃涔堝氨鏄毚闇蹭簡涓嶅繀瑕佺殑瀹炵幇緇嗚妭銆?br />
銆銆鍗忓彉
銆銆鍗忓彉榪斿洖妯″紡灝辨瘮杈冩暣媧併佸畨鍏ㄥ茍涓旀槗浜庣淮鎶わ紝瀹冧篃涓嶉渶瑕佺被鍨嬪己鍒惰漿鎹㈡垨鐗瑰畾鐨勬柟娉曟垨瀛楁錛?br />
銆銆public AnimalImpl getAnimal(){
銆銆return new AnimalImpl();
銆銆}
銆銆浣跨敤緇撴灉錛?br />
銆銆ZooImpl.getAnimal().implMethod();
鍙傝冿細http://www.linuxpk.com/43834.html
鍗佸叚榪涘埗杞垚鍗佽繘鍒?br>Integer.valueOf("FFFF",16).toString()
鍏繘鍒惰漿鎴愬崄榪涘埗
Integer.valueOf("876",8).toString()
浜岃繘鍒惰漿鍗佽繘鍒?br>Integer.valueOf("0101",2).toString()