Java Code Templates
From PeacockWiki
(Difference between revisions)
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 |
[edit]
Naming Conventions
[edit]
Class names start with caps
Class MyClass { }
[edit]
Variable names start with lowercase
MyClass myVariable;
[edit]
Method Names start with lowercase
public void myMethod() { }
[edit]
Objects
[edit]
Creating an Object
= new ();
eg.
String myString = new String("MyStringValue");
[edit]
Calling a method of a object
.();
[edit]
Arrays
[edit]
Creating and instantiating an array
[]; = new [];
[edit]
Loops
[edit]
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. ++ }
[edit]
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) { }
[edit]
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)