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 trialYves Le Palud
4,894 PointsIs 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
15,196 PointsHi 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:
- Access modifier (public / private / protected)
- abstract
- static
- final
- transient
- volatile
- default
- synchronized
- native
- 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
4,894 PointsOk thank you! I should respect practices for a cleaner code. It would be more readable