Java±àÂë¹æ·¶£¨The Elements of Java Style£©
Genaral Principles Ò»°ãÔ¼¶¨
1.Adhere to the style
of the original.
±£³Ö×î³õµÄÑùʽ¡£
2.Adhere to the Principle of Least
Astonishment.
×ñÊØ×îС¾ªÆæÔÔò¡£
3.Do it right the first time.
µÚÒ»´Î¾ÍÓ¦µ±×öºÃ¡£
4.Document any deviations.
¶ÔÓÚÈκα³À붼Ӧµ±Îĵµ×¢ÊÍ¡£
Formatting
Conventions ¸ñʽԼ¶¨
5.Indent nested code.
Ô¼ÊøǶÌ×´úÂë¡£
6.Break up long lines.
²ð·Ö³¤ÐС£
7.Include white space.
°üº¬¿Õ¸ñ¡£
8.Do not use "hard" tabs.
²»ÒªÊ¹ÓÃtab¼ü¡£
Naming
Conventions ÃüÃûÔ¼¶¨
9.Use meaningful names.
ʹÓÃÓÐÒâÒåµÄÃû³Æ¡£
10.Use familiar names.
ʹÓÃÊìϤµÄÃû³Æ¡£
11.Question excessively
long names.
²»ÒªÊ¹Óùý³¤µÄÃû³Æ¡£
12.Join the vowel generation.
¼ÓÈëÔªÒô×Öĸ¡£
13.Capitalize only the first letter in acronyms.
Ö»¶Ô¼ò³ÆµÄµÚÒ»¸ö×Öĸ´óд¡£
14.Do not use names that differ only in case.
²»ÒªÊ¹ÓÃÖ»ÒÀÀµÓÚ´óСдÀ´Çø·ÖµÄÃû³Æ¡£
Package Names °üÃüÃû
15.Use
the reversed, lowercase form of your organization's Internet domain
name as the root qualifier for your package names.
²ÉÓÃÄã×éÖ¯µÄInternetÓòÃû
µÄ·´×ª¡¢Ð¡Ð´ÐÎʽ×÷Ϊ°üÃû³ÆµÄ¸ùÏÞ¶¨´Ê¡£
16.Use a single, lowercase word as the root
name of each package.
ʹÓÃÒ»¸öΨһµÄСдµ¥´Ê×÷Ϊÿ¸ö°üµÄ¸ùÃû³Æ¡£
17.Use the
same name for a new version of a package, but only if that new version
is still binary compatible with the previous versin, otherwise, use a
new name.
Ö»Óе±°üµÄа汾ÈÔÈ»Óë¾É°æ±¾¼æÈÝʱ£¬¶ÔÓÚ°üµÄа汾ʹÓÃÏàͬµÄÃû³Æ£¬·ñÔòʹÓÃÐÂÃû³Æ¡£
Type Names ÀàÐÍÃüÃû
18.Capitalize the first letter of
each word that appears in a class or interface name.
¶ÔÓÚÀàºÍ½Ó¿ÚÃû³ÆÖ»¶Ôÿ¸öµ¥´Ê
µÄµÚÒ»¸ö×Öĸ´óд¡£
Class Names ˈ̟̞
19.Use
nouns when naming classes.
ʹÓÃÃû´ÊÀ´ÃüÃûÀà¡£
20.Pluralize the
names of classes that group related attributes,
Ïà¹ØÎĵµ£º
// ɾ³ýʱ±ØÐëͨ¹ýiterator.remove()À´Ö´ÐУ¬²»ÄÜÖ±½ÓʹÓÃsetµÄremove()À´Ö´ÐУ¬²»È»»á³öÏÖjava.util.ConcurrentModificationExceptionÒì³£
/* Iterator<String> delIter = keySet.iterator();
  ......
java 23ÖÖÉè¼Æģʽ£¬Ò»°ãÇé¿öÏ£¬³£ÓõÄÓÐÄÄЩ?
¹¤³§Ä£Ê½£¬ ¹¤³§·½·¨Ä£Ê½£¬µ¥Àýģʽ£¬ Íâ¹Û£¨Facade£©Ä£Ê½£¬ ¹Û²ìÕߣ¨Observer£©Ä£Ê½£¬ÇŽӣ¨Bridge£©Ä£Ê½¶¼ÊDZȽϳ£Óõģ¬²»Í¬µÄÏîÄ¿Óв»Í¬µÄÉè¼Æ·½Ïò£¬¿ÉÒԲο¼µÄÉè¼ÆģʽҲ²»¾¡Ïàͬ£¬Ã»Óж¨Êý£¬Ö»ÊÇÉÏÃæÕ⼸¸öģʽÓõıȽ϶àһЩ¡£
ÆäËûµÄÄ ......
01¡¢ÈÿؼþµÃµ½½¹µã
ÓÃ.requestFocus();¿ÉÒÔ»ñµÃ¿Ø¼þ½¹µã¡£
nextFocus()Ôò¿É½øÈëÏÂÒ»¸ö½¹µã¡£
02¡¢½«StringÀàÐÍתΪintÀàÐÍ
Integer.parseInt(String);
03¡¢½«IntegerÀàÐÍתΪStringÀàÐÍ
String.valueOf(Integer); ......
·½·¨Ò»£ºÖ»¼ÓÃÜ
import java.security.*;
import java.security.spec.*;
class MD5_test {
public final static String MD5(String s) {
char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
&n ......
ÒÔÏÂÄÚÈÝÕª×Ôjavaº¯ÊýµÄ²ÎÊý´«µÝºÍStringÀàÐÍ http://www.blogjava.net/thuixy/archive/2009/06/06/280302.html
˵ÍêÁËjavaµÄStringÀàÐÍ£¬ÎÒÃÇ×îºó¿´¿´javaº¯Êý²ÎÊýµÄ´«µÝ£¬µ½µ×ÊÇÖµ´«µÝ»¹ÊÇÒýÓô«µÝÄØ£¿Ò»°ãµÄ˵·¨ÊǶÔÓÚ»ù±¾ÀàÐͱÈÈçint¡¢charÊÇÖµ´«µÝ£¬¶ÔÓÚ¶ÔÏóÀàÐÍÊÇÒýÓô«µÝ¡£ÕâÖÖ˵·¨Ã»´í£¬µ«ÊÇÇë¿´ÏÂÃæµÄÀý×Ó£º
Str ......