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
javadoc /** Something here */
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:
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
/**
* This class will be used to display a message than do somethign even cooler
* @author Jeff Boralnd
* @version 4.34.3
*/
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
}
}
}
As opposed to BAD coding:
import java.applet.Applet;
import java.awt.Graphics;
public class helloworld1 extends Applet
{
public void paint(Graphics g)
{ g.drawString("Hello world!", 50, 25);
int a=0;
if (a>5)
{
}
else
{
}}}