1.javaç¼ç¨è§èï¼ï¼ï¼
2.Hibernateå·²ç»è½ä¼äºåï¼
3.怎样把JAVA源代码编译exe文件?源码
4.JWT:谁创造了我,我听命于谁
javaç¼ç¨è§èï¼ï¼ï¼
å称 Javaè¯è¨ç¼ç è§è(Java Code Conventions)
ãç®ä» æ¬æ档讲述äºJavaè¯è¨çç¼ç è§èï¼è¾ä¹éä¸å¿ å çãc++ç¼ç è§èãç浩ç¹è¯¦å°½ï¼æ¤æå½å±çå°ç²¾æäºãèå ¶ä¸æåä¹å项æ¡æ¬¾ï¼ä»ç¼ç é£æ ¼ï¼å°æ³¨æäºé¡¹ï¼ä¸ååªJavaï¼å¯¹äºå ¶ä»è¯è¨ï¼ä¹é½å¾æåé´æä¹ãå 为ç®çï¼æ以æè®°ï¼å¤§å®¶ä¸å¦¨å°æ¤ä½ä¸ºhandbookï¼å¸¸å¤æ¡å¤´ï¼éä¸å¯¹éªã
1 ä»ç»
1.1 为ä»ä¹è¦æç¼ç è§è
1.2 çæ声æ
2 æ件å
2.1 æ件åç¼
2.2 常ç¨æ件å
3 æ件ç»ç»
3.1 Javaæºæ件
3.1.1 å¼å¤´æ³¨é
3.1.2 å åå¼å ¥è¯å¥
3.1.3 ç±»åæ¥å£å£°æ
4 缩è¿æç
4.1 è¡é¿åº¦
4.2 æ¢è¡
5 注é
5.1 å®ç°æ³¨éçæ ¼å¼
5.1.1 å注é
5.1.2 åè¡æ³¨é
5.1.3 尾端注é
5.1.4 è¡æ«æ³¨é
5.2 ææ¡æ³¨é
6 声æ
6.1 æ¯è¡å£°æåéçæ°é
6.2 åå§å
6.3 å¸å±
6.4 ç±»åæ¥å£ç声æ
7 è¯å¥
7.1 ç®åè¯å¥
7.2 å¤åè¯å¥
7.3 è¿åè¯å¥
7.4 ifï¼if-elseï¼if else-if elseè¯å¥
7.5 forè¯å¥
7.6 whileè¯å¥
7.7 do-whileè¯å¥
7.8 switchè¯å¥
7.9 try-catchè¯å¥
8 空ç½
8.1 空è¡
8.2 ç©ºæ ¼
9 å½åè§è
ç¼ç¨æ¯ä¾
.1 æä¾å¯¹å®ä¾ä»¥åç±»åéç访é®æ§å¶
.2 å¼ç¨ç±»åéåç±»æ¹æ³
.3 常é
.4 åéèµå¼
.5 å ¶å®æ¯ä¾
.5.1 åæ¬å·
.5.2 è¿åå¼
.5.3 æ¡ä»¶è¿ç®ç¬¦"?源码正36的源码"åç表达å¼"?"åç表达å¼
.5.4 ç¹æ®æ³¨é
代ç èä¾
.1 Javaæºæ件èä¾
1 ä»ç»(Introduction)
1.1 为ä»ä¹è¦æç¼ç è§è(Why Have Code Conventions)
ç¼ç è§è对äºç¨åºåèè¨å°¤ä¸ºéè¦ï¼æ以ä¸å 个åå ï¼
- ä¸ä¸ªè½¯ä»¶ççå½å¨æä¸ï¼%çè±è´¹å¨äºç»´æ¤
- å ä¹æ²¡æä»»ä½ä¸ä¸ªè½¯ä»¶ï¼å¨å ¶æ´ä¸ªçå½å¨æä¸ï¼åç±æåçå¼å人åæ¥ç»´æ¤
- ç¼ç è§èå¯ä»¥æ¹å软件çå¯è¯»æ§ï¼å¯ä»¥è®©ç¨åºå尽快èå½»åºå°ç解æ°ç代ç
- å¦æä½ å°æºç ä½ä¸ºäº§ååå¸ï¼å°±éè¦ç¡®ä»»å®æ¯å¦è¢«å¾å¥½çæå 并ä¸æ¸ æ°æ 误ï¼ä¸å¦ä½ å·²æ建çå ¶å®ä»»ä½äº§å
为äºæ§è¡è§èï¼æ¯ä¸ªè½¯ä»¶å¼å人åå¿ é¡»ä¸è´éµå®ç¼ç è§èãæ¯ä¸ªäººã
1.2 çæ声æ(Acknowledgments)
æ¬ææ¡£åæ çæ¯Sun MicroSystemså ¬å¸ï¼Javaè¯è¨è§èä¸çç¼ç æ åé¨åã主è¦è´¡ç®è å æ¬ï¼Peter Kingï¼Patrick Naughtonï¼Mike DeMoneyï¼Jonni Kanervaï¼Kathy Walrath以åScott Hommelã
æ¬ææ¡£ç°ç±Scott Hommelç»´æ¤ï¼æå ³è¯è®ºæè§è¯·åè³shommel@eng.sun.com
2 æ件å(File Names)
è¿é¨åååºäºå¸¸ç¨çæ件ååå ¶åç¼ã
2.1 æ件åç¼(File Suffixes)
Javaç¨åºä½¿ç¨ä¸åæ件åç¼ï¼
æä»¶ç±»å« æ件åç¼
Javaæºæ件 .java
Javaåèç æ件 .class
2.2 常ç¨æ件å(Common File Names)
常ç¨çæ件åå æ¬ï¼
æ件å ç¨é
GNUmakefile makefilesçé¦éæ件åãæ们éç¨gnumakeæ¥å建ï¼buildï¼è½¯ä»¶ã
README æ¦è¿°ç¹å®ç®å½ä¸æå«å 容çæ件çé¦éæ件å
3 æ件ç»ç»(File Organization)
ä¸ä¸ªæ件ç±è¢«ç©ºè¡åå²èæç段è½ä»¥åæ è¯æ¯ä¸ªæ®µè½çå¯é注éå ±åç»æãè¶ è¿è¡çç¨åºé¾ä»¥é 读ï¼åºè¯¥å°½éé¿å ã"Javaæºæ件èä¾"æä¾äºä¸ä¸ªå¸å±åççJavaç¨åºèä¾ã
3.1 Javaæºæ件(Java Source Files)
æ¯ä¸ªJavaæºæ件é½å å«ä¸ä¸ªåä¸çå ¬å ±ç±»ææ¥å£ãè¥ç§æç±»åæ¥å£ä¸ä¸ä¸ªå ¬å ±ç±»ç¸å ³èï¼å¯ä»¥å°å®ä»¬åå ¬å ±ç±»æ¾å ¥åä¸ä¸ªæºæ件ãå ¬å ±ç±»å¿ é¡»æ¯è¿ä¸ªæ件ä¸ç第ä¸ä¸ªç±»ææ¥å£ã
Javaæºæ件è¿éµå¾ªä»¥ä¸è§åï¼
- å¼å¤´æ³¨éï¼åè§"å¼å¤´æ³¨é"ï¼
- å åå¼å ¥è¯å¥ï¼åè§"å åå¼å ¥è¯å¥"ï¼
- ç±»åæ¥å£å£°æï¼åè§"ç±»åæ¥å£å£°æ"ï¼
3.1.1 å¼å¤´æ³¨é(Beginning Comments)
ææçæºæ件é½åºè¯¥å¨å¼å¤´æä¸ä¸ªCè¯è¨é£æ ¼ç注éï¼å ¶ä¸ååºç±»åãçæ¬ä¿¡æ¯ãæ¥æåçæ声æï¼
/
** Classname
*
* Version information
*
* Date
*
* Copyright notice
*/
3.1.2 å åå¼å ¥è¯å¥(Package and Import Statements)
å¨å¤æ°Javaæºæ件ä¸ï¼ç¬¬ä¸ä¸ªé注éè¡æ¯å è¯å¥ãå¨å®ä¹åå¯ä»¥è·å¼å ¥è¯å¥ãä¾å¦ï¼
package java.awt;
import java.awt.peer.CanvasPeer;
3.1.3 ç±»åæ¥å£å£°æ(Class and Interface Declarations)
ä¸è¡¨æè¿°äºç±»åæ¥å£å£°æçå个é¨å以åå®ä»¬åºç°çå å次åºãåè§"Javaæºæ件èä¾"ä¸ä¸ä¸ªå å«æ³¨éçä¾åã
ç±»/æ¥å£å£°æçåé¨å 注解
1 ç±»/æ¥å£æ档注é(/**â¦â¦*/) 该注éä¸æéå å«çä¿¡æ¯ï¼åè§"æ档注é"
2 ç±»ææ¥å£ç声æ
3 ç±»/æ¥å£å®ç°ç注é(/*â¦â¦*/)å¦ææå¿ è¦çè¯ è¯¥æ³¨éåºå å«ä»»ä½æå ³æ´ä¸ªç±»ææ¥å£çä¿¡æ¯ï¼èè¿äºä¿¡æ¯åä¸éåä½ä¸ºç±»/æ¥å£æ档注éã
4 ç±»ç(éæ)åé é¦å æ¯ç±»çå ¬å ±åéï¼éåæ¯ä¿æ¤åéï¼ååæ¯å ä¸çº§å«çåé(没æ访é®ä¿®é¥°ç¬¦ï¼access modifier)ï¼æåæ¯ç§æåéã
5 å®ä¾åé é¦å æ¯å ¬å ±çº§å«çï¼éåæ¯ä¿æ¤çº§å«çï¼ååæ¯å ä¸çº§å«ç(没æ访é®ä¿®é¥°ç¬¦)ï¼æåæ¯ç§æ级å«çã
6 æé å¨
7 æ¹æ³ è¿äºæ¹æ³åºè¯¥æåè½ï¼èéä½ç¨åæ访é®æéï¼åç»ãä¾å¦ï¼ä¸ä¸ªç§æçç±»æ¹æ³å¯ä»¥ç½®äºä¸¤ä¸ªå ¬æçå®ä¾æ¹æ³ä¹é´ãå ¶ç®çæ¯ä¸ºäºæ´ä¾¿äºé 读åç解代ç ã
4 缩è¿æç(Indentation)
4ä¸ªç©ºæ ¼å¸¸è¢«ä½ä¸ºç¼©è¿æççä¸ä¸ªåä½ã缩è¿çç¡®å解é并æªè¯¦ç»æå®(ç©ºæ ¼ vs. å¶è¡¨ç¬¦)ãä¸ä¸ªå¶è¡¨ç¬¦çäº8ä¸ªç©ºæ ¼(èé4个)ã
4.1 è¡é¿åº¦(Line Length)
å°½éé¿å ä¸è¡çé¿åº¦è¶ è¿ä¸ªå符ï¼å 为å¾å¤ç»ç«¯åå·¥å ·ä¸è½å¾å¥½å¤çä¹ã
注æï¼ç¨äºææ¡£ä¸çä¾ååºè¯¥ä½¿ç¨æ´ççè¡é¿ï¼é¿åº¦ä¸è¬ä¸è¶ è¿ä¸ªå符ã
4.2 æ¢è¡(Wrapping Lines)
å½ä¸ä¸ªè¡¨è¾¾å¼æ æ³å®¹çº³å¨ä¸è¡å æ¶ï¼å¯ä»¥ä¾æ®å¦ä¸ä¸è¬è§åæå¼ä¹ï¼
- å¨ä¸ä¸ªéå·åé¢æå¼
- å¨ä¸ä¸ªæä½ç¬¦åé¢æå¼
- å®å¯éæ©è¾é«çº§å«(higher-level)çæå¼ï¼èéè¾ä½çº§å«(lower-level)çæå¼
- æ°çä¸è¡åºè¯¥ä¸ä¸ä¸è¡åä¸çº§å«è¡¨è¾¾å¼çå¼å¤´å¤å¯¹é½
- å¦æ以ä¸è§å导è´ä½ ç代ç æ··ä¹±æè ä½¿ä½ ç代ç é½å æ¤å¨å³è¾¹ï¼é£å°±ä»£ä¹ä»¥ç¼©è¿8ä¸ªç©ºæ ¼ã
以ä¸æ¯æå¼æ¹æ³è°ç¨çä¸äºä¾åï¼
someMethod(longExpression1, longExpression2, longExpression3,
longExpression4, longExpression5);
var = someMethod1(longExpression1,
someMethod2(longExpression2,
longExpression3));
以ä¸æ¯ä¸¤ä¸ªæå¼ç®æ¯è¡¨è¾¾å¼çä¾åãåè æ´å¥½ï¼å 为æå¼å¤ä½äºæ¬å·è¡¨è¾¾å¼çå¤è¾¹ï¼è¿æ¯ä¸ªè¾é«çº§å«çæå¼ã
longName1 = longName2 * (longName3 + longName4 - longName5)
+ 4 * longname6; //PREFFER
longName1 = longName2 * (longName3 + longName4
- longName5) + 4 * longname6; //AVOID
以ä¸æ¯ä¸¤ä¸ªç¼©è¿æ¹æ³å£°æçä¾åãåè æ¯å¸¸è§æ å½¢ãåè è¥ä½¿ç¨å¸¸è§ç缩è¿æ¹å¼å°ä¼ä½¿ç¬¬äºè¡å第ä¸è¡ç§»å¾å¾é å³ï¼æ以代ä¹ä»¥ç¼©è¿8ä¸ªç©ºæ ¼
//CONVENTIONAL INDENTATION
someMethod(int anArg, Object anotherArg, String yetAnotherArg,
Object andStillAnother) {
...
}
//INDENT 8 SPACES TO AVOID VERY DEEP INDENTS
private static synchronized horkingLongMethodName(int anArg,
Object anotherArg, String yetAnotherArg,
Object andStillAnother) {
...
}
ifè¯å¥çæ¢è¡é常使ç¨8ä¸ªç©ºæ ¼çè§åï¼å 为常è§ç¼©è¿(4ä¸ªç©ºæ ¼)ä¼ä½¿è¯å¥ä½çèµ·æ¥æ¯è¾è´¹å²ãæ¯å¦ï¼
//DONâT USE THIS INDENTATION
if ((condition1 && condition2)
|| (condition3 && condition4)
||!(condition5 && condition6)) { //BAD WRAPS
doSomethingAboutIt(); //MAKE THIS LINE EASY TO MISS
}
//USE THIS INDENTATION INSTEAD
if ((condition1 && condition2)
|| (condition3 && condition4)
||!(condition5 && condition6)) {
doSomethingAboutIt();
}
//OR USE THIS
if ((condition1 && condition2) || (condition3 && condition4)
||!(condition5 && condition6)) {
doSomethingAboutIt();
}
è¿éæä¸ç§å¯è¡çæ¹æ³ç¨äºå¤çä¸å è¿ç®è¡¨è¾¾å¼ï¼
alpha = (aLongBooleanExpression) ? beta : gamma;
alpha = (aLongBooleanExpression) ? beta
: gamma;
alpha = (aLongBooleanExpression)
? beta
: gamma;
5 注é(Comments)
Javaç¨åºæ两类注éï¼å®ç°æ³¨é(implementation comments)åæ档注é(document comments)ãå®ç°æ³¨éæ¯é£äºå¨C++ä¸è§è¿çï¼ä½¿ç¨/*...*/å//çå®ç注éãæ档注é(被称为"doc comments")æ¯Javaç¬æçï¼å¹¶ç±/**...*/çå®ãæ档注éå¯ä»¥éè¿javadocå·¥å ·è½¬æ¢æHTMLæ件ã
å®ç°æ³¨éç¨ä»¥æ³¨é代ç æè å®ç°ç»èãæ档注éä»å®ç°èªç±(implementation-free)çè§åº¦æ述代ç çè§èãå®å¯ä»¥è¢«é£äºæ头没ææºç çå¼å人å读æã
注éåºè¢«ç¨æ¥ç»åºä»£ç çæ»æ¬ï¼å¹¶æä¾ä»£ç èªèº«æ²¡ææä¾çéå ä¿¡æ¯ã注éåºè¯¥ä» å å«ä¸é 读åç解ç¨åºæå ³çä¿¡æ¯ãä¾å¦ï¼ç¸åºçå å¦ä½è¢«å»ºç«æä½äºåªä¸ªç®å½ä¸ä¹ç±»çä¿¡æ¯ä¸åºå æ¬å¨æ³¨éä¸ã
å¨æ³¨ééï¼å¯¹è®¾è®¡å³çä¸éè¦çæè ä¸æ¯æ¾èæè§çå°æ¹è¿è¡è¯´ææ¯å¯ä»¥çï¼ä½åºé¿å æä¾ä»£ç ä¸å·±æ¸ æ°è¡¨è¾¾åºæ¥çéå¤ä¿¡æ¯ãå¤ä½çç注éå¾å®¹æè¿æ¶ãé常åºé¿å é£äºä»£ç æ´æ°å°±å¯è½è¿æ¶ç注éã
注æï¼é¢ç¹ç注éææ¶åæ åºä»£ç çä½è´¨éãå½ä½ è§å¾è¢«è¿«è¦å 注éçæ¶åï¼èèä¸ä¸éå代ç ä½¿å ¶æ´æ¸ æ°ã
注éä¸åºåå¨ç¨æå·æå ¶ä»å符ç»åºæ¥ç大æ¡éã注éä¸åºå æ¬è¯¸å¦å¶è¡¨ç¬¦ååé符ä¹ç±»çç¹æ®å符ã
5.1 å®ç°æ³¨éçæ ¼å¼(Implementation Comment Formats)
ç¨åºå¯ä»¥æ4ç§å®ç°æ³¨éçé£æ ¼ï¼å(block)ãåè¡(single-line)ã尾端(trailing)åè¡æ«(end-of-line)ã
5.1.1 å注é(Block Comments)
å注éé常ç¨äºæä¾å¯¹æ件ï¼æ¹æ³ï¼æ°æ®ç»æåç®æ³çæè¿°ãå注é被置äºæ¯ä¸ªæ件çå¼å§å¤ä»¥åæ¯ä¸ªæ¹æ³ä¹åãå®ä»¬ä¹å¯ä»¥è¢«ç¨äºå ¶ä»å°æ¹ï¼æ¯å¦æ¹æ³å é¨ãå¨åè½åæ¹æ³å é¨çå注éåºè¯¥åå®ä»¬ææè¿°ç代ç å ·æä¸æ ·ç缩è¿æ ¼å¼ã
å注éä¹é¦åºè¯¥æä¸ä¸ªç©ºè¡ï¼ç¨äºæå注éå代ç åå²å¼æ¥ï¼æ¯å¦ï¼
/
** Here is a block comment.
*/
å注éå¯ä»¥ä»¥/*-å¼å¤´ï¼è¿æ ·indent(1)å°±å¯ä»¥å°ä¹è¯å«ä¸ºä¸ä¸ªä»£ç åçå¼å§ï¼èä¸ä¼éæå®ã
/*-
* Here is a block comment with some very special
* formatting that I want indent(1) to ignore.
*
* one
* two
* three
*/
注æï¼å¦æä½ ä¸ä½¿ç¨indent(1)ï¼å°±ä¸å¿ å¨ä»£ç ä¸ä½¿ç¨/*-ï¼æ为ä»äººå¯è½å¯¹ä½ ç代ç è¿è¡indent(1)ä½è®©æ¥ã
åè§"æ档注é"
5.1.2 åè¡æ³¨é(Single-Line Comments)
ç注éå¯ä»¥æ¾ç¤ºå¨ä¸è¡å ï¼å¹¶ä¸å ¶åç代ç å ·æä¸æ ·ç缩è¿å±çº§ãå¦æä¸ä¸ªæ³¨éä¸è½å¨ä¸è¡å åå®ï¼å°±è¯¥éç¨å注é(åè§"å注é")ãåè¡æ³¨éä¹ååºè¯¥æä¸ä¸ªç©ºè¡ã以ä¸æ¯ä¸ä¸ªJava代ç ä¸åè¡æ³¨éçä¾åï¼
if (condition) {
/* Handle the condition. */
...
}
5.1.3 尾端注é(Trailing Comments)
æçç注éå¯ä»¥ä¸å®ä»¬æè¦æè¿°ç代ç ä½äºåä¸è¡ï¼ä½æ¯åºè¯¥æ足å¤ç空ç½æ¥åå¼ä»£ç å注éãè¥æå¤ä¸ªç注éåºç°äºå¤§æ®µä»£ç ä¸ï¼å®ä»¬åºè¯¥å ·æç¸åç缩è¿ã
以ä¸æ¯ä¸ä¸ªJava代ç ä¸å°¾ç«¯æ³¨éçä¾åï¼
if (a == 2) {
return TRUE; /* special case */
} else {
return isPrime(a); /* works only for odd a */
}
5.1.4 è¡æ«æ³¨é(End-Of-Line Comments)
注éçå®ç¬¦"//"ï¼å¯ä»¥æ³¨éææ´è¡æè ä¸è¡ä¸çä¸é¨åãå®ä¸è¬ä¸ç¨äºè¿ç»å¤è¡ç注éææ¬ï¼ç¶èï¼å®å¯ä»¥ç¨æ¥æ³¨éæè¿ç»å¤è¡ç代ç 段ã以ä¸æ¯ææä¸ç§é£æ ¼çä¾åï¼
if (foo > 1) {
// Do a double-flip.
...
}
else {
return false; // Explain why here.
}
//if (bar > 1) {
//
// // Do a triple-flip.
// ...
//}
//else {
// return false;
//}
5.2 æ档注é(Documentation Comments)
注æï¼æ¤å¤æè¿°ç注éæ ¼å¼ä¹èä¾ï¼åè§"Javaæºæ件èä¾"
è¥æ³äºè§£æ´å¤ï¼åè§"How to Write Doc Comments for Javadoc"ï¼å ¶ä¸å å«äºæå ³æ档注éæ è®°çä¿¡æ¯(@return, @param, @see)ï¼
/javadoc/writingdoccomments/index.html
è¥æ³äºè§£æ´å¤æå ³æ档注éåjavadocç详ç»èµæï¼åè§javadocç主页ï¼
/javadoc/index.html
æ档注éæè¿°Javaçç±»ãæ¥å£ãæé å¨ï¼æ¹æ³ï¼ä»¥åå段(field)ãæ¯ä¸ªæ档注éé½ä¼è¢«ç½®äºæ³¨éå®ç符/**...*/ä¹ä¸ï¼ä¸ä¸ªæ³¨é对åºä¸ä¸ªç±»ãæ¥å£ææåã该注éåºä½äºå£°æä¹åï¼
/
*** The Example class provides ...
*/
public class Example { ...
注æ顶å±(top-level)çç±»åæ¥å£æ¯ä¸ç¼©è¿çï¼èå ¶æåæ¯ç¼©è¿çãæè¿°ç±»åæ¥å£çæ档注éç第ä¸è¡(/**)ä¸é缩è¿ï¼éåçæ档注éæ¯è¡é½ç¼©è¿1æ ¼(使æå·çºµå对é½)ãæåï¼å æ¬æé å½æ°å¨å ï¼å ¶æ档注éç第ä¸è¡ç¼©è¿4æ ¼ï¼éåæ¯è¡é½ç¼©è¿5æ ¼ã
è¥ä½ æ³ç»åºæå ³ç±»ãæ¥å£ãåéææ¹æ³çä¿¡æ¯ï¼èè¿äºä¿¡æ¯åä¸éååå¨ææ¡£ä¸ï¼åå¯ä½¿ç¨å®ç°å注é(è§5.1.1)æç´§è·å¨å£°æåé¢çåè¡æ³¨é(è§5.1.2)ãä¾å¦ï¼æå ³ä¸ä¸ªç±»å®ç°çç»èï¼åºæ¾å ¥ç´§è·å¨ç±»å£°æåé¢çå®ç°å注éä¸ï¼èä¸æ¯æ¾å¨æ档注éä¸ã
æ档注éä¸è½æ¾å¨ä¸ä¸ªæ¹æ³ææé å¨çå®ä¹åä¸ï¼å 为Javaä¼å°ä½äºæ档注éä¹åç第ä¸ä¸ªå£°æä¸å ¶ç¸å ³èã
6 声æ(Declarations)
6.1 æ¯è¡å£°æåéçæ°é(Number Per Line)
æ¨èä¸è¡ä¸ä¸ªå£°æï¼å 为è¿æ ·ä»¥å©äºå注éã亦å³ï¼
int level; // indentation level
int size; // size of table
è¦ä¼äºï¼
int level, size;
ä¸è¦å°ä¸åç±»ååéç声ææ¾å¨åä¸è¡ï¼ä¾å¦ï¼
int foo, fooarray[]; //WRONG!
注æï¼ä¸é¢çä¾åä¸ï¼å¨ç±»ååæ è¯ç¬¦ä¹é´æ¾äºä¸ä¸ªç©ºæ ¼ï¼å¦ä¸ç§è¢«å 许çæ¿ä»£æ¹å¼æ¯ä½¿ç¨å¶è¡¨ç¬¦ï¼
int level; // indentation level
int size; // size of table
Object currentEntry; // currently selected table entry
6.2 åå§å(Initialization)
å°½éå¨å£°æå±é¨åéçåæ¶åå§åãå¯ä¸ä¸è¿ä¹åççç±æ¯åéçåå§å¼ä¾èµäºæäºå ååçç计ç®ã
6.3 å¸å±(Placement)
åªå¨ä»£ç åçå¼å§å¤å£°æåéãï¼ä¸ä¸ªåæ¯æä»»ä½è¢«å å«å¨å¤§æ¬å·"{ "å"}"ä¸é´ç代ç ãï¼ä¸è¦å¨é¦æ¬¡ç¨å°è¯¥åéæ¶æ声æä¹ãè¿ä¼æ注æåä¸éä¸çç¨åºåæç³æ¶ï¼åæ¶ä¼å¦¨ç¢ä»£ç å¨è¯¥ä½ç¨åå çå¯ç§»æ¤æ§ã
void myMethod() {
int int1 = 0; // beginning of method block
if (condition) {
int int2 = 0; // beginning of "if" block
...
}
}
该è§åçä¸ä¸ªä¾å¤æ¯for循ç¯çç´¢å¼åé
for (int i = 0; i < maxLoops; i++) { ... }
é¿å 声æçå±é¨åéè¦çä¸ä¸çº§å£°æçåéãä¾å¦ï¼ä¸è¦å¨å é¨ä»£ç åä¸å£°æç¸åçåéåï¼
int count;
...
myMethod() {
if (condition) {
int count = 0; // AVOID!
...
}
...
}
6.4 ç±»åæ¥å£ç声æ(Class and Interface Declarations)
å½ç¼åç±»åæ¥å£æ¯ï¼åºè¯¥éµå®ä»¥ä¸æ ¼å¼è§åï¼
- å¨æ¹æ³åä¸å ¶åæ°å表ä¹åçå·¦æ¬å·"("é´ä¸è¦æç©ºæ ¼
- 左大æ¬å·"{ "ä½äºå£°æè¯å¥åè¡çæ«å°¾
- å³å¤§æ¬å·"}"å¦èµ·ä¸è¡ï¼ä¸ç¸åºç声æè¯å¥å¯¹é½ï¼é¤éæ¯ä¸ä¸ªç©ºè¯å¥ï¼"}"åºç´§è·å¨"{ "ä¹å
class Sample extends Object {
int ivar1;
int ivar2;
Sample(int i, int j) {
ivar1 = i;
ivar2 = j;
}
int emptyMethod() { }
...
}
- æ¹æ³ä¸æ¹æ³ä¹é´ä»¥ç©ºè¡åé
7 è¯å¥(Statements)
7.1 ç®åè¯å¥(Simple Statements)
æ¯è¡è³å¤å å«ä¸æ¡è¯å¥ï¼ä¾å¦ï¼
argv++; // Correct
argc--; // Correct
argv++; argc--; // AVOID!
7.2 å¤åè¯å¥(Compound Statements)
å¤åè¯å¥æ¯å å«å¨å¤§æ¬å·ä¸çè¯å¥åºåï¼å½¢å¦"{ è¯å¥ }"ãä¾å¦ä¸é¢å段ã
- 被æ¬å ¶ä¸çè¯å¥åºè¯¥è¾ä¹å¤åè¯å¥ç¼©è¿ä¸ä¸ªå±æ¬¡
- 左大æ¬å·"{ "åºä½äºå¤åè¯å¥èµ·å§è¡çè¡å°¾ï¼å³å¤§æ¬å·"}"åºå¦èµ·ä¸è¡å¹¶ä¸å¤åè¯å¥é¦è¡å¯¹é½ã
- 大æ¬å·å¯ä»¥è¢«ç¨äºææè¯å¥ï¼å æ¬å个è¯å¥ï¼åªè¦è¿äºè¯å¥æ¯è¯¸å¦if-elseæforæ§å¶ç»æçä¸é¨åãè¿æ ·ä¾¿äºæ·»å è¯å¥èæ éæ å¿ç±äºå¿äºå æ¬å·èå¼å ¥bugã
7.3 è¿åè¯å¥(return Statements)
ä¸ä¸ªå¸¦è¿åå¼çreturnè¯å¥ä¸ä½¿ç¨å°æ¬å·"()"ï¼é¤éå®ä»¬ä»¥æç§æ¹å¼ä½¿è¿åå¼æ´ä¸ºæ¾è§ãä¾å¦ï¼
return;
return myDisk.size();
return (size ? size : defaultSize);
7.4 ifï¼if-elseï¼if else-if elseè¯å¥(if, if-else, if else-if else Statements)
if-elseè¯å¥åºè¯¥å ·æå¦ä¸æ ¼å¼ï¼
if (condition) {
statements;
}
if (condition) {
statements;
} else {
statements;
}
if (condition) {
statements;
} else if (condition) {
statements;
} else{
statements;
}
注æï¼ifè¯å¥æ»æ¯ç¨"{ "å"}"æ¬èµ·æ¥ï¼é¿å 使ç¨å¦ä¸å®¹æå¼èµ·é误çæ ¼å¼ï¼
if (condition) //AVOID! THIS OMITS THE BRACES { }!
statement;
7.5 forè¯å¥(for Statements)
ä¸ä¸ªforè¯å¥åºè¯¥å ·æå¦ä¸æ ¼å¼ï¼
for (initialization; condition; update) {
statements;
}
ä¸ä¸ªç©ºçforè¯å¥(ææå·¥ä½é½å¨åå§åï¼æ¡ä»¶å¤æï¼æ´æ°åå¥ä¸å®æï¼åºè¯¥å ·æå¦ä¸æ ¼å¼ï¼
for (initialization; condition; update);
å½å¨forè¯å¥çåå§åææ´æ°åå¥ä¸ä½¿ç¨éå·æ¶ï¼é¿å å 使ç¨ä¸ä¸ªä»¥ä¸åéï¼è导è´å¤æ度æé«ãè¥éè¦ï¼å¯ä»¥å¨for循ç¯ä¹å(为åå§ååå¥)æfor循ç¯æ«å°¾(为æ´æ°åå¥)使ç¨åç¬çè¯å¥ã
7.6 whileè¯å¥(while Statements)
ä¸ä¸ªwhileè¯å¥åºè¯¥å ·æå¦ä¸æ ¼å¼
while (condition) {
statements;
}
ä¸ä¸ªç©ºçwhileè¯å¥åºè¯¥å ·æå¦ä¸æ ¼å¼ï¼
while (condition);
7.7 do-whileè¯å¥(do-while Statements)
ä¸ä¸ªdo-whileè¯å¥åºè¯¥å ·æå¦ä¸æ ¼å¼ï¼
do {
statements;
} while (condition);
7.8 switchè¯å¥(switch Statements)
ä¸ä¸ªswitchè¯å¥åºè¯¥å ·æå¦ä¸æ ¼å¼ï¼
switch (condition) {
case ABC:
statements;
/* falls through */
case DEF:
statements;
break;
case XYZ:
statements;
break;
default:
statements;
break;
}
æ¯å½ä¸ä¸ªcase顺çå¾ä¸æ§è¡æ¶(å 为没æbreakè¯å¥)ï¼é常åºå¨breakè¯å¥çä½ç½®æ·»å 注éãä¸é¢ç示ä¾ä»£ç ä¸å°±å å«æ³¨é/* falls through */ã
7.9 try-catchè¯å¥(try-catch Statements)
ä¸ä¸ªtry-catchè¯å¥åºè¯¥å ·æå¦ä¸æ ¼å¼ï¼
try {
statements;
} catch (ExceptionClass e) {
statements;
}
ä¸ä¸ªtry-catchè¯å¥åé¢ä¹å¯è½è·çä¸ä¸ªfinallyè¯å¥ï¼ä¸è®ºtry代ç åæ¯å¦é¡ºå©æ§è¡å®ï¼å®é½ä¼è¢«æ§è¡ã
try {
statements;
} catch (ExceptionClass e) {
statements;
} finally {
statements;
}
8 空ç½(White Space)
8.1 空è¡(Blank Lines)
空è¡å°é»è¾ç¸å ³ç代ç 段åéå¼ï¼ä»¥æé«å¯è¯»æ§ã
ä¸åæ åµåºè¯¥æ»æ¯ä½¿ç¨ä¸¤ä¸ªç©ºè¡ï¼
- ä¸ä¸ªæºæ件ç两个ç段(section)ä¹é´
- 类声æåæ¥å£å£°æä¹é´
ä¸åæ åµåºè¯¥æ»æ¯ä½¿ç¨ä¸ä¸ªç©ºè¡ï¼
- 两个æ¹æ³ä¹é´
- æ¹æ³å çå±é¨åéåæ¹æ³ç第ä¸æ¡è¯å¥ä¹é´
- å注éï¼åè§"5.1.1"ï¼æåè¡æ³¨éï¼åè§"5.1.2"ï¼ä¹å
- ä¸ä¸ªæ¹æ³å ç两个é»è¾æ®µä¹é´ï¼ç¨ä»¥æé«å¯è¯»æ§
8.2 ç©ºæ ¼(Blank Spaces)
ä¸åæ åµåºè¯¥ä½¿ç¨ç©ºæ ¼ï¼
- ä¸ä¸ªç´§è·çæ¬å·çå ³é®ååºè¯¥è¢«ç©ºæ ¼åå¼ï¼ä¾å¦ï¼
while (true) {
...
}
注æï¼ç©ºæ ¼ä¸åºè¯¥ç½®äºæ¹æ³åä¸å ¶å·¦æ¬å·ä¹é´ãè¿å°æå©äºåºåå ³é®ååæ¹æ³è°ç¨ã
- 空ç½åºè¯¥ä½äºåæ°å表ä¸éå·çåé¢
- ææçäºå è¿ç®ç¬¦ï¼é¤äº"."ï¼åºè¯¥ä½¿ç¨ç©ºæ ¼å°ä¹ä¸æä½æ°åå¼ãä¸å æä½ç¬¦åæä½æ°ä¹é´ä¸å 该å ç©ºæ ¼ï¼æ¯å¦ï¼è´å·("-")ãèªå¢("++")åèªå("--")ãä¾å¦ï¼
a += c + d;
a = (a + b) / (c * d);
while (d++ = s++) {
n++;
}
printSize("size is " + foo + "\n");
- forè¯å¥ä¸ç表达å¼åºè¯¥è¢«ç©ºæ ¼åå¼ï¼ä¾å¦ï¼
for (expr1; expr2; expr3)
- 强å¶è½¬åååºè¯¥è·ä¸ä¸ªç©ºæ ¼ï¼ä¾å¦ï¼
myMethod((byte) aNum, (Object) x);
myMethod((int) (cp + 5), ((int) (i + 3)) + 1);
9 å½åè§è(Naming Conventions)
å½åè§è使ç¨åºæ´æ读ï¼ä»èæ´æäºç解ãå®ä»¬ä¹å¯ä»¥æä¾ä¸äºæå ³æ è¯ç¬¦åè½çä¿¡æ¯ï¼ä»¥å©äºç解代ç ï¼ä¾å¦ï¼ä¸è®ºå®æ¯ä¸ä¸ªå¸¸éï¼å ï¼è¿æ¯ç±»ã
æ è¯ç¬¦ç±»å å½åè§å ä¾å
å (Packages) ä¸ä¸ªå¯ä¸å åçåç¼æ»æ¯å ¨é¨å°åçASCIIåæ¯å¹¶ä¸æ¯ä¸ä¸ªé¡¶çº§ååï¼é常æ¯comï¼eduï¼govï¼milï¼netï¼orgï¼æå¹´ISO æ åææå®çæ è¯å½å®¶çè±æåå符代ç ãå åçåç»é¨åæ ¹æ®ä¸åæºæåèªå é¨çå½åè§èèä¸å°½ç¸åãè¿ç±»å½åè§èå¯è½ä»¥ç¹å®ç®å½åçç»ææ¥åºåé¨é¨(department)ï¼é¡¹ç®(project)ï¼æºå¨(machine)ï¼æ注åå(login names)ã com.sun.eng
com.apple.quicktime.v2
edu.cmu.cs.bovik.cheese
ç±»(Classes) å½åè§åï¼ç±»åæ¯ä¸ªä¸åè¯ï¼éç¨å¤§å°åæ··åçæ¹å¼ï¼æ¯ä¸ªåè¯çé¦åæ¯å¤§åãå°½éä½¿ä½ çç±»åç®æ´èå¯äºæè¿°ã使ç¨å®æ´åè¯ï¼é¿å 缩åè¯(é¤é该缩åè¯è¢«æ´å¹¿æ³ä½¿ç¨ï¼åURLï¼HTML) class Raster;
class ImageSprite;
æ¥å£(Interfaces) å½åè§åï¼å¤§å°åè§åä¸ç±»åç¸ä¼¼ interface RasterDelegate;
interface Storing;
æ¹æ³(Methods) æ¹æ³åæ¯ä¸ä¸ªå¨è¯ï¼éç¨å¤§å°åæ··åçæ¹å¼ï¼ç¬¬ä¸ä¸ªåè¯çé¦åæ¯å°åï¼å ¶ååè¯çé¦åæ¯å¤§åã run();
runFast();
getBackground();
åé(Variables) é¤äºåéåå¤ï¼ææå®ä¾ï¼å æ¬ç±»ï¼ç±»å¸¸éï¼åéç¨å¤§å°åæ··åçæ¹å¼ï¼ç¬¬ä¸ä¸ªåè¯çé¦åæ¯å°åï¼å ¶ååè¯çé¦åæ¯å¤§åãåéåä¸åºä»¥ä¸å线æç¾å 符å·å¼å¤´ï¼å°½ç®¡è¿å¨è¯æ³ä¸æ¯å 许çã
åéååºç®çä¸å¯äºæè¿°ãåéåçéç¨åºè¯¥æäºè®°å¿ï¼å³ï¼è½å¤æåºå ¶ç¨éãå°½éé¿å å个å符çåéåï¼é¤éæ¯ä¸æ¬¡æ§ç临æ¶åéã临æ¶åéé常被åå为iï¼jï¼kï¼månï¼å®ä»¬ä¸è¬ç¨äºæ´åï¼cï¼dï¼eï¼å®ä»¬ä¸è¬ç¨äºå符åã char c;
int i;
float myWidth;
å®ä¾åé(Instance Variables) 大å°åè§åååéåç¸ä¼¼ï¼é¤äºåé¢éè¦ä¸ä¸ªä¸å线 int _employeeId;
String _name;
Customer _customer;
常é(Constants) 类常éåANSI常éç声æï¼åºè¯¥å ¨é¨å¤§åï¼åè¯é´ç¨ä¸å线éå¼ã(å°½éé¿å ANSI常éï¼å®¹æå¼èµ·é误) static final int MIN_WIDTH = 4;
static final int MAX_WIDTH = ;
static final int GET_THE_CPU = 1;
ç¼ç¨æ¯ä¾(Programming Practices)
.1 æä¾å¯¹å®ä¾ä»¥åç±»åéç访é®æ§å¶(Providing Access to Instance and Class Variables)
è¥æ²¡æ足å¤çç±ï¼ä¸è¦æå®ä¾æç±»åé声æä¸ºå ¬æãé常ï¼å®ä¾åéæ éæ¾å¼ç设置(set)åè·å(gotten)ï¼é常è¿ä½ä¸ºæ¹æ³è°ç¨çè¾¹ç¼æåº (side effect)è产çã
ä¸ä¸ªå ·æå ¬æå®ä¾åéçæ°å½ä¾åï¼æ¯ç±»ä» ä½ä¸ºæ°æ®ç»æï¼æ²¡æè¡ä¸ºã亦å³ï¼è¥ä½ è¦ä½¿ç¨ä¸ä¸ªç»æ(struct)èéä¸ä¸ªç±»(å¦æjavaæ¯æç»æçè¯)ï¼é£ä¹æç±»çå®ä¾åé声æä¸ºå ¬ææ¯åéçã
Hibernateå·²ç»è½ä¼äºåï¼
ããå¨Javaä¸ç Hibernateæ¯æå¼äººå ³æ³¨çä¸ä¸ªè¯é¢ ä»Gavin Kingå å ¥EJB EG è´è´£å¶è®¢EJB çæä¹ å±è§è å°Gavin Kingéæ£å¼éåºJDO EG 并ä¸å 满个人æ 绪çæ»å»JDO è§è å°ãHibernate in Actionãçåè¡ åå°Hibernate Alphaçåå¸ æååå°æè¿JBoss PRçåå¸ï¼ä½¿ç¨Hibernate å®ç°Entity Beanï¼ å¯ä»¥è¯´è¿å ¶ä¸çæ¯ä¸æ¥é½å¼èµ·ä¸çç侧ç®ããHibernateå¨ä¸å° å¹´çæ¶é´é ä»ä¸ä¸ªä¸èµ·ç¼çå¼æºè½¯ä»¶åå±å°ä»å¤©ä»¤ä¸çç©ç®ç主æµO/R Mappingæ¡æ¶ Gavin Kingä»ä¸ä¸ªå¼æºè½¯ä»¶çä½è æ为ä¸ç举足轻éçäººç© è¿å¤å°æäºä¼ å¥çè²å½© æ¯ç« å纯ä»ææ¯æå°±èè¨ Hibernateä¸ç®æ¯æææå°±çJavaå¼æºæ¡æ¶è½¯ä»¶ å°ç®å为æ¢ä¹ä¸æ¯ä¸ä¸ªå®ç¾æ 缺ç软件 ä»ä¸ªäººææ¯æ°´å¹³èè¨ Gavin Kingä¹ä¸ç®ç»é¡¶é«æ
ããå¨å½åçJavaæä¹ å±æ¡æ¶ä¸ ææµè¡çO/R Mappin *** ååå«æ¯Hibernate JDOåTopLink
ããèªä»å»å¹´Gavin Kingå å ¥JBossä¹å Hibernateå·²ç»ç±ä¸ä¸ªæ°é´çå¼æºè½¯ä»¶èµ°ä¸äºå ¼å®¹EJB EntityBeançéè·¯ ç¶èæ´å 令人侧ç®çæ¯ Gavin Kingå¨EJB EGä¸å å½äºä¸ä¸ªé常éè¦çè§è² åªè¦å¯¹æ¯ä¸ä¸EJB çEntityBeanåHibernate çç¸å°±ä¼å¤§ç½ è½ç¶APIæ¥å£ä¸å ä½æ¯ EntityBeanç设计ç念å®å ¨æ¥èªäºHibernate
ããè½ç¶EJB çEntityBeanå¨ç¸å½ç¨åº¦ä¸æ¥æºäºHibernate ä½æ¯æ¯ç«æ¯ä¸åçAPIæ¥å£ å æ¤HibernateåEJB EntityBean究ç«æ¯ææ ·çä¸ç§å ³ç³» æ¯å¾å¤äººå¿ä¸ççé®
ãã å¹´åæ份JBossçBen Wang访åæé´ ææ¾ç»åBen请æHibernateçæªæ¥åå± ä»åç说 Hibernateæªæ¥å°ä»æ§ä»¥ç¬ç«ç软件产ååå¨ååå± æ¢å¯ä»¥ outside EJB containerä½¿ç¨ åæ¶Hibernateä¹å°å为JBoss EntityBean Implementation åå¯ä»¥inside EJB containerä½¿ç¨ ç¶èå¦ä½æ¢inside åoutside ç»ç©¶ç¼ºä¹ä¸ä¸ªææ§ç认è¯
ãã æ æ¥JBossåå¸ç EJB PRæå¼äºçæ¡ ä»SourcefeçCVSæå¡å¨ä¸é¢checkoutåºæ¥æºä»£ç çä¸ä¸ æ们å¯ä»¥åç° Gavin King对Hibernate è¿è¡äºç®åçå°è£ å°EJB EntityBean APIè°ç¨è½¬æ¢ä¸ºå é¨Hibernate èªå·±çAPI ä»èå®ç°EJB EntityBeançå ¼å®¹
ããEJB ä¸æ¿è¯ºè±ç¦»å®¹å¨è°ç¨ å¦æä½ æ³äº«ç¨EJB åå¿ é¡»è¿è¡å¨æ个EJB Vendoræä¾ç容å¨å ä¾å¦ä½ 使ç¨JBossæä¾çå®¹å¨ é£ä¹ä½ è°ç¨çæ¯EntityBean API è¿äºè°ç¨è¯·æ±ä¼è¢«è½¬æ¢ä¸ºHibernate APIçè°ç¨è¯·æ± è¿æå³çHibernateå®é ä¸æä¾äºä¸¤å¥API ä¸å¥æ¯HibernateåçAPI å¦ä¸å¥æ¯å ¼å®¹EJB EntityBean API 对äºé£äºéè¦åå¸å¼è°ç¨æ¯æ éè¦EJB容å¨çå¼å人åæ¥è¯´ ä»ä»¬éæ©åä¸å¥API 对äºä¸éè¦EJB容å¨çå¼å人åæ¥è¯´ ä»ä»¬éæ©åä¸å¥ API è¿å°±æ¯Hibernateæ¢å®çåå±çç¥
ããä»å¹´å¤å¤©æ票éè¿çJDO æ åä»æç§ç¨åº¦èè¨ å¹¶ä¸éè²äº Hibernateå½åççæ¬ æäºåè½çè³æ¯Hibernateè¿è¦å¥½ ä¾å¦ JDOæ¯æ对类å±æ§çlazy loading èHibernateè¦å° ææ¯æ å½åHibernateä» ä» æ¯æç±»çlazy loading å®é ä¸å¨å»å¹´ 就已ç»æå¾å¤ç¨æ·ä¸ææåºå¯¹ç±»å±æ§çlazy loadingçéæ± ç¶èGavin Kingå½æ¶ä¸ç´ä¸è®¤ä¸ºè¿ä¸ªéæ±ææ·»å çå¿ è¦æ§ åä¾å¦è¢«Gavin King形容为 å¯æç JDOQL å®é ä¸æ¯ç±»SQLæ¥è¯¢è¯è¨å对象æ¡ä»¶æ¥è¯¢çæ··åä½ ä»åè½ä¸æ¥è¯´ ä¸å¦HQL强大 ä½æ¯æ¯Hibernateèªå·±çæ¡ä»¶æ¥è¯¢å¼º
ããä¸ç¥é究ç«åºäºä»ä¹åå Gavin King对JDOä¼¼ä¹ä¸ç´ææç±è¡·çåæ¶ æ ä»å¨Hibernateçblogä¸é¢å¯¹JDOè¿è¡äºæ¯«ä¸çæ çæ¹å¤ å举äºJDOçç§ç§ç¼ºç¹æ¥è§£é为ä»ä¹EJB æä¹ å±è§è没ææJDOèèè¿å» ç¶èäºå®ä¸ä»çæ¹å¤å 满äºå¯¹JDOç误解ååè§ ä¾å¦Gavin Kingææ¨JDOQLä¸æ¯«æ²¡æä»ä¹ç¹å«ççç± åªå 为JDOQLä¸æ¯ä¸ä¸ªçº¯ç²¹çæ¥è¯¢è¯è¨ èæ¯ä¸ä¸ªæ··åä½ è¿å¤å°è®©äººå¯¹Gavin Kingçé£åº¦æå°éæ¾ å¨è¢«SolarmetricçAbe Whiteå驳ä¹å åæ ·æ²¡æé£åº¦ç说 æå¯æ²¡ææ¶é´åè¿ç§æ è°çäºè®º äºå®ä¸æ¯ä¸ªäººé½è®¤ä¸ºä»èªå·±çææ¯æ¯æ好çâ¦â¦ææ¯éäº JDOé£ä¼äººä¹éäº æ¯ä¸ªäººé½ä¼ç¯é误â¦â¦ ï¼æ以说人æ å®äººï¼ï¼
ããJDO è§èçåºå°äºå®ä¸ææäºå¯¹Hibernate ä¹è³åºäº Hibernateç念çEJB EntityBeanç严éå¨è JDO è§èå¨åè½ä¸ç严é缺失导è´äºJDOæ åé¢å¯¹HibernateåTopLinkçç«äº ç¶èåè½åºæ¬å®å¤çJDO æä¼å¤JDO Vendoråä¸æ¯æçåå åæ¶JDOè§èå¯ä»¥é¿å 产åéå®å¨æ个Vendorçä¼å¿ å·²ç»å°ç«äºç天平æç´
ãã
ããç¶èJDO åEJB 两大åä¸ä¸»æµæ åçåè£ æ¯å¤§é¨å人 çè³å æ¬ååæä¸å¸æçå°ç äºæ¯æç»EJB çLead Linda DeMichielåJDO çLead Craig Russellèååè¡¨å ¬å¼ä¿¡ 宣å¸äºä¸ä¸ªå并EJB åJDO æä¹ å±è§èç计å æ°çæä¹ å±è§èå°ä»¥JSR ï¼EJB ï¼çæä¹ å±è§è为åºç¡ èåJDO çé¨åç¹æ§ æ°çæä¹ å±è§èå°è¿å ¥J EE ä¹ä¸ ç¬ç«äºEJBåå¨ æ¢å¯ä»¥inside J EE容å¨æ¥ä½¿ç¨ ä¹å¯ä»¥è±ç¦»J EEå®¹å¨ ç¬ç«çè¿è¡
ããè¿ä¸ªæ°çæä¹ å±æ¡æ¶å¯ä»¥è¯´å®å ¨æ¯ä¸ä¸ªæ¿æ²»çäº§ç© EJB Vendorsåºäºèªèº«å©çå对JDO 使å¾JDO没æåæ³æ为J EEçä¸é¨å ç¶èæ åçåè£ä¹æ¯å¤§é¨å人æ´å ä¸å¸æçå°ç äºæ¯æç»JDOæäºæ¿æ²»æäºççºç²å ä»è¡¨é¢ä¸æ¥ç JDOåEJB EntityBeané½å°è¢«æ°çæä¹ å±æ¡æ¶å代 ä¼¼ä¹JDO并没æåäº ä½å®é ä¸JDO æ åå·²ç»æç é¨åJDOé¢å¯¼ååç产åå·²ç»èå§å¾ å è EJB EntityBeanè¿å¤äºEarly Draft çå¾ äº§åè¯çè³å°ä¹æ¯ä¸å¹´ä¹åçäºæ äº å¦å¤å¼å¾è人寻å³çæ¯ æ°çæä¹ å±æ¡æ¶å°åºäºå½åEJB EntityBean åç»åJDO çè§è 并ä¸å°å¤äºEJB EGçæ§å¶ä¹ä¸ åå å ¥ä¸äºJDO EGçæå å æ¤å¯ä»¥çåºæ¥æ°çæä¹ å±æ¡æ¶æ çè¿æ¯ä»¥EJB EG为主导è¿è¡å¶å®ç
ããä»é¿è¿æ¥ç EJB åJDO çæ¿æ²»æäºå¯¹åæ¹é½æå¥½å¤ é¿æåè£å¸¦æ¥çåæ对åæ¹çåå±é½ä¸å© ç¶èä»çææ¥ç JDO ç¡®å®æ¯å¨è¿åºæ¿æ²»æäºä¸è´¥ä¸éµæ¥ æç´æ¥çä½ç°å°±æ¯ å·²ç»æä¸äºJDOçç¨æ·å¯¹JDOçåæ¯äº§çäºå¨æåè¿·è« ä¸å°çJDOç±å¥½è æ´æ¯ç´è¨JDOå°æ»
ããTopLinkæ¯ä¸ä¸ªèçç O/R Mappingè½¯ä»¶äº èªä»è¢«Oracleæ¶è´ä¹å åå¢å äºå¯¹Oracleæ°æ®åºçè¯å¥½æ¯æ å对Oracle AS EntityBeançæ¯æ Oracleæä¾äºTopLinkçå¾å½¢è®¾è®¡ç¯å¢ å¯ä»¥ä½¿å¾è®¾è®¡å¥½çTopLinkå模åæ¢å¯ä»¥è¢«åç¬ç¨å¨TopLink ä¸ ä¹å¯ä»¥è¢«ç¨å¨EJB CMPä¸ å æ¤çæ¥TopLinkä¹èµ°äºä¸æ¡åHibernateåæ ·çç¥çè·¯
ããTopLinkçé®é¢å¨äºç¸æ¯Hibernateçå¼æºåå è´¹çä¼å¿æ¥è¯´ TopLinkæ¢ä¸å¼æº å®ä»·åä¸è²ä¸ æ¬æ¥åä¸è½¯ä»¶TopLinkåºè¯¥å¨ææ¯æ¯æååä¸å®£ä¼ çç¥ä¸æ¥æ足å¤çä¼å¿ ç¶èOracleå ¬å¸æ¯ç«æ¯ä¸ä¸ªä»¥æ°æ®åºä¸ºæ ¸å¿äº§åçå ¬å¸ å ¶ä»çä¸å产åé½æ¯ä¸ºäºæ°æ®åºéå®ä¸ç»©èæå¡ç å¨Oracle产å线ä¸å¤äºä¸ä¸ªä»å±å°ä½çTopLink ç±äºå 天ä¸è¶³ åªè½ç¼ççççHibernateçæ¥ç壮大èæ æä½ä¸º å æ¤ TopLinkæ´å¤ç被å±éå¨è´ä¹°äºOracleæ°æ®åº 并ä¸ç»å®Oracleæ°æ®åºçç¨æ·ç¾¤ä½ä¸
ããJ EE çæ°æä¹ å±è§èå°æ¯«æ æ¬å¿µçæ为æªæ¥æä¹ å±æ¡æ¶ç主æµAPI æ 论æ¯Hibernate JDO è¿æ¯TopLinkç»å°å ¼å®¹è¿ä¸ªä¸»æµåä¸API å¨å½åçè¿ä¸ç§æä¹ å±APIå½ä¸ Hibernateæ çæ¯ææåéç è¿æ¯å 为 æ°çæä¹ å±è§èå°åºäºEJB EntityBeanè§è è¿æå³çä»å°ä»¥Hibernateç设计ç念为åºç¡
ãã JBoss对EJB è§èè·éçæ¥ä¼éå¸¸ç´§å¯ å¨è§èå¶å®è¿ç¨ä¸å°±ä¸æçåå¸åèå®ç°äº§å å æ¤å¯ä»¥å¯¹å¯¹EJB è§è产çæ¯è¾å¤§çå½±åå
ãã综ä¸æè¿° æ们æçç±å¯¹Hibernateçåéæ±æ强ççä¿¡å¿
ããæåçä¸ä¸ªçé®æ¯ æ¢ç¶J EE çæ°æä¹ å±æ¡æ¶å¯ä»¥è±ç¦»J EE容å¨è¿è¡ é£ä¹å¤§å®¶ä¸å ¨é¨é½å»ç¨Hibernateçåä¸å¥å ¼å®¹API èå®å ¨æ¾å¼HibernateçåçAPIäºåï¼é£ä¹æ¯å¦æå³çHibernateå为ä¸ä¸ªç¬ç«äº§åç使å½å½»åºç»ç»å¢ï¼
ãã对äºè¿ä¸ªé®é¢æççæ³æ¯ J EE çæä¹ å±è§èè¦ç»¼åå个EJB Vendor JDO Vendorçæè§ è¦å¹³è¡¡ä»ä»¬ä¹é´çå©çå¾å¤± é£ä¹è¿æ ·ä¸ä¸ªç»å顾åçè§èå¿ ç¶æ æ³è¦çææåºç¨åºåçå ¨é¢éè¦ è¿ä¸åHibernateçåçAPI å¯ä»¥éæ¶æ ¹æ®å¼å人åçè¦æ±å¢å åè½é£ä¹çµæ´» å æ¤æé¢è®¡HibernateçåçAPIä»¥å ¶æ´å 强大çåè½ä»ç¶ä¼å¸å¼ä¸å¤§æ¹äººç´æ¥ä½¿ç¨åçAPI èä¸æ¯å ¼å®¹J EEè§èçAPI
lishixinzhi/Article/program/Java/ky//怎样把JAVA源代码编译exe文件?
你可以下载专门的工具比如:/tools/.html 但是如果你想自己知道怎么做的,可以参考下面文章
源码传奇1.70源码
2024-11-19 08:202239人浏览
2024-11-19 08:20261人浏览
2024-11-19 06:56270人浏览
2024-11-19 06:421027人浏览
2024-11-19 06:201978人浏览
2024-11-19 06:121942人浏览
1.游戏源代码是什么意思?2.源码游戏和组件游戏的区别3.游戏源代码是什么4.游戏源代码什么意思5.游戏源码是什么6.什么是源代码?游戏源代码是什么意思? 游戏源代码是游戏开发者所编写的程序代码,
1.微信小程序和APP有什么区别 微信小程序和App手机软件对比评测2.怎么选择一个手机APP开发公司?3.什么游戏社交软件比较好玩?微信小程序和APP有什么区别 微信小程序和App手机软件对比评测