java±àÂë¹æ·¶_Ëõ½øºÍ×¢ÊÍ
1. Ëõ½øÅÅ°æ(Indentation)
4¸ö¿Õ¸ñ³£±»×÷ΪËõ½øÅÅ°æµÄÒ»¸öµ¥Î»¡£Ëõ½øµÄÈ·ÇнâÊͲ¢Î´Ïêϸָ¶¨(¿Õ¸ñ vs. ÖƱí·û)¡£Ò»¸öÖƱí·ûµÈÓÚn¸ö¿Õ¸ñ(ÊÓ¾ßÌåµÄ±à¼Æ÷¶ø¶¨£¬EclipseĬÈÏÒ»¸öÖƱí·ûΪ4¸ö×Ö·û)¡£
3.1 Ð㤶È(Line Length)
¾¡Á¿±ÜÃâÒ»Ðеij¤¶È³¬¹ý80¸ö×Ö·û£¬ÒòΪºÜ¶àÖն˺͹¤¾ß²»Äܺܺô¦ÀíÖ®¡£
×¢Ò⣺¼øÓÚEclipse¿ª·¢¹¤¾ß¹¤×÷ÇøµÄ×ó²àºÍÓҲ඼±»·Ç´úÂë±à¼Æ÷ËùÕ¼¾Ý£¬Òò´Ë½¨ÒéÿÐеĴúÂ볤¶È²»Òª³¬¹ý70¸ö×Ö·û¡£
3.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; //ÍƼöʹÓÃ
longName1 = longName2 * ( longName3 + longName4
- longName5 ) + 4 * longname6; //Ó¦±ÜÃâÕâÑùʹÓÃ
ÒÔÏÂÊÇÁ½¸öËõ½ø·½·¨ÉùÃ÷µÄÀý×Ó¡£Ç°ÕßÊdz£¹æÇéÐΡ£ºóÕßÈôʹÓó£¹æµÄËõ½ø·½Ê½½«»áʹµÚ¶þÐк͵ÚÈýÐÐÒƵúܿ¿ÓÒ£¬ËùÒÔ´úÖ®ÒÔËõ½ø¿Õ¸ñ£¬¾¡Á¿ÓëÔËËã·û»òÕßÀ¨ºÅ¶ÔÆë¡£
//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¸ö¿Õ¸ñ)»áʹÓï¾äÌå¿´Æð
Ïà¹ØÎĵµ£º
Java ¶àÏ̱߳à³ÌÖ®Áù£ºÏß³ÌÖ®¼äµÄͨÐÅ£¨¸½Ô´´úÂ룩
Ô´´úÂëÏÂÔØ
¶àÏ̱߳à³ÌÖУ¬Ïß³ÌÖ®¼äµÄͨÐÅÊÇÒ»¸ö±È½Ï¸´ÔÓµÄÎÊÌâ¡£´ó¼ÒÍùÍù¸ã²»¶®Ê²Ã´ÊǾºÕù×ÊÔ´£¿Ê²Ã´Ê±ºò¿¼ÂÇͬ²½£¿Ôõô½øÐÐͬ²½£¿Ê²Ã´ÊÇÏß³ÌͨÐÅ£¿Ôõô½øÐÐͨÐÅ£¿ºÜ
¶àÅóÓÑÃæÊÔµÄʱºò¶¼Óöµ½¹ýÕâÑùÀàËƵÄÒ»¸ö±à³ÌÌ⣺¸ø¶ ......
/************************************************
MD5 Ëã·¨µÄJava Bean
*************************************************/
package beartool;
import java.lang.reflect.*;
public class MD5 {
/* ÏÂÃæÕâЩS11-S44ʵ¼ÊÉÏÊÇÒ»¸ö4*4µÄ¾ ......
Java ¶àÏ̱߳à³ÌÖ®ÆߣºËÀËø£¨¸½Ô´´úÂ룩
Ô´´úÂëÏÂÔØ
¶àÏ̱߳à³ÌÖУ¬Ïß³ÌËÀËøÒ²ÊÇÒ»¸ö±È½ÏÓÐȤµÄÎÊÌ⡣Ȼ¶øËÀËø·¢ÉúµÄ¿ÉÄÜÐÔºÜС£¬ÕýÒòÈç´Ë£¬´ó¼Ò¿ÉÄܶԴ˲»ÊǺÜÊìϤ¡£µ«ÊÇËÀËø²¢²»ÊDz»ÖØÒª£¬ÒòΪËüȷȷʵʵ´æÔÚ×Å£¬Ëæʱ»á³öÏÖÔÚÎÒÃǵijÌÐòÖ®ÖС£ºÜ¶àÅóÓÑÃæÊÔµÄʱºò¶¼Óöµ½¹ýÕâ ......
Äú²éѯµÄ¹Ø¼ü´ÊÊÇ£ºnewinstance object initargs ¡£Èç¹û´ò¿ªËÙ¶ÈÂý£¬¿ÉÒÔ³¢ÊÔ¿ìËٰ棻Èç¹ûÏë±£´æ¿ìÕÕ£¬¿ÉÒÔÌí¼Óµ½ËѲء£
(°Ù¶ÈºÍÍøÒ³http://bbs.iaiai.com/forum/read.php?tid=2690µÄ×÷ÕßÎ޹أ¬²»¶ÔÆäÄÚÈݸºÔ𡣰ٶȿìÕÕ½÷ΪÍøÂç¹ÊÕÏʱ֮Ë÷Òý£¬²»´ú±í±»ËÑË÷ÍøÕ¾µÄ¼´Ê±Ò³Ãæ¡£)
Ö÷Ìâ : javaµÄ·´Éä ......
ºÜ¶àÈ˶¼ÖªµÀÔÚswingÖмÓÈëjPopupMenu×é¼þºó¿ÉÒÔÔÚÊó±êµÄÇý¶¯ÏÂ̽³öÒ»¸ö²Ëµ¥£¬µ«ÊÇ£¬Èç¹ûÓÃÒ»°ã×ö·¨£¬ÔÚ½çÃæÉϵ¥»÷×ó¼üÒ²»áµ¯³ö²Ëµ¥£¬ÄÇôÓÐûÓа취ÔÚÖ»Óе¥»÷ÓÒ¼ü²Åµ¯³ö²Ëµ¥ÄØ£¿ÆäʵֻÊÇÓõ½ÁËÒ»¸öС¼¼ÇÉ¡£ ÄãµÄµ¯³öÊó±ê²Ëµ¥Êó±êÇý¶¯Ñ¡Ôñ MouseReleased È»ºóÔÙÔÚ¼àÌýʼþµÄ·½·¨ÖмÓÈëÏÂÃæµÄ´úÂë¾Í¿ÉÒÔÁË£º if(evt.isPop ......