Java Code Templates

From PeacockWiki

Revision as of 09:21, 7 November 2005; Trevorp (Talk | contribs)
(diff) ←Older revision | Current revision | Newer revision→ (diff)
Jump to: navigation, search

Creating an Object

= new ();

eg.

String myString = new String("MyStringValue");




Calling a method of a object

.();




Creating and instantiating an array

[];
= new [];


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.
  ++
}



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(condition)
{
}

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)




Naming Conventions

Class names start with caps

Class MyClass
{
}

Variable names start with lowercase

MyClass myVariable;


Method Names start with lowercase

public void myMethod()
{
}
Personal tools