Ordering Java methods is probably the least important code style issue ever, but I'm trying to develop a code style as similar to what most people do as possible. It's by far the most popular approach to first declare all fields and then all methods, so I'll only ask about methods.
Now I'm wondering how to order Java methods. I can think of two sensible basic approaches:
Order methods by visibility (i.e. first public, then protected, then private or the other way around)
Order methods by dependency (i.e. if method a() calls method b(), put them as closely together as possible)
As far as I see it, the second approach seems to be more popular by far. Nonetheless, in both cases there is the question of the direction, and it is not as clear what most people use. In the second approach, you can either place a() above or below b(). I think placing b() above a() (and eventually main() at the bottom of the class file) is more common in C, not sure about C++. The other way around is IMO better for reading, from top to bottom. What's the most common approach in Java? Any special rules about static fields/methods?
解决方案
I would generally prefer option 2 - with a class overview in the IDE showing public and private methods and auto-complete only showing the visible ones for a class, it does matter less though, as @Visage mentions.