• Java技术学习系列

                            ---Java基础

    内容:
    .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 <options> <source files>
    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 <path>         Specify where to find user class files
      -sourcepath <path>        Specify where to find input source files
      -bootclasspath <path>     Override location of bootstrap class files
      -extdirs <dirs>           Override location of installed extensions
      -d <directory>            Specify where to place generated class files
      -encoding <encoding>      Specify character encoding used by source files
      -source <release>         Provide source compatibility with specified

    release
      -target <release>         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 Code Style说明在http://www.jboss.org/developers/guides/codestyle ,这里摘取其中的代码模板的例子:

    /*
     * 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 <tt>$Revision: 1.3 $</tt>
     * @author  <a href="
    mailto:{email}">{full name}</a>.
     * @author  <a href="
    mailto:marc@jboss.org">Marc Fleury</a>
     */
    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 -------------------------------------------------
    }

     

  • Dominoo项目日记(一)
                      -- 初识Dominoo

    国庆节前夕见到了Darwin_yuan,他给我们带来了Dominoo。

    Domino是什么?
    在Darwin_yuan的blog中是这样描述的:Dominoo means "Design Of Model IN Object-Oriented.",从字面的意思来理解Dominoo就是“用面向对象的方法进行模型设计”。

    Dominoo的主要意图是什么?
    Dominoo的提出的大背景是UML、MDA(Model Driven Architecture)[1]等概念和方法论的提出和飞速发展。Dominoo的最直接意图就是由软件的设计模型直接产生可执行代码,也就是说Dominoo将传统的“需求”--〉“设计”--〉“编码”--〉“测试”的软件开发过程链缩短了,变成了“需求”--〉“设计”--〉“测试”。这将把开发人员从繁重的编码中解脱出来而专著于软件系统的模型设计,从而大大提高了软件开发人员的劳动生产率。


    注1:什么是MDA呢?简而言之,就是一个围绕支持模型驱动开发过程的一系列标准的框架,这些标准包括:统一建模语言UML(Unified Modeling Language)、元对象机制MOF(Meta Object Facility)、XML元数据交换XMI(XML Metadata Interchange)、公共数据仓库元模型CWM(Common Warehouse Metamodel)等。MDA的三个主要目标是:通过架构性的分离来实现轻便性、互操作性和可重用性。