Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between public static and static public? [duplicate]

Tags:

java

What is difference between public static and static public?

For example :

static public class MyClass....

Or

public static class MyClass....
like image 329
A.A Avatar asked Jan 11 '15 10:01

A.A


3 Answers

While there's no difference in terms of functionality (byte code will be exactly the same) you do want to follow conventions, visit the JLS - 8.3.1. Field Modifiers:

FieldModifiers:
    FieldModifier
    FieldModifiers FieldModifier

FieldModifier: one of
    Annotation public protected private
    static final transient volatile

It'll be weird to see static public..

I also recommend you to visit checkstyle.


Edit:

Link from the same page to the class section:

http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.1.1

like image 123
Maroun Avatar answered Oct 04 '22 02:10

Maroun


JLS 8.1.1 :

A class declaration may include class modifiers.

ClassModifiers: ClassModifier ClassModifiers ClassModifier

ClassModifier: one of Annotation public protected private
abstract static final strictfp

If two or more (distinct) class modifiers appear in a class declaration, then it is customary, though not required, that they appear in the order consistent with that shown above in the production for ClassModifier.

So, public static is preferred, but the order doesn't really matter.

like image 32
Eran Avatar answered Oct 04 '22 02:10

Eran


There is no difference, but dare I say that the de facto standard is public static. More importantly, be consistent throughout your code.

like image 22
kinbiko Avatar answered Oct 04 '22 02:10

kinbiko