Search code examples
javacoding-styleconventionsconvention

Java convention with regard to code format


Is it allowed in Java convention to write such code:

public void nameOfTheFunction()
{

}

A lot of people said me that it is prohibited according to Java code convention and that my code should look like:

public void nameOfTheFunction(){

}

But I did not find any info about this.


Solution

  • This is oracle(/java) convention

    see oracle

    Quote:

    Class and Interface Declarations When coding Java classes and interfaces, the following formatting rules should be followed: • No space between a method name and the parenthesis “(“ starting its parameter list • Open brace “{” appears at the end of the same line as the declaration statement • Closing brace “}” starts a line by itself indented to match its corresponding opening statement, except when it is a null statement the “}” should appear immediately after the “{“

    class Sample extends Object {
     int ivar1;
     int ivar2;
     Sample(int i, int j) {
       ivar1 = i;
       ivar2 = j;
     }
     int emptyMethod() {}
     ...
    }