2004年十月月 发布的文章

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
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 ————————————————-
}

Dominoo项目日记(一)

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

Dominoo是什么?

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

Dominoo的主要意图是什么?

Dominoo的提出的大背景是UMLMDA(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的三个主要目标是:通过架构性的分离来实现轻便性、互操作性和可重用性。

如发现本站页面被黑,比如:挂载广告、挖矿等恶意代码,请朋友们及时联系我。十分感谢! Go语言第一课 Go语言精进之路1 Go语言精进之路2 商务合作请联系bigwhite.cn AT aliyun.com

欢迎使用邮件订阅我的博客

输入邮箱订阅本站,只要有新文章发布,就会第一时间发送邮件通知你哦!

这里是 Tony Bai的个人Blog,欢迎访问、订阅和留言! 订阅Feed请点击上面图片

如果您觉得这里的文章对您有帮助,请扫描上方二维码进行捐赠 ,加油后的Tony Bai将会为您呈现更多精彩的文章,谢谢!

如果您希望通过微信捐赠,请用微信客户端扫描下方赞赏码:

如果您希望通过比特币或以太币捐赠,可以扫描下方二维码:

比特币:

以太币:

如果您喜欢通过微信浏览本站内容,可以扫描下方二维码,订阅本站官方微信订阅号“iamtonybai”;点击二维码,可直达本人官方微博主页^_^:
本站Powered by Digital Ocean VPS。
选择Digital Ocean VPS主机,即可获得10美元现金充值,可 免费使用两个月哟! 著名主机提供商Linode 10$优惠码:linode10,在 这里注册即可免费获 得。阿里云推荐码: 1WFZ0V立享9折!


View Tony Bai's profile on LinkedIn
DigitalOcean Referral Badge

文章

评论

  • 正在加载...

分类

标签

归档



View My Stats