Saturday, January 11, 2014

Java Coding Conventions - Basics

Camel Case
All class names, method (subroutine) names and variable names must use came case. For example: MyClassName, myMethodName, myVariableName.

Note that:
  • Class names must begin with an upper case letter
  • Method and variable names must begin with a lower case letter
File name and Class name
The file name must be the same as your public class <Name>. For example and public class MyClassName

To make code easier to read and understand use a tab or 4 spaces for each “level” your code is indented.
Here is an example. Note how code is indented further in each time a new block of code starts. Also the end “}” aligns with where “{“ began.

Tip: In Eclipse you can use Source > Format to indent your code.

No comments: