Jump to content
  • Advertisement
Sign in to follow this  

Question: Coding Conventions

This topic is 1369 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys, I'm trying to look up the various conventions for writing classes in Java (and beyond). For anyone equally new to programming, I've been looking at the various coding standards found @ https://ace.apache.org/dev-doc/coding-standards.html


My Question:
For the pros out there, I'm trying to get confirmed where (in Java) I should place constructors. Is it typical to group them all up before or after normal methods? I've seen a lot of people start with constructors.

Here's what I'm thinking right now:


package gTLD.subdomain.application.package.subpackage.*;

import external package.subpackage.*;
// Class, Interface, Enum and Annotation names: nouns with first letter per word capitalized.
public MyClass extends SuperClass implements Interface {

    public static void main(String[] args) {

    private static final int CONSTANTINE = 123; // All final variables at top of list.
    private static String m_goldMember = null; // Other fields. Notice the m_

// Recommend one declaration per line. Encourage commenting and cause less confusion.
// All instance variables at bottom of list.

    private int x = 0; // x of something
    private int y = 0; // y of something

/* Methods: Verbs with first letter lowercase.
 * Vars used and declared within methods must always be initialized explicitly.
 * Declare all local vars just before needed.

    Constructor (x, y, z) {

    method (x, y, z) {

    String toString() {
        return stringConcat; // stringConcat: whichever variables concatonated to create the string;

Feel free to comment on how you personally organize things and what you think is good and bad (e.g. about my code here).

Thanks in advance.

Edited by Madolite

Share this post

Link to post
Share on other sites

That makes a lot of sense. I'll go read up on the comments in that thread, as well. smile.png

Edited by Madolite

Share this post

Link to post
Share on other sites

I normally organize my classes as follows:


public static member

public static methods

public members

public constructors

public methods


same for protected

same for private


With this method the things most important do the user of your class are on top


Another method I've seen and found not to bad:


everything static

all methods in oder public, protected. private

all members in order public, protected, private

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!