Programming What is a program? A set of instructions Understood by a computer
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
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
What is Alice? A programming environment.
What is Alice? A programming language. A library of graphic objects
What is Alice? A tool for running animations
What about JAVA? BlueJ - a programming environment designed to teach programming
The Java Language A programming language (Widely Used) 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(); } } Can be compiled on many computer systems
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
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(); } }
Types Number int double Boolean boolean Object Penguin Location Train …
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(); } }
Creating Objects In Java: 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(); } }
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 { parameter public void onMousePress ( Location point ) { new Text("I’m touched", 40, 50, canvas ); Instruction } Method public void onMouseRelease( Location point ) { canvas.clear(); } class }
Coordinate system Coordinates measure pixels, the smallest dot of color a display can make
Methods and Constructors public class TouchyWindow extends WindowController { public void onMousePress ( Location point ) { Constructor call new Text("I’m touched", 40, 50, canvas ); } public void onMouseRelease( Location point ) { canvas.clear(); Method call } }
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
Graphical Objects new Text ( "I’m Touched", 40, 50, canvas );
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
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
Recommend
More recommend