Skip to content

1.1.2 File Organization

Tomaz Martins edited this page Jul 31, 2015 · 3 revisions

1.1.2.1 File Source Java

Each Java source file should contain only one class or interface public. When a class and/or private interface is associated with a public class, it can to put it in the same file as the public class. The class or interface, the public should be the first thing visible in the file.

Java source files must follow the following sort order:

  • Initial comments.
  • Instructions packages and import.
  • Class or interface statement.

1.1.2.1.1 Initial Comments

Every source file should start with a review-style C, which lists the name of the class or interface and its purpose. An example follows:

/ *
  * File: ExampleClass
  * Purpose: This is the example to explain how to write a comment beginning.
  * /

1.1.2.1.2 Instructions Packages and Imports

The first line of the file that is not a comment should be an instruction package. Then, follow the instructions to import. Example:

br.com.visualize.akan.domain.controller package;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.http.client.ResponseHandler;
import org.json.JSONException;

import android.content.Context;
import android.util.Log;
import br.com.visualize.akan.api.dao.CongressmanDao;
import br.com.visualize.akan.api.helper.JsonHelper;
import br.com.visualize.akan.api.request.HttpConnection;
import br.com.visualize.akan.domain.enumeration.Order;
import br.com.visualize.akan.domain.exception.ConnectionFailedException;
import br.com.visualize.akan.domain.exception.DatabaseInvalidOperationException;
import br.com.visualize.akan.domain.exception.NullCongressmanException;
import br.com.visualize.akan.domain.exception.NullQuotaException;
import br.com.visualize.akan.domain.model.Congressman;
import br.com.visualize.akan.domain.model.Quota;

1.1.2.1.3 Declaration of Classes and Interfaces

The table below describes the parts of a class declaration or interface. These parties must appear in the order they are presented in the table.

Ordem Part of Class / Interface Description
1 Documentation comments of Class/Interface See section on Documentation Comments
2 Instruction class or interface -
3 Implementation Comments Class/Interface This comment contains any information about the class/interface that is not appropriate to the documentation of comments.
4 Variables static of class First the variables public, followed by protected variables. After the variables private.
5 Instance variables of class. First the variables public, followed by protected variables. After the variables private.
6 Constructors -
7 Documentation comments of Methods See section on Documentation Comments
8 Methods First the methods public, followed by protected methods. After the merthods private.