Proper indentation/spacing - makes reading the code easier
Proper comments - allows you and future editors of code
to understand program (now and more importantly later)
big block comments /* something relevant*/
before a line // this is one line
Proper names - names for variables, methods and classes
should be appropriate
style for variables and methods is first word lower case
and future words upper case. monsterXValue or mouseCursorX
classes - first letter of first word and every other word
is capital, ie Person, or Picture or BookWorm
Below is the sample code:
// This applet displays helloworld to the screen
// Created 10/3/06 by Jeff Borland
import java.applet.Applet; //THIS IS NECESSARY TO BE INCLUDED FOR ALL APPLETS
import java.awt.Graphics; //THIS IS NECESSARY TO BE INCLUDED FOR ALL GRAPHIC IN APPLETS
public class HelloWorld1 extends Applet
{
// This method is called automatically and will paint text to the
// screen
public void paint(Graphics g)
{
// the code below will print out hello world to the screen
g.drawString("Hello world!", 50, 25);
int age=0;
if (age>5)
{
//do this
//do that
}
//age is less than or equal to 5 so do something else
else
{
//more stuff
}
}
}