java7 package guide翻译---第一章

CHAPTER 1----Naming Conventions

Naming conventions are used to make Java programs more read‐ able. It is important to use meaningful and unambiguous names comprised of Java letters.

使用命名约定可以使java程序变得更具可读性。使用有意义且不模棱两可的名字是很重要的。

Class Names

类的命名

Class names should be nouns, as they represent “things” or “objects.” They should be mixed case (camel case) with only the first letter of each word capitalized, as in the following:

类的名字应该是名词形式的,因为它代表着事物对象。使用混合命名(驼峰式大小写),也就是说每个单词的首字母应该大写。如下所示:

public class Fish {...}

Interface Names

接口的命名

Interface names should be adjectives. They should end with “able” or “ible” whenever the interface provides a capability; otherwise, they should be nouns. Interface names follow the same capitali‐ zation convention as class names:

接口,当接口提供了某个功能时,接口应该命名为形容词形式,并以ableible结尾。否则则命名为名词形式,且与名词的命名规则相同。

public interface Serializable {...} public interface SystemPanel {...}

Method Names

方法的命名

Method names should contain a verb, as they are used to make an object take action. They should be mixed case, beginning with a lowercase letter, and the first letter of each subsequent word should be capitalized. Adjectives and nouns may be included in method names:

方法名应该包含一个动词,毕竟他们会对一个对象发生一个动作。它是混合命名的,以小写字母开头,之后的每个词的首字母都应该是大写的。方法的名字中也会包含形容词和名词:

public void locate() {...} // verb public String getWayPoint() {...} // verb and noun

Instance and Static Variable Names

实例与静态变量的命名

Instance variable names should be nouns and should follow the same capitalization convention as method names:

实例变量的名字是名词形式的,和方法的命名规范相同:

private String wayPoint;

Parameter and Local Variable Names

参数和本地变量的命名

Parameter and local variable names should be descriptive lowercase single words, acronyms, or abbreviations. If multiple words are necessary, they should follow the same capitalization convention as method names:

参数和本地变量的名字应该是具有叙述性的、小写的且是单独的一个词,首字母缩略词或缩略词。如果想要写成混合单词的话,可以参考方法的大写命名方式:

public void printHotSpots(ArrayList spotList) { int counter = 0; for (String hotSpot : spotList) { System.out.println("Hot Spot #" + ++counter + ": " + hotSpot); } }

Temporary variable names may be single letters such as i, j, k, m, and n for integers and c, d, and e for characters.

临时变量可以是单独的字母,像可以使用i,j,k,mn来命名整数,用c,de之类的字母来表示字符。

Generic Type Parameter Names

泛型参数的命名

Generic type parameter names should be uppercase single letters. The letter T for type is typically recommended.

泛型参数应该是大写的单独字母,强烈建议使用T来表示类型。

The Collections Framework makes extensive use of generics. E is used for collection elements, S is used for service loaders, and K and V are used for map keys and values:

集合框架大量使用了泛型,E用来表示集合元素,S用来表示service loaders,KV用来表示map的键和值。

public interface Map { V put(K key, V value); }

Constant Names

常量的命名

Constant names should be all uppercase letters, and multiple words should be separated by underscores:

常量全部是大写字母,不同的单词之间通过下划线分隔开:

public static final int MAX_DEPTH = 200;

Enumeration Names

枚举的命名

Enumeration names should follow the conventions of class names. The enumeration set of objects (choices) should be all uppercase letters:

枚举的命名应该遵循类命名的规范。而枚举集合里的对象应该是全部大写的:

enum Battery {CRITICAL, LOW, CHARGED, FULL}

Package Names

包的命名

Package names should be unique and consist of lowercase letters. Underscores may be used if necessary:

包名应该是独一无二的且由小写字母构成,必要的话也可使用下划线:

package com.oreilly.fish_finder;

Publicly available packages should be the reversed Internet do‐ main name of the organization, beginning with a single-word top-level domain name (e.g., com, net, org, or edu), followed by the name of the organization and the project or division. (Internal packages are typically named according to the project.)

Package names that begin with java and javax are restricted and can be used only to provide conforming implementations to the Java class libraries.

javajavax开头的包名是被限制使用的,而且只能

Acronyms

首字母缩略词

When using acronyms in names, only the first letter of the acronym should be uppercase and only when uppercase is appropriate:

当在名字中使用首字母缩略词时,首字母缩略词只有首字母是大写,且要确保大写是合适的:

public String getGpsVersion() {...}

你可能感兴趣的:(java7,package,翻译,guide)