Top
Previous Next
Elements of the Java Platform CS 161 - Java

What the MyName Class demonstrates

 

 

 

Java starts by finding and running the method named main

 

 

public static void main(String[] arg)

 

 

 

String name defines a variable (or field)

 

  Notice where it is declared: inside the class but outside any method.

 

 

 

The name variable is associated with MyName objects

 

  These are called instance variables

 

 

 

You assign values to variables

 

  A variable (also called a field) is given a value using

destination = source expression;

 

 

 

You call methods

 

 

object_reference.method_name();

 

 

 

You generate output

 

 

System.out.println( [ a string ] )

 

 

 

Java forces you to check for possible exceptions

 

 

try {
 ...
} catch ( ... ) {
 ...
}

Top
Previous Next
jwd