Search code examples
javaconventionscurly-braces

What is the name of this convention for curly braces?


I'm a bit puzzled by the number of developers I see writing methods and classes with curly braces below the class name or the method. What convention are they following?

Sun clearly states that the correct declaration would be:

// this declaration follows sun's conventions
class Sample extends Object {

    Sample(int i, int j) {
        ....
    }
}

Yet more and more I see this declared as (even in books):

// this declaration follows a convention I cant identify
class Sample extends Object 
{

    Sample(int i, int j) 
    {
        ....
    }
}

And I know that a convention is just a convention and, as long as you follow one, all is good. I'm just looking for the answer on what convention does the latter declaration follow?


Solution

  • This is a standard style convention called the ANSI style. It's common in other languages besides Java, as well.