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,
Ïà¹ØÎĵµ£º
¶ÔÓÚÕâ¸öϵÁÐÀïµÄÎÊÌ⣬ÿ¸öѧJavaµÄÈ˶¼Ó¦¸Ã¸ã¶®¡£µ±È»£¬Èç¹ûÖ»ÊÇѧJavaÍæÍæ¾ÍÎÞËùνÁË¡£Èç¹ûÄãÈÏΪ×Ô¼ºÒѾ³¬Ô½³õѧÕßÁË£¬È´²»ºÜ¶®ÕâЩÎÊÌ⣬Ç뽫Äã×Ô¼ºÖعé³õѧÕßÐÐÁС£ÄÚÈݾùÀ´×ÔÓÚCSDNµÄ¾µäÀÏÌù¡£Èç¹û´ó¼Ò¸Ð¾õÔÚ»ù´¡Ñ§Ï°×Ô¼º±¡ÈõµÄÒ²¿ÉÒÔÄdzöÀ´¹²Ïí,¹²Í¬Ñ§Ï°.
&nb ......
System.currentTimeMillis()£º¿ÉÒÔÌáÈ¡µ½µ±Ç°Ê±¼äµÄºÁÃëÊý£¬²úÉúÒ»¸öµ±Ç°µÄºÁÃ룬Õâ¸öºÁÃëÆäʵ¾ÍÊÇ×Ô1970Äê1ÔÂ1ÈÕ0ʱÆðµÄºÁÃëÊý¡£
³£¼û×÷ÓãºÒ»°ã¶¼ÊÇÓÃ2¸öʱ¼äµÄ²îÖµÀ´µÃµ½ÔËÐÐʱ¼äµÄ£¬³£ÓÃÀ´±È½Ï2¸öËã·¨µÄЧÂÊ£¡
long start = System.currentTimeMillis();
// ÕâÀï¿ÉÒÔ¼ÓÉÏÄãÒªÖªµÀµÄ·½·¨ÔËÐеÄʱ¼ä£¡£¡
......
Executing a CommandSee also e90 Reading Output from a Command.
try {
// Execute a command without arguments
String command = "ls";
Process child = Runtime.getRuntime().exec(command);
// Execute a command with an argument
command = "ls /tmp"; ......
½øÒ»·¨£º ¼´Ê¡ÂÔµÄλÉÏÖ»Òª´óÓÚÁ㶼Ҫ½øһλ £»
ËÄÉáÎåÈë·¨£º ¼´Ê¡ÂÔµÄλÉÏСÓÚÎ嶼ҪÉáÈ¥£¬µ«Ê¡ÂÔµÄλÉÏÂúÎ嶼Ҫ½øһλ £»
»¹ÓÐÒ»ÖÖ
ȥβ·¨£º ¼´Ê¡ÂÔµÄλÉϲ»¹ÜÊÇ·ñÂúÎ嶼ҪÉáÈ¥ £»
1¡¢³ý·¨´øСÊý
ÀýÈ磺
int a = 8;
int b = 3;
int c = ((double)la)/b;
System.out.println(c); ......
Ãô½Ý¿ª·¢µÄÀíÄîÒѾÁ÷ÐÐÁ˺ܳ¤µÄʱ¼ä£¬ÔÚÃô½Ý¿ª·¢ÖеĿª·¢µü´ú½×¶ÎÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ýÎå¸ö²½Ö裬À´ÓÐЧµÄÌá¸ßÕû¸öÏîÄ¿µÄ´úÂëÖÊÁ¿¡£
JavaÏîÄ¿¿ª·¢¹ý³ÌÖУ¬ÓÉÓÚ¿ª·¢ÈËÔ±µÄ¾Ñé¡¢Java´úÂë±àдϰ¹ß£¬ÒÔ¼°È±·¦Í³Ò»µÄ±ê×¼ºÍ¹ÜÀíÁ÷³Ì£¬ÍùÍùµ¼ÖÂÕû¸öÏîÄ¿µÄ´úÂëÖÊÁ¿½Ï²î£¬ÄÑÓÚά
»¤£¬ÐèÒª½Ï´óµÄ²âÊÔͶÈëºÍÖÜÆÚµÈÎÊÌâ¡£ÕâЩÎÊÌâÔÚÒ»¸ ......