QandA/survey.html
(starting with
the course root).
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()); }
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 Mon Nov 10 08:56:25 1997.
This page generated on Mon Nov 10 10:13:17 1997 by SiteWeaver.
Contact our webmaster at rebelsky@math.grin.edu