What is the difference between using static public boolean
and public static boolean
for methods?
I just tried both and both seem to compile fine and have the same effect unless I am doing it wrong. Which one is better and why?
There's absolutely no difference, but putting public
first is slightly preferred in terms of conventions. From section 8.4.3 of the Java Language Specification:
MethodModifier
: one ofAnnotation public protected private abstract static final synchronized native strictfp
...
If two or more (distinct) method modifiers appear in a method declaration, it is customary, though not required, that they appear in the order consistent with that shown above in the production for MethodModifier.
I just tried both and both seem to compile fine and have the same effect unless I am doing it wrong. Which one is better and why?
They are pretty same. No difference only first case is less readable. I think second case is more human-readable and you should program for humans so choose option that is more readable. Also by conventions you should use first.
This is similar if you ask for null != obj
or obj != null
both are same but first case is sometimes used but is much less readable and for me it's annoying.
public static boolean
is more readable than static public boolean