• Post Reply Bookmark Topic Watch Topic
  • New Topic

static final (or) final static  RSS feed

 
rama murthy
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public static final int ABC= 100;
public final static int ABC= 100;

which one should be followed?
Is there any standard of which one should be followed?
 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rama murthy:
public static final int ABC= 100;
public final static int ABC= 100;

which one should be followed?
Is there any standard of which one should be followed?


Well Although there is not any reason, I have seen for this. But usually I use to follow



Could any other rancher throw some light with specific reason.
[ August 24, 2006: Message edited by: Ankur Sharma ]
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no official coding standard for Java, although many people use Sun's Code Conventions for the Java Programming Language.

But I don't think that document says anything about your question.

Just use whatever you like and use it consistently (i.e., don't use "static final" in one place and "final static" in another place - the code will look less messy if you consistently do it in one way).
 
Dana Bothner-By
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sun's coding convention is to order them "static final".

I remember that by thinking "static final ... science fiction", but then I'm a big SF&F fan and often mistaken for an elf.
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've always done static final. I don't know why, it just makes more sense.
 
Srikanth Basa
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For me "public static final" makes more sense. Im more bothered to see if a member variable is a class variable or an instance variable.
 
aitex abex
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In general we use Public static final but there is no any restriction or any rule for not use Public final static its depends upon your coding habits.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Dana]: Sun's coding convention is to order them "static final".

I disagree. The only mention of final is in the section on Naming Conventions, where the give some code examples of constants. And yes, the examples do say "static final" - but they're just examples. Not rules. The rule that the examples are illustrating there is just about the name of the constant - nothing about the order of the modifiers.

For what it's worth, I would use "static final" too. It seems to be the prevalent style that most people are used to seeing. I'm just saying it's not actually part of Sun's standard.
 
Dana Bothner-By
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your'e right. I was thinking of the JLS. I have the second edition handy and in section 8.3.1 (Field Modifers) they give the production:

FieldModifier: one of
public protected private
static final transient volatile

Below this it is written:

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


That is where I got the idea that "static final" or "public static final" was prefered.
 
Guru Yegnanarayanan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but you can definately write i beleive as

static public final void in ABC=100;
[ August 28, 2006: Message edited by: Guru Yegnanarayanan ]
 
Dana Bothner-By
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Guru Yegnanarayanan:
but you can definately write i beleive as

static public final void in ABC=100;


void?
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Guru Yegnanarayanan:
but you can definately write i beleive as

static public final void in ABC=100;

[ August 28, 2006: Message edited by: Guru Yegnanarayanan ]


No...I'm pretty sure you can't. void is not a valid modifier and there is no "in" primitive. I'm guess you're saying you can write the modifiers in a different order which is true, nobody's contested that.
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dana Bothner-By:


void?


it's a no-brainer
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!