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 trialfbenedetti
2,010 PointsIs there a style guide for Java objects?
Hi there!
I might be anticipating some content further down the track, but the constructor method made me wonder if there's a recommended way of structuring objects in Java.
Is there a recommended way of creating classes / objects in Java? Perhaps an official style guide that says things like "variables first, constructor, then methods, etc"?
Cheers!
F.
Edit: I found this styleguide --section 4 looks relevant:
3 Answers
Craig Dennis
Treehouse TeacherHere is Google's Java style guide and here is Android's contributor guidelines and Oracle's.
You'll see they all differ slightly. As stated, it's best to work in whatever style you land in ;)
Alice Spencer
12,273 PointsI'm learning Java also, but have lucked out having my own tutor right here at home for questions. My husband is a software engineer who programs in Java, and as since it's release. I asked him your question, and his answer was
"No, it's completely up to the person programming. In fact people get into 'wars' over what is the best methodology"
I can totally see some lively discussions in my house in the future LOL (our 8 year old is getting a Minecraft Modding program for Christmas that teaches Java) so we'll have 3 of us, probably all with slightly different thoughts on the subject.
Robert Richey
Courses Plus Student 16,352 PointsI don't believe so. My recommendation is to try and stick with whatever style you're learning from. For example, in Stanford's Programming Methodology course, class styles looked like this
class declaration
constants
methods
variables
and it was easier to follow along with the material by adopting their styles.
Lisa Steendam
6,825 PointsVariables last feels really odd to me. I always use :
- variables
- constants
- constuctor
- getters/setters
- other methods
But of course, to each their own. As long as you group things together, variables and methods mixed all over the place is not very reader friendly.