programming and problem solving
play

Programming and Problem Solving Introduction to the Course Spring - PowerPoint PPT Presentation

Dennis Komm Programming and Problem Solving Introduction to the Course Spring 2019 February 18, 2019 Welcome to the Course Material Lecture website http://lec.inf.ethz.ch/ppl Programming and Problem Solving Introduction to the Course


  1. Java Java is based on a virtual machine (with von Neumann architecture) program code is tranlated to intermediate code Intermediate code runs a simulated environment, interpreted through special interpreter Optimization: Just-in-Time (JIT) compilation of frequently used code: virtual machine ➯ physical machine Implication and declared goal of the Java developers: portability “write once – run anywhere” Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 13 / 52

  2. Introduction to the Course Project

  3. Ready, Set, Go! learning curve You have seven weeks to complete a non-trivial project After the first few weeks you will already know the basic concepts, to implement the project 1 2 3 4 5 6 7 Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 14 / 52

  4. Ready, Set, Go! learning curve You have seven weeks to complete a non-trivial project After the first few weeks you will already know the basic concepts, to implement the project project 1 2 3 4 5 6 7 Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 14 / 52

  5. Java Tutorial In the first weeks, you independently work on our Java tutorial Easy introduction to Java, no previous knowledge necessary Time needed: roughly two hours In the second week, there will be a self-assessment Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 15 / 52

  6. Java Tutorial In the first weeks, you independently work on our Java tutorial Easy introduction to Java, no previous knowledge necessary Time needed: roughly two hours In the second week, there will be a self-assessment ➯ This time is well invested Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 15 / 52

  7. Java Tutorial In the first weeks, you independently work on our Java tutorial Easy introduction to Java, no previous knowledge necessary Time needed: roughly two hours In the second week, there will be a self-assessment ➯ This time is well invested Tutorial website https://frontend-1.et.ethz.ch/sc/WKrEKYAuHvaeTqLzr Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 15 / 52

  8. Project You choose a project from a list of predefined projects The project is worked on independently Pattern: Data ➯ read in ➯ process ➯ output Information is continuously updated on course website Exericse: Wednesday, 17–18, HG 26.5 (right after the lecture) Supervised by Moritz Hoffmann , CAB F 69 ( moritz.hoffmann@inf.ethz.ch ), office hours: Monday, 15–17 Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 16 / 52

  9. Project – Team Work is Key You work in teams of two Both partners contribute provably half Projects are graded per team Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 17 / 52

  10. Project – Team Work is Key You work in teams of two Both partners contribute provably half Projects are graded per team ➯ Contact us as soon as there are any problems or disagreements Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 17 / 52

  11. Project – Milestones Milestones have to be complied with Compliance with the milestone will be part of the grade Every milestone corresponds to some output (document or code) Week 2 Week 3 Week 6 Week 7 Team assembled Project plan All features Handing in all Project chosen handed in ready materials Tools installed Solution design Test plan done Presentation fixed First GIT commit Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 18 / 52

  12. Graded Semester Performance Presentation of the project on April 3 and 10 Duration: Around 10 minutes, depending on the number of projects handed in Handing in all materials All milestones have to be complied with Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 19 / 52

  13. Discussion Platform You can sign in to our Slack forum https://bit.ly/2UXaWzg General discussion of course Search for team partners . . . Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 20 / 52

  14. Introduction to Java

  15. Programming Tools Editor: Program to modify, edit and store Java program texts Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 21 / 52

  16. Programming Tools Editor: Program to modify, edit and store Java program texts Compiler: Program to translate a program text into machine language (intermediate code, respectively) Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 21 / 52

  17. Programming Tools Editor: Program to modify, edit and store Java program texts Compiler: Program to translate a program text into machine language (intermediate code, respectively) Computer: Machine to execute machine language programs Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 21 / 52

  18. Programming Tools Editor: Program to modify, edit and store Java program texts Compiler: Program to translate a program text into machine language (intermediate code, respectively) Computer: Machine to execute machine language programs Operating System: Program to organize all procedures such as file handling, editing, compiling, and program execution Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 21 / 52

  19. English vs. Programming Language English “Science is what we understand well enough to explain to a computer. Art is everything else we do. ” D ONALD K NUTH Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 22 / 52

  20. English vs. Programming Language English “Science is what we understand well enough to explain to a computer. Art is everything else we do. ” D ONALD K NUTH Java / C / C++ // computation int b = a * a; // b = a^2 b = b * b; // b = a^4 Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 22 / 52

  21. Syntax and Semantics Like our language, programs have to be formed according to certain rules Syntax: Connection rules for elementary symbols (characters) Semantics: Interpretation rules for connected symbols Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 23 / 52

  22. Syntax and Semantics Like our language, programs have to be formed according to certain rules Syntax: Connection rules for elementary symbols (characters) Semantics: Interpretation rules for connected symbols Corresponding rules for a computer program are simpler but also more strict because computers are relatively stupid Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 23 / 52

  23. Kinds of Errors Illustrated with English Language The car drove too fast. Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 24 / 52

  24. Kinds of Errors Illustrated with English Language The car drove too fast. Syntactically and semantically correct Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 24 / 52

  25. Kinds of Errors Illustrated with English Language The car drove too fast. Syntactically and semantically correct Thecar drove too fsat. Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 24 / 52

  26. Kinds of Errors Illustrated with English Language The car drove too fast. Syntactically and semantically correct Thecar drove too fsat. Syntax error: word building Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 24 / 52

  27. Kinds of Errors Illustrated with English Language The car drove too fast. Syntactically and semantically correct Thecar drove too fsat. Syntax error: word building Red the car is. Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 24 / 52

  28. Kinds of Errors Illustrated with English Language The car drove too fast. Syntactically and semantically correct Thecar drove too fsat. Syntax error: word building Red the car is. Syntax error: word order Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 24 / 52

  29. Kinds of Errors Illustrated with English Language The car drove too fast. Syntactically and semantically correct Thecar drove too fsat. Syntax error: word building Red the car is. Syntax error: word order I find inspiration in cooking my dog and my cat Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 24 / 52

  30. Kinds of Errors Illustrated with English Language The car drove too fast. Syntactically and semantically correct Thecar drove too fsat. Syntax error: word building Red the car is. Syntax error: word order I find inspiration in cooking , my dog , Syntax error: missing punctuation marks and my cat . Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 24 / 52

  31. Kinds of Errors Illustrated with English Language The car drove too fast. Syntactically and semantically correct Thecar drove too fsat. Syntax error: word building Red the car is. Syntax error: word order I find inspiration in cooking my dog Syntax error: missing punctuation marks and my cat She is not tall and red-haired. Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 24 / 52

  32. Kinds of Errors Illustrated with English Language The car drove too fast. Syntactically and semantically correct Thecar drove too fsat. Syntax error: word building Red the car is. Syntax error: word order I find inspiration in cooking my dog Syntax error: missing punctuation marks and my cat She is not tall and red-haired. Syntactically correct, but ambiguous [no analogon] Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 24 / 52

  33. Kinds of Errors Illustrated with English Language The car drove too fast. Syntactically and semantically correct Thecar drove too fsat. Syntax error: word building Red the car is. Syntax error: word order I find inspiration in cooking my dog Syntax error: missing punctuation marks and my cat She is not tall and red-haired. Syntactically correct, but ambiguous [no analogon] I own an red car. Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 24 / 52

  34. Kinds of Errors Illustrated with English Language The car drove too fast. Syntactically and semantically correct Thecar drove too fsat. Syntax error: word building Red the car is. Syntax error: word order I find inspiration in cooking my dog Syntax error: missing punctuation marks and my cat She is not tall and red-haired. Syntactically correct, but ambiguous [no analogon] Syntactically correct, but gramatically and semanti- I own an red car. cally wrong: wrong article [type error] Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 24 / 52

  35. Kinds of Errors Illustrated with English Language The car drove too fast. Syntactically and semantically correct Thecar drove too fsat. Syntax error: word building Red the car is. Syntax error: word order I find inspiration in cooking my dog Syntax error: missing punctuation marks and my cat She is not tall and red-haired. Syntactically correct, but ambiguous [no analogon] Syntactically correct, but gramatically and semanti- I own an red car. cally wrong: wrong article [type error] The bike gallops fast. Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 24 / 52

  36. Kinds of Errors Illustrated with English Language The car drove too fast. Syntactically and semantically correct Thecar drove too fsat. Syntax error: word building Red the car is. Syntax error: word order I find inspiration in cooking my dog Syntax error: missing punctuation marks and my cat She is not tall and red-haired. Syntactically correct, but ambiguous [no analogon] Syntactically correct, but gramatically and semanti- I own an red car. cally wrong: wrong article [type error] Syntactically and gramatically correct, but semanti- The bike gallops fast. cally wrong [run-time error] Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 24 / 52

  37. Kinds of Errors Illustrated with English Language The car drove too fast. Syntactically and semantically correct Thecar drove too fsat. Syntax error: word building Red the car is. Syntax error: word order I find inspiration in cooking my dog Syntax error: missing punctuation marks and my cat She is not tall and red-haired. Syntactically correct, but ambiguous [no analogon] Syntactically correct, but gramatically and semanti- I own an red car. cally wrong: wrong article [type error] Syntactically and gramatically correct, but semanti- The bike gallops fast. cally wrong [run-time error] We saw her duck. Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 24 / 52

  38. Kinds of Errors Illustrated with English Language The car drove too fast. Syntactically and semantically correct Thecar drove too fsat. Syntax error: word building Red the car is. Syntax error: word order I find inspiration in cooking my dog Syntax error: missing punctuation marks and my cat She is not tall and red-haired. Syntactically correct, but ambiguous [no analogon] Syntactically correct, but gramatically and semanti- I own an red car. cally wrong: wrong article [type error] Syntactically and gramatically correct, but semanti- The bike gallops fast. cally wrong [run-time error] Syntactically and sematically correct, but ambiguous We saw her duck. [no analogon] Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 24 / 52

  39. Introduction to Java A First Java Program

  40. A First Java Program // input Out.print("Compute a^8 for a= ?"); int a; a = In.readInt(); // computation int b = a * a; // b = a^2 b = b * b; // b = a^4 // output b*b, i.e., a^8 Out.println(a + "^8 = " + b * b); Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 25 / 52

  41. A First Java Program public static void main(String[] args) { // input Out.print("Compute a^8 for a= ?"); int a; a = In.readInt(); // computation int b = a * a; // b = a^2 b = b * b; // b = a^4 // output b*b, i.e., a^8 Out.println(a + "^8 = " + b * b); } Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 25 / 52

  42. A First Java Program public class Main { public static void main(String[] args) { // input Out.print("Compute a^8 for a= ?"); int a; a = In.readInt(); // computation int b = a * a; // b = a^2 b = b * b; // b = a^4 // output b*b, i.e., a^8 Out.println(a + "^8 = " + b * b); } } Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 25 / 52

  43. A First Java Program public class Main { Class: a program Method: named sequence of public static void main(String[] args) { statements // input Out.print("Compute a^8 for a= ?"); int a; a = In.readInt(); // computation int b = a * a; // b = a^2 b = b * b; // b = a^4 // output b*b, i.e., a^8 Out.println(a + "^8 = " + b * b); } } Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 25 / 52

  44. Behavior of a Program At compile time Program accepted by the compiler (syntactically correct) Compiler error Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 27 / 52

  45. Behavior of a Program At compile time Program accepted by the compiler (syntactically correct) Compiler error During runtime correct result incorrect result program crashes program does not terminate (endless loop) Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 27 / 52

  46. Comments public class Main { public static void main(String[] args) { // input Out.print("Compute a^8 for a= ?"); int a; a = In.readInt(); // computation int b = a * a; // b = a^2 b = b * b; // b = a^4 // output b * b, i.e., a^8 Out.println(a + "^8 = " + b * b); } } Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 28 / 52

  47. Comments public class Main { public static void main(String[] args) { // input Comments Out.print("Compute a^8 for a= ?"); int a; a = In.readInt(); // computation int b = a * a; // b = a^2 b = b * b; // b = a^4 // output b * b, i.e., a^8 Out.println(a + "^8 = " + b * b); } } Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 28 / 52

  48. Comments and Layout The compiler does not care. . . public class Main{public static void main(String[] args){Out.print ("Compute a^8 for a= ?");int a;a = In.readInt();int b = a*a;b = b * b;Out.println(a + "^8 = " + b * b);}} Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 30 / 52

  49. Comments and Layout The compiler does not care. . . public class Main{public static void main(String[] args){Out.print ("Compute a^8 for a= ?");int a;a = In.readInt();int b = a*a;b = b * b;Out.println(a + "^8 = " + b * b);}} . . . but we do Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 30 / 52

  50. Introduction to Java Statements

  51. Statements public class Main { public static void main(String[] args) { // input Out.print("Compute a^8 for a= ?"); int a; a = In.readInt(); // computation int b = a * a; // b = a^2 b = b * b; // b = a^4 // output b*b, i.e., a^8 Out.println(a + "^8 = " + b * b); } } Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 31 / 52

  52. Statements public class Main { public static void main(String[] args) { // input Out.print("Compute a^8 for a= ?"); int a; a = In.readInt(); Expression statements // computation int b = a * a; // b = a^2 b = b * b; // b = a^4 // output b*b, i.e., a^8 Out.println(a + "^8 = " + b * b); } } Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 31 / 52

  53. Statements – Values and Effects public class Main { public static void main(String[] args) { // input Effect: Output of the string Compute ... Out.print("Compute a^8 for a= ?"); int a; a = In.readInt(); Effect: Input of number and store it in a // computation Effect: Store the computed value of a*a in b int b = a * a; // b = a^2 b = b * b; // b = a^4 Effect: Store the computed value of b*b in b // output b*b, i.e., a^8 Out.println(a + "^8 = " + b * b); Effect: Output of the value of a , the string ˆ8 = , and } the calculated value of b*b } Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 35 / 52

  54. Introduction to Java Declaration

  55. Variable Definitions public class Main { public static void main(String[] args) { // input Out.print("Compute a^8 for a= ?"); int a; a = In.readInt(); // computation int b = a * a; // b = a^2 b = b * b; // b = a^4 // output b*b, i.e., a^8 Out.println(a + "^8 = " + b * b); } } Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 37 / 52

  56. Variable Definitions public class Main { public static void main(String[] args) { // input Out.print("Compute a^8 for a= ?"); int a; Declaration statement a = In.readInt(); Type // computation names int b = a * a; // b = a^2 b = b * b; // b = a^4 // output b*b, i.e., a^8 Out.println(a + "^8 = " + b * b); } } Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 37 / 52

  57. Introduction to Java Variables and Objects

  58. Variables Variables represent (varying) values have name type value address are “visible” in the program context Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 42 / 52

  59. Variables Variables Example represent (varying) values int a; defines a variable with have name: a name type: int type value value: (initially) undefined address address: determined by are “visible” in the program context compiler Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 42 / 52

  60. Objects Objects represent values in main memory have type , address and value (memory content at the address) can be named . . . . . . but also anonymous Remark A program has a fixed number of variables. In order to be able to deal with a variable number of values, it requires “anonymous” addresses that can be addressed via temporary names. Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 43 / 52

  61. Introduction to Java Expressions

  62. Expressions Expressions represent computations Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 45 / 52

  63. Expressions Expressions represent computations are either primary ( b ) Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 45 / 52

  64. Expressions Expressions represent computations are either primary ( b ) or composed ( b * b ). . . Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 45 / 52

  65. Expressions Expressions represent computations are either primary ( b ) or composed ( b * b ). . . . . . from different expressions by operators Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 45 / 52

  66. Expressions // input Out.print("Compute a^8 for a= ?"); int a; a = In.readInt(); // computation int b = a * a; // b = a^2 b = b * b; // b = a^4 // output b * b, i.e., a^8 Out.println(a + "^8 = " + b * b ); Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 46 / 52

  67. Expressions // input Out.print("Compute a^8 for a= ?"); int a; a = In.readInt(); Variable name, primary expression // computation int b = a * a; // b = a^2 b = b * b; // b = a^4 Variable name, primary expression // output b * b, i.e., a^8 Out.println(a + "^8 = " + b * b ); Programming and Problem Solving – Introduction to the Course Spring 2019 Dennis Komm 46 / 52

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend