.jdk的安装
.环境变量的配置
.Eclipse IDE的安装和配置
.Java编码规范

1、jdk的安装

Java号称跨平台,实际上其本身就是个平台,我们要使用Java开发应用程序,我们首先就要安装Java平台,所谓Java平台就是指Java的运行环境(JRE)和相应的SDK。

这里我们选择j2sdk1.4.2来作为我们的Java平台,安装过程只需一路next即可。安装结束后,我们在命令行下输入“java -version”,若显示出:

java version "1.4.2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)

则说明我们的安装成功了!

2、环境变量的配置

很多初学者接触Java时都在环境变量的配置上花了不少时间和精力,这也是我把它单列出来加以说明的原因。

Java开发环境需要配置3个环境变量,分别是:

JAVA_HOME=your_j2sdk_installation_path
PATH=%JAVA_HOME%\bin;%PATH%
CLASSPATH=.;%JAVA_HOME%\jre\lib\rt.jar;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar

注意:CLASSPATH中包含一个“.”,这个“.”很重要千万不能遗漏,这个“.”的含义是允许在当前路径下搜索。

这些环境变量如何配置呢,在Windows下最简单的配置环境变量的方法是在“我的电脑”上单击右键点击“属性”,打“系统属性”对话框,选择“高级”标签栏,其中有“环境变量”按钮,点击之后打开“环境变量”对话框,在下面的“系统变量”中添加上述3个环境变量即可。

配置成功后,在命令行下输入:javac ,若显示:

Usage: javac
where possible options include:
-g                        Generate all debugging info
-g:none                   Generate no debugging info
-g:{lines,vars,source}    Generate only some debugging info
-nowarn                   Generate no warnings
-verbose                  Output messages about what the compiler is doing
-deprecation              Output source locations where deprecated APIs are used
-classpath          Specify where to find user class files
-sourcepath         Specify where to find input source files
-bootclasspath      Override location of bootstrap class files
-extdirs            Override location of installed extensions
-d             Specify where to place generated class files
-encoding       Specify character encoding used by source files
-source          Provide source compatibility with specified

release

-target          Generate class files for specific VM version
-help                     Print a synopsis of standard options

则说明环境变量配置成功。

3、Eclipse IDE的安装和配置

开发java程序,我们需要一个功能强大而且易用性好的ide,JBuilder太贵我们用不起,我们选择免费的eclipse。eclipse的安装很简单。只需将下载后的压缩包解压到某个目录下即可。相关的eclipse ide的配置我们都可以通过“Window”菜单下的“Open Perspective”和“Preferences”两个菜单项进行设置。

这里我们再来重点说说Java开发中常用的几个工具的配置和使用方法:

Ant — 待定
CVS — 见我的blog文章“CVS Primer
JUnit — 待定

参考资料:OReilly@2004 -  《Eclipse Cookbook》

4、Java编码规范

感觉Java在编码规范方面的分歧较小,比较容易在group中达成共识。
我们准备在Dominoo项目中使用“JBoss Code Style”,这里摘取其中的代码模板的例子:

/*
 * JBoss, the OpenSource J2EE webOS
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package x;

// EXPLICIT IMPORTS
import a.b.C1; // GOOD
import a.b.C2;
import a.b.C3;

// DO NOT WRITE
import a.b.*;  // BAD

// DO NOT USE "TAB" TO INDENT CODE USE *3* SPACES FOR PORTABILITY AMONG EDITORS

/**
 * A description of this class.
 *
 * @see SomeRelatedClass.
 *
 * @version $Revision: 1.3 $
 * @author  xx
 * @author  yy
 */
public class X
    extends Y
    implements Z
{
    // Constants —————————————————–

    // Attributes —————————————————

    // Static ——————————————————–

    // Constructors ————————————————–

    // Public ——————————————————–

    public void startService() throws Exception
    { // Use the newline for the opening bracket so we can match top and bottom bracket visually

        Class cls = Class.forName(dataSourceClass);
        vendorSource = (XADataSource)cls.newInstance();

        // JUMP A LINE BETWEEN LOGICALLY DISCTINT **STEPS** AND ADD A LINE OF COMMENT TO IT
        cls = vendorSource.getClass();

        if(properties != null && properties.length() > 0)
        {

            try
            {
            }
            catch (IOException ioe)
            {
            }
            for (Iterator i = props.entrySet().iterator(); i.hasNext();)
            {

                // Get the name and value for the attributes
                Map.Entry entry = (Map.Entry) i.next();
                String attributeName = (String) entry.getKey();
                String attributeValue = (String) entry.getValue();

                // Print the debug message
                log.debug("Setting attribute '" + attributeName + "' to '" +
                        attributeValue + "'");

                // get the attribute
                Method setAttribute =
                    cls.getMethod("set" + attributeName,
                            new Class[] { String.class });

                // And set the value
                setAttribute.invoke(vendorSource,
                        new Object[] { attributeValue });
            }
        }

        // Test database
        vendorSource.getXAConnection().close();

        // Bind in JNDI
        bind(new InitialContext(), "java:/"+getPoolName(),
                new Reference(vendorSource.getClass().getName(),
                    getClass().getName(), null));
    }

    // Z implementation ———————————————-

    // Y overrides —————————————————

    // Package protected ———————————————

    // Protected —————————————————–

    // Private ——————————————————-

    // Inner classes ————————————————-
}

© 2004, bigwhite. 版权所有.

No related posts.