I don't know if it is just what my first Java lecturer taught me or if it is based on something. It has parts of it that are the same as the Oracle Java style (naming) but differs in other ways, as they seems to prefer K&R braces.

  1. Braces are always on a line of their own.
  2. Even one line statements inside blocks get braces.
  3. Spaces after the comma separating parameters.
  4. Spaces between the operator and the variables for binary operators but not for unary operators.
  5. Four spaces for a tab.
  6. Blank lines between separate concepts inside functions and between class level elements i.e. separating functions from each other and from declarations/definitions.
  7. Capital for each new word.
  8. Classes start with a capital.
  9. Functions and variables start with a lower case letter.
  10. Constants are all capitals.
public class MyClass
    public static final float PI = 3.14;

    public static void main(String[] args)
        if((1 + 2) == 3 && returnFirstMinusSecond(9, 2) == 7 && !returnsFalse())
            // output 

            // some other code that is logically separate from output
            // do something else that I want to keep separate as it is complex

closed as primarily opinion-based by gnat, Blrfl, user40980, user22815, Bart van Ingen Schenau Apr 6 '15 at 9:38

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • "Standard Java"? I mean, what am I missing? – Telastyn Apr 5 '15 at 20:25
  • Seems to be Allman Style for indent+braces. It's certainly not K&R. – Deduplicator Apr 5 '15 at 20:33
  • BTW: Consider using a java highlighting hint or the java tag... – Deduplicator Apr 5 '15 at 20:39
  • I might call your No.2 rule of explicitly putting braces even for one line statements "Perl style" because Perl enforces this rule in the language. Your rules about adding spaces after commas seem like the same rule that is used in standard English prose. e.g. "I think, therefore I am." – Brandin Apr 5 '15 at 20:44
  • Your No.5 rule is known in some text editors as "Insert spaces for tabs" or "expandtab" in VIM. – Brandin Apr 5 '15 at 20:49

Coding styles generally aren't referred to by name unless the name is a clear reference to a published style guide, such as the ones published by Google.

Indeed, rarely is the collective styles of indentation, naming convention, alignment, etc. given a single name, and even those individual styles don't have standard names.

Based on your description, however, I can give you the names that are commonly-accepted by parts of the programming community:

  • Your indentation style is usually called Allman Style, for Eric Allman, the author of sendmail and syslog.
  • Your naming convention is generally referred to as CamelCase, in reference to the bumpy use of upper- and lower-case letters. More specifically, you are mixing UpperCamelCase (also sometimes called PascalCase) for class names and lowerCamelCase for method names.

Other than that, there isn't really an applicable name for operator style or alignment of which I am aware.

Your use of internal whitespace (such as between operators and in parameter lists and between logical blocks), however, is widely regarded as simply "good style."

  • 1
    +1 Exactly what I was going to write. I'd add that in OP's list items 2, 3, 4 and 6 would probably be considered "good coding style" and also not given any specific name. – Ixrec Apr 5 '15 at 20:43
  • @greyfade Thanks. I had misread the wiki page on Allman. Allman + CamelCase + Good is as close as seems to be possible. – Encaitar Apr 6 '15 at 11:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.