1 / 22

Programming

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.

heinrichj
Download Presentation

Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming • What is a program? • A set of instructions • Understood by a computer

  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

  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

  4. The Java Language • Widely Used • Can be compiled on many computer systems • Object Oriented (we’ll learn what this means later)

  5. Event Driven Programming • Old programs would start with all input at once and run until completion • Event: An action, a mouse click, an item selected • Using events made easy in Java

  6. A First Program import objectdraw.*; import java.awt.*; public class TouchyWindow extends WindowController { publicvoid onMousePress ( Location point ) { new Text("I’m touched", 40, 50, canvas ); } public void onMouseRelease( Location point ) { canvas.clear(); } }

  7. What do all these words mean? • Let’s break the program apart

  8. Some of the words • Class • A set, collection, group, or configuration containing members regarded as having certain attributes or traits in common. (American Heritage Dictionary) • Very similar meaning in Java

  9. Software Libraries • Reuse code already written • extends • Builds upon an already written class • import • Allows the use of instructions written elsewhere

  10. Parts of a Class • Body • Enclosed in the curly braces found on the line “public class…” • Methods: publicvoid onMousePress ( Location point ) { new Text( "I’m touched", 40, 50, canvas ); }

  11. The Life of a Program • Write the Program • Translate the program into a language the computer understands • Run the Program

  12. Integrated Development Environments • Eclipse • Professional Programming Tool • TouchyWindow in Eclipse

  13. Integrated Development Environments • BlueJ • Designed to teach Java • TouchyWindow in BlueJ

  14. Integrated Development Environments • Eclipse and BlueJ: • Available on Windows, MacOS, Unix • Free and downloadable

  15. More Programming • Normal vs Graphics Coordinate Systems

  16. 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

  17. Graphical Objects new Text ( "I’m Touched", 40, 50, canvas );

  18. Events 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

  19. The begin Method public void begin(){ … } • begin method • Executed (run) exactly once for each program • Executed early in program’s life

  20. Graphical Objects new Line( 100, 150, 200, 0 canvas);

  21. Graphical Objects • New FilledRect( 10, 20, 30, 40, canvas ); • Creates a 30x40 rectangle • Upper left corner at (10,20) • new FilledOval( 10, 20, 30, 40, canvas); • Imagine a 30x40 rectangle at (10,20) • Draws the largest oval that can fit inside the imaginary rectangle

  22. Mistakes? Impossible! • Sadly, computers read what is written, not the intention. • Errors will often generate complaints from the IDE. • Some complaints are more informative than others

More Related