171 Java Command Reference

Class Structure:

public class MyClassName
{
     // you can define a class variable here
     public static void main( )
     {

           // your statements will go here
           // your calls to method1 will have the form: method1()
     }
     public static void method1( )
     {

           // your statements will go here
     }
}

Create variables

Assign values to variables:

Compare values:

Decisions

Loops (Repeat)

Make methods:

Use methods

Make classes:

Use classes

Print to the screen:

Comments:

Read from screen:

Syntax rules

Tracing

Details on some classes we used:

Scanner: import java.util.*;
create instance: Scanner x = new Scanner(System.in);
call methods: int y = x.next();

Random: import java.util.Random;
create instance: Random x = new Random();
call methods: int y = x.nextInt(6);

Decimal Format: Library: import java.text.DecimalFormat; ---> (we did not use this much)
Create instance: DecimalFormat percentage2 = new DecimalFormat(“0.00%”);
Call methods: System.out.println(percentage2.format(.308)); // will print 30.80

0 = required position
# = show it if you have it
% = make it a % (mult by 100)
E = E notation (scientific)

String:

Math:

Graphics:

Picture It