Java Code Templates

From PeacockWiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 09:21, 7 November 2005 (edit)
Trevorp (Talk | contribs)

← Previous diff
Current revision (09:48, 7 November 2005) (edit)
Trevorp (Talk | contribs)
(Re-arrange and add sections)
 
Line 1: Line 1:
-Creating an Object+==Naming Conventions==
 +===Class names start with caps===
 + Class MyClass
 + {
 + }
 + 
 +===Variable names start with lowercase===
 + MyClass myVariable;
 + 
 +===Method Names start with lowercase===
 + public void myMethod()
 + {
 + }
 + 
 +==Objects==
 +===Creating an Object===
= new (); = new ();
Line 5: Line 20:
String myString = new String("MyStringValue"); String myString = new String("MyStringValue");
- +===Calling a method of a object===
---------------------------------------------------------------------------------+
- +
- +
-Calling a method of a object+
- +
.(); .();
- +==Arrays==
---------------------------------------------------------------------------------+===Creating and instantiating an array===
- +
- +
-Creating and instantiating an array+
- +
[]; [];
= new []; = new [];
---------------------------------------------------------------------------------+==Loops==
- +===For Loops===
- +
-For Loops+
- +
for(assignment;comparator;incrementer) for(assignment;comparator;incrementer)
{ {
Line 36: Line 39:
do something here; do something here;
} }
- 
this for loop is equivilant to the following while loop this for loop is equivilant to the following while loop
Line 47: Line 49:
} }
- +===Pre-Tested===
- +
---------------------------------------------------------------------------------+
- +
-Loops+
- +
While is a "pre-tested" loop. The condition is tested before the code block is executed. As a result, it is possible that the code block will never execute. While is a "pre-tested" loop. The condition is tested before the code block is executed. As a result, it is possible that the code block will never execute.
Line 59: Line 56:
} }
 +===Post-Tested===
Do is a "post-tested" loop. The condition is tested after the code block is executed. As a result, the code block will always execute at least once. Do is a "post-tested" loop. The condition is tested after the code block is executed. As a result, the code block will always execute at least once.
Line 65: Line 63:
} }
while(condition) while(condition)
- 
- 
--------------------------------------------------------------------------------- 
- 
- 
- 
-Naming Conventions 
- 
-Class names start with caps 
- 
- Class MyClass 
- { 
- } 
- 
-Variable names start with lowercase 
- 
- MyClass myVariable; 
- 
- 
-Method Names start with lowercase 
- 
- public void myMethod() 
- { 
- } 

Current revision

Contents

Naming Conventions

Class names start with caps

Class MyClass
{
}

Variable names start with lowercase

MyClass myVariable;

Method Names start with lowercase

public void myMethod()
{
}

Objects

Creating an Object

= new ();

eg.

String myString = new String("MyStringValue");

Calling a method of a object

.();

Arrays

Creating and instantiating an array

[];
= new [];

Loops

For Loops

for(assignment;comparator;incrementer)
{
  do something here;
}
for( = ; [<] ; ++)
{
  do something here;
}

this for loop is equivilant to the following while loop

=
While( [<] )
{
  do something here.
  ++
}

Pre-Tested

While is a "pre-tested" loop. The condition is tested before the code block is executed. As a result, it is possible that the code block will never execute.

while(condition)
{
}

Post-Tested

Do is a "post-tested" loop. The condition is tested after the code block is executed. As a result, the code block will always execute at least once.

do
{
}
while(condition)
Personal tools