---
title: "Code Conventions for the Java TM Programming Language "
author: "joyo_fly"
date: "2011-03-28T10:02:55Z"
tags: []
categories: ["编程语言"]
slug: "code-conventions-for-the-java-tm-programming-language"
draft: false
lastmod: "2011-03-28T10:02:55Z"
id: 977064
url: "https://joyo-fly.iteye.com/blog/977064"
---

[http://www.oracle.com/technetwork/java/codeconvtoc-136057.html](http://www.oracle.com/technetwork/java/codeconvtoc-136057.html)

[**1**](http://joyo-fly.iteye.com/technetwork/java/codeconventions-139411.html) [Introduction](http://joyo-fly.iteye.com/technetwork/java/codeconventions-139411.html#16711)

**1.1 [Why Have Code Conventions](http://joyo-fly.iteye.com/technetwork/java/codeconventions-139411.html#16712)**

**1.2 [Acknowledgments](http://joyo-fly.iteye.com/technetwork/java/codeconventions-139411.html#16729)**

[**2**](http://joyo-fly.iteye.com/technetwork/java/codeconventions-137760.html) [File Names](http://joyo-fly.iteye.com/technetwork/java/codeconventions-137760.html#16732)

**2.1 [File Suffixes](http://joyo-fly.iteye.com/technetwork/java/codeconventions-137760.html#647)**

**2.2 [Common File Names](http://joyo-fly.iteye.com/technetwork/java/codeconventions-137760.html#253)**

[**3**](http://joyo-fly.iteye.com/technetwork/java/codeconventions-141855.html) [File Organization](http://joyo-fly.iteye.com/technetwork/java/codeconventions-141855.html#3043)

**3.1 [Java Source Files](http://joyo-fly.iteye.com/technetwork/java/codeconventions-141855.html#11684)**

**3.1.1 [Beginning Comments](http://joyo-fly.iteye.com/technetwork/java/codeconventions-141855.html#3441)**

**3.1.2 [Package and Import Statements](http://joyo-fly.iteye.com/technetwork/java/codeconventions-141855.html#277)**

**3.1.3 [Class and Interface Declarations](http://joyo-fly.iteye.com/technetwork/java/codeconventions-141855.html#1852)**

[**4**](http://joyo-fly.iteye.com/technetwork/java/codeconventions-136091.html) [Indentation](http://joyo-fly.iteye.com/technetwork/java/codeconventions-136091.html#262)

**4.1 [Line Length](http://joyo-fly.iteye.com/technetwork/java/codeconventions-136091.html#313)**

**4.2 [Wrapping Lines](http://joyo-fly.iteye.com/technetwork/java/codeconventions-136091.html#248)**

[**5**](http://joyo-fly.iteye.com/technetwork/java/codeconventions-141999.html) [Comments](http://joyo-fly.iteye.com/technetwork/java/codeconventions-141999.html#385)

**5.1 [Implementation Comment Formats](http://joyo-fly.iteye.com/technetwork/java/codeconventions-141999.html#216)**

**5.1.1 [Block Comments](http://joyo-fly.iteye.com/technetwork/java/codeconventions-141999.html#680)**

**5.1.2 [Single-Line Comments](http://joyo-fly.iteye.com/technetwork/java/codeconventions-141999.html#341)**

**5.1.3 [Trailing Comments](http://joyo-fly.iteye.com/technetwork/java/codeconventions-141999.html#342)**

**5.1.4 [End-Of-Line Comments](http://joyo-fly.iteye.com/technetwork/java/codeconventions-141999.html#286)**

**5.2 [Documentation Comments](http://joyo-fly.iteye.com/technetwork/java/codeconventions-141999.html#16838)**

[**6**](http://joyo-fly.iteye.com/technetwork/java/codeconventions-141270.html) [Declarations](http://joyo-fly.iteye.com/technetwork/java/codeconventions-141270.html#2991)

**6.1 [Number Per Line](http://joyo-fly.iteye.com/technetwork/java/codeconventions-141270.html#2992)**

**6.2 [Initialization](http://joyo-fly.iteye.com/technetwork/java/codeconventions-141270.html#18761)**

**6.3 [Placement](http://joyo-fly.iteye.com/technetwork/java/codeconventions-141270.html#16817)**

**6.4 [Class and Interface Declarations](http://joyo-fly.iteye.com/technetwork/java/codeconventions-141270.html#381)**

[**7**](http://joyo-fly.iteye.com/technetwork/java/codeconventions-142311.html) [Statements](http://joyo-fly.iteye.com/technetwork/java/codeconventions-142311.html#430)

**7.1 [Simple Statements](http://joyo-fly.iteye.com/technetwork/java/codeconventions-142311.html#431)**

**7.2 [Compound Statements](http://joyo-fly.iteye.com/technetwork/java/codeconventions-142311.html#15395)**

**7.3 [return Statements](http://joyo-fly.iteye.com/technetwork/java/codeconventions-142311.html#438)**

**7.4 [if, if-else, if else-if else Statements](http://joyo-fly.iteye.com/technetwork/java/codeconventions-142311.html#449)**

**7.5 [for Statements](http://joyo-fly.iteye.com/technetwork/java/codeconventions-142311.html#454)**

**7.6 [while Statements](http://joyo-fly.iteye.com/technetwork/java/codeconventions-142311.html#460)**

**7.7 [do-while Statements](http://joyo-fly.iteye.com/technetwork/java/codeconventions-142311.html#465)**

**7.8 [switch Statements](http://joyo-fly.iteye.com/technetwork/java/codeconventions-142311.html#468)**

**7.9 [try-catch Statements](http://joyo-fly.iteye.com/technetwork/java/codeconventions-142311.html#472)**

[**8**](http://joyo-fly.iteye.com/technetwork/java/codeconventions-141388.html) [White Space](http://joyo-fly.iteye.com/technetwork/java/codeconventions-141388.html#475)

**8.1 [Blank Lines](http://joyo-fly.iteye.com/technetwork/java/codeconventions-141388.html#487)**

**8.2 [Blank Spaces](http://joyo-fly.iteye.com/technetwork/java/codeconventions-141388.html#682)**

[**9**](http://joyo-fly.iteye.com/technetwork/java/codeconventions-135099.html) [Naming Conventions](http://joyo-fly.iteye.com/technetwork/java/codeconventions-135099.html#367)

[**10**](http://joyo-fly.iteye.com/technetwork/java/codeconventions-137265.html) [Programming Practices](http://joyo-fly.iteye.com/technetwork/java/codeconventions-137265.html#529)

**10.1 [Providing Access to Instance and Class Variables](http://joyo-fly.iteye.com/technetwork/java/codeconventions-137265.html#177)**

**10.2 [Referring to Class Variables and Methods](http://joyo-fly.iteye.com/technetwork/java/codeconventions-137265.html#587)**

**10.3 [Constants](http://joyo-fly.iteye.com/technetwork/java/codeconventions-137265.html#1255)**

**10.4 [Variable Assignments](http://joyo-fly.iteye.com/technetwork/java/codeconventions-137265.html#547)**

**10.5 [Miscellaneous Practices](http://joyo-fly.iteye.com/technetwork/java/codeconventions-137265.html#554)**

**10.5.1 [Parentheses](http://joyo-fly.iteye.com/technetwork/java/codeconventions-137265.html#331)**

**10.5.2 [Returning Values](http://joyo-fly.iteye.com/technetwork/java/codeconventions-137265.html#333)**

**10.5.3 [Expressions before \`?' in the Conditional Operator](http://joyo-fly.iteye.com/technetwork/java/codeconventions-137265.html#353)**

**10.5.4 [Special Comments](http://joyo-fly.iteye.com/technetwork/java/codeconventions-137265.html#395)**

[**11**](http://joyo-fly.iteye.com/technetwork/java/codeconventions-137946.html) [Code Examples](http://joyo-fly.iteye.com/technetwork/java/codeconventions-137946.html#186)

**11.1 [Java Source File Example](http://joyo-fly.iteye.com/technetwork/java/codeconventions-137946.html#182)**