What are your java conventions?



public class NameSpace {

	private static final int NAME_SPACE = 0;

	private static int name_space;

	private int nameSpace;
	
	private float floatTest = 0.1f; // some people put a capital 'f' like 0.1F
	private double doubleTest = 0.1D; // some people put a lowercase 'd' like 0.1d
	
	private void nameSpace(int nameSpace) {
		this.nameSpace = nameSpace;
	}
	
	public static int nameSpace(boolean nameSpaceBool) {
		return nameSpaceBool ? 1 : name_space;
	}
	
	public void lotsOfIfs() {
		if (nameSpace < 1) {
			nameSpace = 1;
		} else if (nameSpace > 1) {
			nameSpace = 2;
		} else {
			nameSpace = 0;
		}
	}
	
	private int someMath(int a, int b) {
		return (a * b) + (a / b) - (a * a); // some people don't put those parenthesis
	}
	
}

These are my conventions, i’m not sure if I covered all convention issues however so if you think of another convention please include it in your reply :slight_smile:

I like to separate static members and put them on top.


private static final int NAME_SPACE = 0;
private static int name_space;

private int nameSpace;

Haha whoops i totally forgot that I do that as well. I edited my main post hahaha

I like braces on their own lines. My brain needs a lower information density on screen.

Other than that I try to stick to what Sun had defined long ago. I hope Oracle hasn’t changed too much of those in the meantime … if you work with other people it’s best to have some sort of official standartd.

http://www.oracle.com/technetwork/java/codeconvtoc-136057.html

Prepare for your java eyes to bleed, I feel that I should be able to tell what something is based off my convention, so I don’t camelCase everything. I also dislike writing “this”, but for inheritance I make sure to use “super” for clarity. However, I also don’t go so far as to define the data type in variable names. Anyway bring on the hate.

public class NameSpace 
{

   private static final int NAME_SPACE = 0;//Not really sure what I do here, I'd have to look, but I think this is it...

   private static int sm_name_space;

   private int m_name_space;
   
   private float m_float_test = 0.1f;
   private double m_double_test = 0.1;
   
   private void nameSpace(int name_space)
   {
      sm_name_space = name_space;
   }
   
   public static int nameSpace(boolean name_space_bool)
   {
      return name_space_bool ? 1 : m_name_space;
   }
   
   public void lotsOfIfs()
   {
      if(m_name_space < 1)
      {
        m_name_space = 1;
      } 
      else if(m_name_space > 1)
      {
         m_name_space = 2;
      } 
      else
      {
         m_name_space = 0;
      }
   }
   
   private int someMath(int a, int b)
   {
      return (a * b) + (a / b) - (a * a);//I wouldn't always add parenthesis, just when the formula is difficult to read without them.
   }
   
}

Mine are a mix from C/C++, Java and C#.

[] Use only 4 SPACES to indent code
[
] Keep braces on their own line
[] Indent names of variables so equals signs are at same level
[
] Lower camel case for methods and variables (Upper camel case in C++/C#)
[] No m_ prefix for variables (Only in except C++)
[
] Spaces after keywords if/else/do/while
[] Short hand syntax of if will have the statement on next line
[
] Indent the case statements in switch
[] Don’t use blocks for case statements.
[
] In OpenGL, add a block for statements between a glBegin and glEnd (I simulate them)