新增章节 1_1 和 1_2

+YUCHENG HU+

git-svn-id: https://svn.code.sf.net/p/hawebs/svn@504 a2543c7e-f6e9-4f8a-8bff-1ffc34733512
This commit is contained in:
YuCheng Hu
2010-07-15 02:53:23 +00:00
parent f167b51caf
commit 3bdc5de232
9 changed files with 361 additions and 11 deletions
@@ -1,10 +1,10 @@
#Wed Jul 14 21:06:16 EDT 2010
#Wed Jul 14 22:52:34 EDT 2010
copytosourcelist=
hreftargetslist=tasks/info/hacopyright.dita,tasks/info/apachelicense.dita,tasks/chapter1/chapter1.dita
hreftargetslist=tasks/info/hacopyright.dita,tasks/info/apachelicense.dita,tasks/chapter1/chapter1.dita,tasks/chapter1/chapter1_2.dita,tasks/chapter1/chapter1_1.dita
fullditatopicfile=fullditatopic.list
fullditamapandtopicfile=fullditamapandtopic.list
fullditatopiclist=tasks/info/hacopyright.dita,tasks/info/apachelicense.dita,tasks/chapter1/chapter1.dita
fullditamapandtopiclist=tasks/info/hacopyright.dita,tasks/info/apachelicense.dita,tasks/chapter1/chapter1.dita,code_conventions.ditamap
fullditatopiclist=tasks/info/hacopyright.dita,tasks/info/apachelicense.dita,tasks/chapter1/chapter1.dita,tasks/chapter1/chapter1_2.dita,tasks/chapter1/chapter1_1.dita
fullditamapandtopiclist=tasks/info/hacopyright.dita,tasks/info/apachelicense.dita,tasks/chapter1/chapter1.dita,tasks/chapter1/chapter1_2.dita,code_conventions.ditamap,tasks/chapter1/chapter1_1.dita
hrefditatopicfile=hrefditatopic.list
hrefditatopiclist=tasks/info/hacopyright.dita,tasks/chapter1/chapter1.dita
user.input.file=code_conventions.ditamap
@@ -27,7 +27,7 @@ imagelist=images/halogo.jpg
htmlfile=html.list
htmllist=
canditopicsfile=canditopics.list
canditopicslist=tasks/info/hacopyright.dita,tasks/info/apachelicense.dita,tasks/chapter1/chapter1.dita
canditopicslist=tasks/info/hacopyright.dita,tasks/info/apachelicense.dita,tasks/chapter1/chapter1.dita,tasks/chapter1/chapter1_2.dita,tasks/chapter1/chapter1_1.dita
keyreffile=keyref.list
subjectschemefile=subjectscheme.list
keyreflist=
@@ -3,11 +3,11 @@
SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<entry key="copytosourcelist"></entry>
<entry key="hreftargetslist">tasks/info/hacopyright.dita,tasks/info/apachelicense.dita,tasks/chapter1/chapter1.dita</entry>
<entry key="hreftargetslist">tasks/info/hacopyright.dita,tasks/info/apachelicense.dita,tasks/chapter1/chapter1.dita,tasks/chapter1/chapter1_2.dita,tasks/chapter1/chapter1_1.dita</entry>
<entry key="fullditatopicfile">fullditatopic.list</entry>
<entry key="fullditamapandtopicfile">fullditamapandtopic.list</entry>
<entry key="fullditatopiclist">tasks/info/hacopyright.dita,tasks/info/apachelicense.dita,tasks/chapter1/chapter1.dita</entry>
<entry key="fullditamapandtopiclist">tasks/info/hacopyright.dita,tasks/info/apachelicense.dita,tasks/chapter1/chapter1.dita,code_conventions.ditamap</entry>
<entry key="fullditatopiclist">tasks/info/hacopyright.dita,tasks/info/apachelicense.dita,tasks/chapter1/chapter1.dita,tasks/chapter1/chapter1_2.dita,tasks/chapter1/chapter1_1.dita</entry>
<entry key="fullditamapandtopiclist">tasks/info/hacopyright.dita,tasks/info/apachelicense.dita,tasks/chapter1/chapter1.dita,tasks/chapter1/chapter1_2.dita,code_conventions.ditamap,tasks/chapter1/chapter1_1.dita</entry>
<entry key="hrefditatopicfile">hrefditatopic.list</entry>
<entry key="hrefditatopiclist">tasks/info/hacopyright.dita,tasks/chapter1/chapter1.dita</entry>
<entry key="user.input.file">code_conventions.ditamap</entry>
@@ -30,7 +30,7 @@
<entry key="htmlfile">html.list</entry>
<entry key="htmllist"></entry>
<entry key="canditopicsfile">canditopics.list</entry>
<entry key="canditopicslist">tasks/info/hacopyright.dita,tasks/info/apachelicense.dita,tasks/chapter1/chapter1.dita</entry>
<entry key="canditopicslist">tasks/info/hacopyright.dita,tasks/info/apachelicense.dita,tasks/chapter1/chapter1.dita,tasks/chapter1/chapter1_2.dita,tasks/chapter1/chapter1_1.dita</entry>
<entry key="keyreffile">keyref.list</entry>
<entry key="subjectschemefile">subjectscheme.list</entry>
<entry key="keyreflist"></entry>
@@ -10,6 +10,8 @@
<meta name="description" content="主要对为什么要进行编码规范和如何进行编码规范进行说明"/>
<meta name="DC.subject" content="Java, 编码规范"/>
<meta name="keywords" content="Java, 编码规范"/>
<meta name="DC.Relation" scheme="URI" content="../../tasks/chapter1/chapter1_1.html"/>
<meta name="DC.Relation" scheme="URI" content="../../tasks/chapter1/chapter1_2.html"/>
<meta name="prodname" content="Java 编码规范"/>
<meta name="version" content="1.0.0.0"/>
<meta name="brand" content="HAWEBS ZEN Java 编码规范"/>
@@ -50,6 +52,14 @@
</div>
<div>
<ul class="ullinks">
<li class="ulchildlink"><strong><a href="../../tasks/chapter1/chapter1_1.html">程序编写规范</a></strong><br/>
</li>
<li class="ulchildlink"><strong><a href="../../tasks/chapter1/chapter1_2.html">排版规范</a></strong><br/>
</li>
</ul>
</div>
</body>
</html>
@@ -0,0 +1,115 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="zh" xml:lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="DC.Type" content="concept"/>
<meta name="DC.Title" content="程序编写规范"/>
<meta name="DC.subject" content="Java, 编码规范"/>
<meta name="keywords" content="Java, 编码规范"/>
<meta name="DC.Relation" scheme="URI" content="../../tasks/chapter1/chapter1.html"/>
<meta name="prodname" content="Java 编码规范"/>
<meta name="version" content="1.0.0.0"/>
<meta name="brand" content="HAWEBS ZEN Java 编码规范"/>
<meta name="copyright" content="HAWEBS信息技术股份有限公司 2006, 2010" type="primary"/>
<meta name="DC.Rights.Owner" content="HAWEBS信息技术股份有限公司 2006, 2010" type="primary"/>
<meta name="DC.Format" content="XHTML"/>
<meta name="DC.Identifier" content="chapter1_1"/>
<meta name="DC.Language" content="zh"/>
<link rel="stylesheet" type="text/css" href="../../css/commonltr.css"/>
<link rel="stylesheet" type="text/css" href="../../css/public.css"/>
<title>程序编写规范</title>
</head>
<body id="chapter1_1"><a name="chapter1_1"><!-- --></a>
<h1 class="topictitle1">程序编写规范</h1>
<div>
<div class="p"><ul>
<li>
<p>exit()</p>
<p>exit 除了在 main 中可以被调用外,其他的地方不应该调用。因为这样做不给任何代码代码机会来截获退出。一个类似后台服务地程序不应该因为某一个库模块决定了要退出就退出。</p>
</li>
<li>
<p>异常</p>
<p>申明的错误应该抛出一个RuntimeException或者派生的异常。顶层的main()函数应该截获所有的异常,并且打印(或者记录在日志中)在屏幕上。</p>
</li>
<li>
<p>垃圾收集</p>
<p>JAVA使用成熟的后台垃圾收集技术来代替引用计数。但是这样会导致一个问题:你必须在使用完对象的实例以后进行清场工作。除非输出流一出作用域就关闭,非引用计数的程序语言,比如JAVA,是不能自动完成变量的清场工作的。必须象下面一样写:</p>
<div class="p"><pre class="codeblock">FileOutputStream fos = new FileOutputStream(projectFile);
project.save(fos, "IDE Project File");
fos.close();</pre>
</div>
</li>
<li>
<p>Clone</p>
<p>下面是一种有用的方法:</p>
<div class="p"><pre class="codeblock">implements Cloneable
public
Object clone()
{
try {
ThisClass obj = (ThisClass)super.clone();
obj.field1 = (int[])field1.clone();
obj.field2 = field2;
return obj;
} catch(CloneNotSupportedException e) {
throw new InternalError("Unexpected CloneNotSUpportedException: " + e.getMessage());
}
}</pre>
</div>
</li>
<li>
<p>final 类</p>
<p>绝对不要因为性能的原因将类定义为 final 的(除非程序的框架要求)。如果一个类还没有准备好被继承,最好在类文档中注明,而不要将她定义为 final 的。这是因为没有人可以保证会不会由于什么原因需要继承她。</p>
</li>
<li>
<p>访问类的成员变量</p>
<p>大部分的类成员变量应该定义为 protected 的来防止继承类使用他们。注意,要用"int[] packets",而不是"int packets[]",后一种永远也不要用。</p>
<div class="p"><pre class="codeblock">public void setPackets(int[] packets) { this.packets = packets; }
CounterSet(int size)
{
this.size = size;
}</pre>
</div>
</li>
</ul>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>父主题:</strong> <a href="../../tasks/chapter1/chapter1.html" title="主要对为什么要进行编码规范和如何进行编码规范进行说明">Java 编码规范</a></div>
</div>
</div>
</body>
</html>
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="zh" xml:lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="DC.Type" content="concept"/>
<meta name="DC.Title" content="排版规范"/>
<meta name="DC.subject" content="Java, 编码规范"/>
<meta name="keywords" content="Java, 编码规范"/>
<meta name="DC.Relation" scheme="URI" content="../../tasks/chapter1/chapter1.html"/>
<meta name="prodname" content="Java 编码规范"/>
<meta name="version" content="1.0.0.0"/>
<meta name="brand" content="HAWEBS ZEN Java 编码规范"/>
<meta name="copyright" content="HAWEBS信息技术股份有限公司 2006, 2010" type="primary"/>
<meta name="DC.Rights.Owner" content="HAWEBS信息技术股份有限公司 2006, 2010" type="primary"/>
<meta name="DC.Format" content="XHTML"/>
<meta name="DC.Identifier" content="chapter1_2"/>
<meta name="DC.Language" content="zh"/>
<link rel="stylesheet" type="text/css" href="../../css/commonltr.css"/>
<link rel="stylesheet" type="text/css" href="../../css/public.css"/>
<title>排版规范</title>
</head>
<body id="chapter1_2"><a name="chapter1_2"><!-- --></a>
<h1 class="topictitle1">排版规范</h1>
<div>
<div class="p"><ol>
<li>关键词和操作符之间加适当的空格。</li>
<li>相对独立的程序块与块之间加空行。</li>
<li>较长的语句、表达式等要分成多行书写。</li>
<li>划分出的新行要进行适应的缩进,使排版整齐,语句可读。 </li>
<li>长表达式要在低优先级操作符处划分新行,操作符放在新行之首。 </li>
<li>循环、判断等语句中若有较长的表达式或语句,则要进行适应的划分。</li>
<li>若函数或过程中的参数较长,则要进行适当的划分。 </li>
<li>不允许把多个短语句写在一行中,即一行只写一条语句。</li>
<li>函数或过程的开始、结构的定义及循环、判断等语句中的代码都要采用缩进风格。</li>
<li>C/C++语言是用大括号‘{’和‘}’界定一段程序块的,编写程序块时‘{’和 ‘}’应各独占一行并且位于同一列,同时与引用它们的语句左对齐。在函数体 的开始、类的定义、结构的定义、枚举的定义以及if、for、do、while、switch、case语句中的程序都要采用如上的缩进方式。</li>
</ol>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>父主题:</strong> <a href="../../tasks/chapter1/chapter1.html" title="主要对为什么要进行编码规范和如何进行编码规范进行说明">Java 编码规范</a></div>
</div>
</div>
</body>
</html>
@@ -12,7 +12,12 @@
<ul>
<li><a href="tasks/info/hacopyright.html">版权信息</a></li>
<li><a href="tasks/info/apachelicense.html">Apache 许可证</a></li>
<li><a href="tasks/chapter1/chapter1.html">Java 编码规范</a></li>
<li><a href="tasks/chapter1/chapter1.html">Java 编码规范</a>
<ul>
<li><a href="tasks/chapter1/chapter1_1.html">程序编写规范</a></li>
<li><a href="tasks/chapter1/chapter1_2.html">排版规范</a></li>
</ul>
</li>
</ul>
</body>
</html>
@@ -60,6 +60,7 @@
<topicref href="tasks/info/hacopyright.dita"/>
<topicref href="tasks/info/apachelicense.dita"/>
<topicref href="tasks/chapter1/chapter1.dita">
<topicref href="tasks/chapter1/chapter1_1.dita"/>
<topicref href="tasks/chapter1/chapter1_2.dita"/>
</topicref>
</map>
@@ -0,0 +1,96 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- This document was created with Syntext Serna Free. --><!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd" []>
<!--
**
* Copyright (C) 2006-2010 YUCHENG HU
*
* +++++++++++++++++++++++++++++++++++++++++++++++++
* HA WEBSYSTEMS
* http://www.hawebs.net
* http://www.tcivis.com
*
* Contact
* huyuchengus@gmail.com / yuchenghu@hawebs.net
*
* +++++++++++++++++++++++++++++++++++++++++++++++++
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
* GNU GENERAL PUBLIC LICENSE
* APACHE LICENSE, VERSION 2.0
*
* +++++++++++++++++++++++++++++++++++++++++++++++++
-->
<concept id="chapter1_1" xml:lang="zh">
<title>程序编写规范</title>
<prolog>
<metadata>
<keywords>
<indexterm>Java</indexterm>
<indexterm>编码规范</indexterm>
</keywords>
</metadata>
</prolog>
<conbody>
<p><ul>
<li>
<p>exit()</p>
<p>exit 除了在 main 中可以被调用外,其他的地方不应该调用。因为这样做不给任何代码代码机会来截获退出。一个类似后台服务地程序不应该因为某一个库模块决定了要退出就退出。</p>
</li>
<li>
<p>异常</p>
<p>申明的错误应该抛出一个RuntimeException或者派生的异常。顶层的main()函数应该截获所有的异常,并且打印(或者记录在日志中)在屏幕上。</p>
</li>
<li>
<p>垃圾收集</p>
<p>JAVA使用成熟的后台垃圾收集技术来代替引用计数。但是这样会导致一个问题:你必须在使用完对象的实例以后进行清场工作。除非输出流一出作用域就关闭,非引用计数的程序语言,比如JAVA,是不能自动完成变量的清场工作的。必须象下面一样写:</p>
<p><codeblock>FileOutputStream fos = new FileOutputStream(projectFile);
project.save(fos, &quot;IDE Project File&quot;);
fos.close();</codeblock></p>
</li>
<li>
<p>Clone</p>
<p>下面是一种有用的方法:</p>
<p><codeblock>implements Cloneable
public
Object clone()
{
try {
ThisClass obj = (ThisClass)super.clone();
obj.field1 = (int[])field1.clone();
obj.field2 = field2;
return obj;
} catch(CloneNotSupportedException e) {
throw new InternalError(&quot;Unexpected CloneNotSUpportedException: &quot; + e.getMessage());
}
}</codeblock></p>
</li>
<li>
<p>final 类</p>
<p>绝对不要因为性能的原因将类定义为 final 的(除非程序的框架要求)。如果一个类还没有准备好被继承,最好在类文档中注明,而不要将她定义为 final 的。这是因为没有人可以保证会不会由于什么原因需要继承她。</p>
</li>
<li>
<p>访问类的成员变量</p>
<p>大部分的类成员变量应该定义为 protected 的来防止继承类使用他们。注意,要用&quot;int[] packets&quot;,而不是&quot;int packets[]&quot;,后一种永远也不要用。</p>
<p><codeblock>public void setPackets(int[] packets) { this.packets = packets; }
CounterSet(int size)
{
this.size = size;
}</codeblock></p>
</li>
</ul></p>
</conbody>
</concept>
@@ -0,0 +1,59 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- This document was created with Syntext Serna Free. --><!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd" []>
<!--
**
* Copyright (C) 2006-2010 YUCHENG HU
*
* +++++++++++++++++++++++++++++++++++++++++++++++++
* HA WEBSYSTEMS
* http://www.hawebs.net
* http://www.tcivis.com
*
* Contact
* huyuchengus@gmail.com / yuchenghu@hawebs.net
*
* +++++++++++++++++++++++++++++++++++++++++++++++++
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
* GNU GENERAL PUBLIC LICENSE
* APACHE LICENSE, VERSION 2.0
*
* +++++++++++++++++++++++++++++++++++++++++++++++++
-->
<concept id="chapter1_2" xml:lang="zh">
<title>排版规范</title>
<prolog>
<metadata>
<keywords>
<indexterm>Java</indexterm>
<indexterm>编码规范</indexterm>
</keywords>
</metadata>
</prolog>
<conbody>
<p><ol>
<li>关键词和操作符之间加适当的空格。</li>
<li>相对独立的程序块与块之间加空行。</li>
<li>较长的语句、表达式等要分成多行书写。</li>
<li>划分出的新行要进行适应的缩进,使排版整齐,语句可读。 </li>
<li>长表达式要在低优先级操作符处划分新行,操作符放在新行之首。 </li>
<li>循环、判断等语句中若有较长的表达式或语句,则要进行适应的划分。</li>
<li>若函数或过程中的参数较长,则要进行适当的划分。 </li>
<li>不允许把多个短语句写在一行中,即一行只写一条语句。</li>
<li>函数或过程的开始、结构的定义及循环、判断等语句中的代码都要采用缩进风格。</li>
<li>C/C++语言是用大括号‘{’和‘}’界定一段程序块的,编写程序块时‘{’和 ‘}’应各独占一行并且位于同一列,同时与引用它们的语句左对齐。在函数体 的开始、类的定义、结构的定义、枚举的定义以及if、for、do、while、switch、case语句中的程序都要采用如上的缩进方式。</li>
</ol></p>
</conbody>
</concept>