HelloWorld class that
we didn't get to, we won't be going over it today.
let.
block command in scheme.
if
statement. In most imperative languages, if
selects between two alternative sequences of actions (or decides
whether or
not to execute a single alternative) based on the value of
a boolean expression.
do loop of scheme.
public)
class and
the name of the class. Custom says that we capitalize the names
of classes.
class
with public.
public we use with the class).
boolean, for true/false values
char, for characters (unlike many other languages,
Java officially supports more than just the basic American
set; it has built-in support for full Unicode)
byte, for very small integers in the range
short, for small integers in the range
int, for integers in the approximate range
long, for integers in a much bigger range
float, for numbers that may have a fractional
component (e.g., 10.32533).
double, for better accuracy
public class Complex {
double real_part;
double imaginary_part;
}
Complex has two fields, each of
type double.
class-name variable-name = new class-name()
Complex c1 = new Complex()
return statement).
public class Complex {
double real_part;
double imaginary_part;
public void setValue(double rpart, double ipart) {
real_part = rpart;
imaginary_part = ipart;
}
public double getReal() {
return real_part;
}
public double getImaginary() {
return imaginary_part;
}
}
main method, which is where
the interpreter begins. main has type void
and must be public and static. It takes
one parameter, an array of strings.
main routine for our sample class
public static void main(String[] args) {
Complex c1 = new Complex();
System.out.print("Initially, the real part is ");
System.out.println(c1.getReal());
System.out.print("Initially, the imaginary part is ");
System.out.println(c1.getImaginary());
c1.setValue(1.0,3.4);
System.out.print("Now, the real part is ");
System.out.println(c1.getReal());
System.out.print("Now, the imaginary part is ");
System.out.println(c1.getImaginary());
}
Chair, that includes at least one attribute,
serial_number, of type int,
and at least two methods,
setNumber(), which sets the number,
getNumber(), which returns the number.
main() routine to the class which creates two
chairs, gives them serial numbers, and then prints out the
serial numbers.
Chair.getNumber()?
ugly.main(), where
ugly is an object of class Chair?
Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
Source text last modified Wed Nov 5 12:35:58 1997.
This page generated on Wed Nov 5 12:38:51 1997 by SiteWeaver.
Contact our webmaster at rebelsky@math.grin.edu