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,
Ïà¹ØÎĵµ£º
cd /usr/lib/jvm/java
-1.5.0-sun-1.5.0.15/jre/lib/fonts
sudo mkdir fallback
cd fallback
sudo cp /usr/share/fonts/truetype/arphic/uming.ttc /usr/lib/jvm/java
-1.5.0-sun-1.5.0.15/jre/lib/fonts/fallback
sudo mkfontdir
sudo mkfontscale ......
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"; ......
package com.lovo.cq.shopping10_1.common;
import java.sql.*;
public class DbUtil {
private PreparedStatement pstmt = null;
private Connection con = null;
public DbUtil() {
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://l ......
½øÒ»·¨£º ¼´Ê¡ÂÔµÄλÉÏÖ»Òª´óÓÚÁã¶¼Òª½øÒ»Î» £»
ËÄÉáÎåÈë·¨£º ¼´Ê¡ÂÔµÄλÉÏСÓÚÎå¶¼ÒªÉáÈ¥£¬µ«Ê¡ÂÔµÄλÉÏÂúÎå¶¼Òª½øÒ»Î» £»
»¹ÓÐÒ»ÖÖ
ȥβ·¨£º ¼´Ê¡ÂÔµÄλÉϲ»¹ÜÊÇ·ñÂúÎå¶¼ÒªÉáÈ¥ £»
1¡¢³ý·¨´øÐ¡Êý
ÀýÈ磺
int a = 8;
int b = 3;
int c = ((double)la)/b;
System.out.println(c); ......
Ãô½Ý¿ª·¢µÄÀíÄîÒѾÁ÷ÐÐÁ˺ܳ¤µÄʱ¼ä£¬ÔÚÃô½Ý¿ª·¢ÖеĿª·¢µü´ú½×¶ÎÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ýÎå¸ö²½Ö裬À´ÓÐЧµÄÌá¸ßÕû¸öÏîÄ¿µÄ´úÂëÖÊÁ¿¡£
JavaÏîÄ¿¿ª·¢¹ý³ÌÖУ¬ÓÉÓÚ¿ª·¢ÈËÔ±µÄ¾Ñé¡¢Java´úÂë±àдϰ¹ß£¬ÒÔ¼°È±·¦Í³Ò»µÄ±ê×¼ºÍ¹ÜÀíÁ÷³Ì£¬ÍùÍùµ¼ÖÂÕû¸öÏîÄ¿µÄ´úÂëÖÊÁ¿½Ï²î£¬ÄÑÓÚά
»¤£¬ÐèÒª½Ï´óµÄ²âÊÔͶÈëºÍÖÜÆÚµÈÎÊÌâ¡£ÕâЩÎÊÌâÔÚÒ»¸ ......