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.
- Braces are always on a line of their own.
- Even one line statements inside blocks get braces.
- Spaces after the comma separating parameters.
- Spaces between the operator and the variables for binary operators but not for unary operators.
- Four spaces for a tab.
- Blank lines between separate concepts inside functions and between class level elements i.e. separating functions from each other and from declarations/definitions.
- Capital for each new word.
- Classes start with a capital.
- Functions and variables start with a lower case letter.
- 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
System.out.println("true");
// some other code that is logically separate from output
// do something else that I want to keep separate as it is complex
}
else
{
while(true)
{
System.out.println("false");
}
}
}
}
9
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.”
2