CPS 1 - Spring, 1999 - Ramm 1/22/98 #4
- Announce
- Labs started yesterday (Thursday)
- Read Chapter 1 of Biermann
Chapt 1. An Introduction to Programming: Coding Decision Trees
- Heading for Java
- Book uses Pascal
- Ideas the same
- At lowest level, many similarities between Java & Pascal
- Pascal originally designed as a teaching language
- Read material in book and use Pascal guide
- Object Oriented Programming
- Treats everything as an Object
- Object has Data and Functions (Methods)
- Lawn mower Analogy
- Data: Location, Running, FuelLevel,
OilLevel, ThrottleSetting
- Methods: StartEngine, StopEngine, SetSpeed,
GoForward, GoBackward, TurnLeft, TurnRight
- Can go into much greater detail if desired
- Class Describes an Object in Java
- Two Ways of Using Java
- Stand Alone (like most traditional programs)
- Using Web as an Applet
- Will work with Applets in this Class
- Java Language
- Is simple and compact
- Smaller than C or C++
- However, for Practical Program
- Use many predefined Classes
- For effective use: experience
- Lots of grammar and detail
- Will have to memorize very little
- Understand and Know how to use
- Dump into the Water to Teach to Swim
- May be Bewildering at First
- Work with Examples
- Will seem Easy Later
- "Hello World" Demo
HelloWorld.java
hw.html
- Things to Note
- Program is a class
- Class contains data and methods
- Method init() always started for applets
- add statements (layout questions)
- Applet invoked through HTML file
- Program tested with Web Browser or appletviewer
- Demonstrate Use of Buttons
- Clicking on buttons can cause things to happen
- Triggers action method
- Car Diagnosis Demo
CarDx.java
car.html
- Important Pieces:
- action method
- events
- if statements
- return statements