templates for java programs
// created 11 2 1
most basic
public class Nn
{
public static void main( String[] args )
{
;
}
}
int, short x; (int)charCastedToInt;
float, double y; (float)intPromotedToFloat;
char z; z.toString( );
String aa; aa[ 0 ] // a char
boolean ab;
// comment follows
/*
multiline betwixt these
*/
int[ ] array = new int[ size ];
string[ ][ ] grid = new String[ rows ][ columns ];
Enum Name { fields, of, the, enumm } // these can be given other fields individually too
Name personVar = Name.fields; if ( personVar == Name.of ) action( );
Nn objectOfClassNn = new Nn( any_relevant, arguments );
object.field; object.method( );
if ( x == y )
action( );
else if ( condition( ) || x = 5 ) // nn OR mm, second will ALWAYS evaluate true as the assignment succeeded
{
action( );
batchProcess( );
}
else
action( );
do
action( );
while( condition( ) && !falseCondition( ) ); // and not
while ( true )
action( );
for ( begin, condition( ), step )
action( );
public class Nn
{
private/public/[none means package scope] dType var;
static private dType varA;
static dType functionsCanOnly( dType callOtherStatic ) // functions or methods of the objects they create
{
return callOtherStatic;
}
}
basic keyboard i/o
System.out.print( "nn" );
System.out.println( "nn" );
System.out.printf( "nn %x", varTypeX );
%c char
%d int decimal %o octal %x hex
%f float %e scientific notation, %g %a hex
%t time [look up specific formats required]
%n line separator
%% '%'
import java.util.Scanner; // program uses Scanner
Scanner input = new Scanner( System.in );
String courseName = input.nextLine(); // read a line of text