SLIDE 1 Programming
What is a program?
A set of instructions Understood by a computer
SLIDE 2 What does a program look like?
An algorithm is a set of instructions designed to
accomplish a specific goal
For a temperature f in Fahrenheit
Subtract 32 from f. Divide f by 1.8. Display the value of f. [Converts to Celsius]
Don’t need to understand the goal to follow
instructions
SLIDE 3 Programming Languages
A language is a tool with which we tell a
computer an algorithm
Compilers translate from one computer language
to another
Each language has own advantages and
disadvantages
SLIDE 4 What is Alice?
A programming environment.
SLIDE 5 What is Alice?
A programming language. A library of graphic objects
SLIDE 6
What is Alice?
A tool for running animations
SLIDE 7 What about JAVA?
BlueJ - a programming environment designed to
teach programming
SLIDE 8 The Java Language
A programming language (Widely Used) Can be compiled on many computer systems
public class TouchyWindow extends WindowController { public void onMousePress ( Location point ) { new Text("I’m touched", 40, 50, canvas ); } public void onMouseRelease( Location point ) { canvas.clear(); } }
SLIDE 9 What about Java?
A huge library, but less visual
2D Graphical shapes - circles, lines, … User interface elements - buttons, sliders, … Networking Image manipulation Many, many things
A tool for running a wide range of applications
SLIDE 10
SLIDE 11
SLIDE 12
SLIDE 13
Methods in Java
public class TouchyWindow extends WindowController { public void onMousePress ( Location point ) { new Text("I’m touched", 40, 50, canvas ); } public void onMouseRelease( Location point ) { canvas.clear(); } }
SLIDE 14 Types
Number Boolean Object int double boolean Penguin Location Train …
SLIDE 15
Event Handling
In Alice:
In Java: public class TouchyWindow extends WindowController { public void onMousePress ( Location point ) { new Text("I’m touched", 40, 50, canvas ); } public void onMouseRelease( Location point ) { canvas.clear(); } }
SLIDE 16 Creating Objects
In Alice: In Java:
In Java: public class TouchyWindow extends WindowController { public void onMousePress ( Location point ) { new Text("I’m touched", 40, 50, canvas ); } public void onMouseRelease( Location point ) { canvas.clear(); } }
SLIDE 17
Anatomy of a Java Class: set, collection group, or configuration containing members regarded as having certain attributes or traits in common
import objectdraw.*; import java.awt.*; public class TouchyWindow extends WindowController { public void onMousePress ( Location point ) { new Text("I’m touched", 40, 50, canvas ); } public void onMouseRelease( Location point ) { canvas.clear(); } }
Method Instruction parameter class
SLIDE 18 Coordinate system
Coordinates measure pixels, the smallest dot of
color a display can make
SLIDE 19
Methods and Constructors
public class TouchyWindow extends WindowController { public void onMousePress ( Location point ) { new Text("I’m touched", 40, 50, canvas ); } public void onMouseRelease( Location point ) { canvas.clear(); } }
Constructor call Method call
SLIDE 20 Graphical Objects
new Text ( "I’m Touched", 40, 50, canvas );
new an instruction that tells we want to construct
a new object
Text the object we want to construct (…) comma delineated “parameters” that tell how
to construct the object
; semicolons are important too!
every command semicolon terminated
SLIDE 21
Graphical Objects
new Text ( "I’m Touched", 40, 50, canvas );
SLIDE 22 Events
In Alice, need to specify which method to call when an event occurs Java: public void onMousePress( Location point )
Will run the code when mouse button is pressed
onMouseRelease:
Runs code when the buttons released
Many more mouse event handling methods
SLIDE 23 Summary
Many similarities in programming concepts Alice - limited to creating animations Java - wide applicability Alice programming environment - menu,
drag&drop eliminates syntax errors, but clumsy
Java programming environment - less clumsy, but
requires learning syntax