设为首页 加入收藏

TOP

Good Java Style: Part 2
2011-06-09 13:02:42 来源: 作者: 【 】 浏览:390次 评论:0
Good Java Style: Part 2
By Thornton Rose
Introduction
This is the conclusion of a two-part series on Java coding style. In Good Java Style: Part 1
, I introduced my case for writing Java code using good habits, explained why we should care about the way our code looks, and illustrated some general elements of good Java style. In this part, I illustrate more elements of good style and bring my case to a conclusion.
Source Files
There are many ways that a Java source file can be organized. Here is one that works well:
File header comment (optional).
Package declaration.
Blank line or other separator.
Import statements.
Blank line or other separator.
Class(es).
Example 1. Bad File Organization.
   package org.rotpad;
   import java.awt.*;
   import javax.swing.event.*;
   import org.javacogs.*;
   import javax.swing.*;
   import java.awt.event.*;
   class Foo {
    ...
   }
   public class RotPad extends JFrame {
    ...
   }
Example 2. Good File Organization.
   package org.rotpad;
   // Java classes
   import java.awt.*;
   import java.awt.event.*;
   import javax.swing.*;
   import javax.swing.event.*;
   // JavaCogs classes
   import org.javacogs.*;
   /**
    * RotPad is a simple GUI application for performing rotation ciphers on plain
    * text.
    *
    * @author Thornton Rose
    * @version 1.0
    */
   public class RotPad extends JFrame {
您看到此篇文章时的感受是:
Tags: 责任编辑:administrator
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到QQ空间
分享到: 
上一篇JAVA程序员必读:基础篇(8) 下一篇更改 Netbeans 中选项卡的名称

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

相关栏目

最新文章

图片主题

热门文章

推荐文章

相关文章

广告位