Comments

  • Block Comments

Block comments are used to provide descriptions of files, methods, data structures and algorithms. Block comments may be used at the beginning of each file and before each method. They can also be used in other places, such as within methods. Block comments inside a function or method should be indented to the same level as the code they describe.

A block comment should be preceded by a blank line to set it apart from the rest of the code.


    /*
     * Here is a block comment.
     */
  • Single-Line Comments

Short comments can appear on a single line indented to the level of the code that follows. If a comment can’t be written in a single line, it should follow the block comment format. A single-line comment should be preceded by a blank line. Here’s an example of a single-line comment in Java code.


    if (condition) {

        /* Handle the condition. */
        ...
    }
  • Trailing Comments

Very short comments can appear on the same line as the code they describe, but should be shifted far enough to separate them from the statements. If more than one short comment appears in a chunk of code, they should all be indented to the same tab setting.

Here’s an example of a trailing comment in Java code:


    if (a == 2) {
        return TRUE;            /* special case */
    } else {
        return isPrime(a);      /* works only for odd a */
    }
  • End-Of-Line Comments

The // comment delimiter can comment out a complete line or only a partial line. It shouldn’t be used on consecutive multiple lines for text comments; however, it can be used in consecutive multiple lines for commenting out sections of code. Examples of all three styles follow:


    if (foo > 1) {

        // Do a double-flip.
        ...
    }
    else {
        return false;          // Explain why here.
    }
    //if (bar > 1) {
    //
    //    // Do a triple-flip.
    //    ...
    //}
    //else {
    //    return false;
    //}

Original Post

http://www.oracle.com/technetwork/java/codeconventions-141999.html

Advertisements

Comment Rules For Java Source Files

Each Java source file contains a single public class or interface. When private classes and interfaces are associated with a public class, you can put them in the same source file as the public class. The public class should be the first class or interface in the file.

Java source files have the following ordering:

  • Beginning comments
  • Package and Import statements
  • Class and interface declarations

Java Source File Example

The following example shows how to format a Java source file containing a single public class. Interfaces are formatted similarly.

/*
 * @(#)Blah.java        1.82 99/03/18
 *
 * Copyright (c) 1994-1999 Sun Microsystems, Inc.
 * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of Sun
 * Microsystems, Inc. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Sun.
 */

package java.blah;

import java.blah.blahdy.BlahBlah;

/**
 *
 *
 Class description goes here.
 *
 * @version
 *
 1.82 18 Mar 1999
 * @author
 *
 Firstname Lastname
 */
public class Blah extends SomeClass {

    /* A class implementation comment can go here. */

    /**
     *
     classVar1 documentation comment */
    public static int classVar1;

    /**
     *
     *
     *
     *
     classVar2 documentation comment that happens to be
     *
     *
     more than one line long
     */
    private static Object classVar2;

    /**
     *
     instanceVar1 documentation comment */
    public Object instanceVar1;

    /**
     *
     instanceVar2 documentation comment */
    protected int instanceVar2;

    /**
     *
     instanceVar3 documentation comment */
    private Object[] instanceVar3;

    /**
     * ...
     *
     constructor Blah documentation comment...
     */
    public Blah() {

        // ...implementation goes here...
    }

    /**
     * ...
     *
     method doSomething documentation comment...
     */
    public void doSomething() {

        // ...implementation goes here...
    }

    /**
     * ...method doSomethingElse
     *
     documentation comment...
     * @param someParam
     *
     description
     */
    public void doSomethingElse(Object someParam) {

        // ...implementation goes here...
    }
}

Original Post
http://www.oracle.com/technetwork/java/codeconventions-137946.html#182

Introduction

java

Java is a programming language originally developed by James Gosling at Sun Microsystems (which is now a subsidiary of Oracle Corporation) and released in 1995 as a core component of Sun Microsystems’ Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. Java applications are typically compiled to bytecode (class file) that can run on any Java Virtual Machine (JVM) regardless of computer architecture. Java is a general-purpose, concurrent, class-based, object-oriented language that is specifically designed to have as few implementation dependencies as possible. It is intended to let application developers “write once, run anywhere”. Java is currently one of the most popular programming languages in use, and is widely used from application software to web applications. The original and reference implementation Java compilers, virtual machines, and class libraries were developed by Sun from 1995. As of May 2007, in compliance with the specifications of the Java Community Process, Sun relicensed most of its Java technologies under the GNU General Public License. Others have also developed alternative implementations of these Sun technologies, such as the GNU Compiler for Java, GNU Classpath, and Dalvik.

wikipedia

1st thing you should do that download the jdk (java development kit) from here and then download any of the IDE.  For java you should know the java documentation (javadoc) and the Java Language Specification (JLS).

There were five primary goals in the creation of the Java language:

1. It should be “simple, object oriented, and familiar”.
2. It should be “robust and secure”.
3. It should have “an architecture-neutral and portable environment”.
4. It should execute with “high performance”.
5. It should be “interpreted, threaded, and dynamic”.

There are several IDE (Integrated development environment) for java like

Eclipse, NetBeans, DrJava, JIPE, Gel, BlueJ

In this website we are going to cover JAVA SE(wiki), JAVA SE(oracle). Before starting coding you should gone through following pages.

1. Java Code Convention’s Click Here
2. Java data types Click Here
3. Java operators Click Here

mascot

Duke, the Java mascot