Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Objects Harnessing the Power of Objects Constants

Yves Le Palud
Yves Le Palud
4,894 Points

Is there a specific order for keywords?

like "public" then "static" then "final"?

Is there a difference if I made a different order?

2 Answers

Yanuar Prakoso
Yanuar Prakoso
15,196 Points

Hi Yves

I guess there is no fix rules on the order of the modifiers. I was running this main method in my IDE (IntelliJ IDEA):

public class Main {
    final static public void main(String[] args){
        try {
            CSVPrinter printer = new CSVPrinter(System.out, CSVFormat.EXCEL);
            printer.printRecord("Mooracles", 5, "Loved it");
            printer.printRecord("John", 4, "Can be better, okay?");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

And that code is still works just fine despite, as you can see, it does not use the traditional order of public, static, final. One big warning here that never ever you move void from its original place!! Because void is not modifier, void is a type that is must be stand before the methods name!!

Yes there is some initiative and honestly I think this is also best practice to use commonly used order of modifiers. Such as mentioned here:

  1. Access modifier (public / private / protected)
  2. abstract
  3. static
  4. final
  5. transient
  6. volatile
  7. default
  8. synchronized
  9. native
  10. strictfp

Although it is okay not to use that recommended order it will be best practice to use them. It is common usage so it will make other developer to read your code for better collaboration.

I hope this can help a little

Yves Le Palud
Yves Le Palud
4,894 Points

Ok thank you! I should respect practices for a cleaner code. It would be more readable