[Instructions] [Search] [Current] [News] [Syllabus] [Glance] [Links] [Handouts] [Project] [Outlines] [Labs] [Assignments] [Quizzes] [Exams] [Examples] [EIJ] [JPDS] [Tutorial] [API]
Back to Introduction to Java. On to Lab: Objects and Methods.
Held Wednesday, January 26, 2000
Overview
Today, we ground our discussion of Java in practice, writing, compiling, and executing Java programs.
Notes
Contents
Summary
main method that directs the program
main method in some class
main method is the director of the ``play''
that is an object oriented program. As such it
Computer,
that does some computations.
/** // Introductory class comment
* A class that can perform some very
* simple computations.
*/ // End of introductory comment
public class Computer // Class declaration
{ // Start body of class
/** // Method comment
* Compute the square of X.
*/ // End of method comment
public int square(int X) // Method declaration
{ // Start of method body
return X*X; // Return a value
} // int square(int) // End of method body
/**
* Compute the absolute value of X.
*/
public int absoluteValue(int X)
{
if (X < 0) // Conditional
return -X;
else
return X;
} // absoluteValue(int)
} // class Computer // End body of class
ProgramTwo, uses the a
Computer to compute some values.
import Computer;
import SimpleOutput;
/**
* Print the results of some simple computations.
*/
public class ProgramTwo
{
public static void main(String[] args)
{
SimpleOutput output = new SimpleOutput();
Computer hal = new Computer();
int value = -5;
output.println(value + " squared is " + hal.square(value));
output.println("|" + value + "| is " + hal.absoluteValue(value));
} // main(String[])
} // class ProgramTwo
output, hal).
+ operation.
I'll spend a few minutes taking general questions about the lab before we begin.
ClassName.java.
/home/rebelsky/bin/jc filename
/home/rebelsky/bin/ji filename
Do Lab J1 from Experiments in Java.
We'll spend a few minutes reflecting on what we learned today.
Tuesday, 18 January 2000
Wednesday, 26 January 2000
Back to Introduction to Java. On to Lab: Objects and Methods.
[Instructions] [Search] [Current] [News] [Syllabus] [Glance] [Links] [Handouts] [Project] [Outlines] [Labs] [Assignments] [Quizzes] [Exams] [Examples] [EIJ] [JPDS] [Tutorial] [API]
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.
This page may be found at http://www.math.grin.edu/~rebelsky/Courses/CS152/2000S/Outlines/outline.03.html
Source text last modified Wed Jan 26 08:30:37 2000.
This page generated on Sat Feb 19 16:08:21 2000 by Siteweaver. Validate this page's HTML.
Contact our webmaster at rebelsky@grinnell.edu