Java coding specification

zhaozj2021-02-16  45

Java coding specification

Translation: Wang Shi Yong

(Reprinted please keep the author, thank you)

1. Introduction

1.1 Why is the code specification

Why is the coding specification is important? There are some reasons:

l A software 80% life cycle is the maintenance period

l It is hard to say that his entire life cycle is maintained by his original author.

l Code specification to improve software readability, so that software engineers fully understand the new code becomes very fast.

l If you want to release your original code as a product, you need to make sure that he is as clean and packaged like your other products.

In order to work according to the specification, the coding specification must be observed when each person is written. Remember, everyone!

1.2 acknowledgment

This book reflects the Java Language Specification for Java language coding specifications. Here to focus on Peter King, Patrick Naughton, Mike Demoney, Jonni Kanerva, Kathy Walrath, and Scott Hommel thank you.

2. file name

This section lists most of the file names and suffixes used in this book.

2.1 File suffix

.java java source file suffix

.CLASS JAVA byte code file suffix

2.2 Common file name

The file names that are often used include the following:

Gnumakefile preferred Makefile's name, we use gnumake to build our software.

Readme, those preferred names that specifically outline the file of the specific folder content

3. Organization of documents

The individual parts of a file should be spaced apart from the space, and one optional annotation should be used to indicate each different portion.

The file is more than 2,000 lines, which is very cumbersome, should be avoided.

As for examples of the correct format of Java programming, see "Java Source File Example (Java Original File Example)" on page 18.

3.1 Java source code file

Each Java source file includes a unique public class or interface. When private classes and interface are related to this public class, you can put them in the source file of this public class. This public class or interface should be the first class or interface of this file.

The Java source file has the following order:

l The beginning of the file (see "Beginning Comments (beginning)")

l Declare the statement and load statement.

Laws with Class L and Interface (see "Class and Interface Declarations") of Page 3)

3.3.1 Opening

All source files should begin with a C language style. This annotation should list class name, version information, date, and copyright statement:

/ *

* ClassName

*

* Version Information

*

* Date

*

* CopyRight Notice

*

* /

3.1.2 Solutions and Import statements

The vast majority of Java source files should be the statement of a statement package. Since then, it is followed by an Import statement. E.g:

Package java.aw;

Import java.awt.peer.canvaspeer;

3.1.3 Declaration of Category and Interface

The following table describes the declaration of the partial class and interface, and they should follow the order of the table. See "Java Source File Example" on page 18.

转载请注明原文地址:https://www.9cbs.com/read-27561.html

New Post(0)