教程集 www.jiaochengji.com
教程集 >  脚本编程  >  java  >  正文 Good Java Style: Part 2

Good Java Style: Part 2

发布时间:2019-01-28   编辑:jiaochengji.com
教程集为您提供Good Java Style: Part 2等资源,欢迎您收藏本站,我们将为您提供最新的Good Java Style: Part 2资源
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 {

您可能感兴趣的文章:
Good Java Style: Part 2
php 获取访问者浏览器的代码
php数组遍历(foreach,list,each)实例演练
几个PHP技巧
PHP中的一些经验积累
js实现输入框自动匹配字符的实例代码
php 获取客户浏览器与操作系统类型
php遍历哈希表及关联数组的实例代码
jsp中foreach与for循环使用实例
使用u盘自动化安装centos的例子

[关闭]
~ ~