html5-img
1 / 40

מבוא למדעי המחשב

מבוא למדעי המחשב. Lesson A - Introduction. Unit A1 – About This Course . מבוא למדעי המחשב. מרצה: נעם ניסן שעת קבלה: ג’ 2:00-3:00 (בנין רוס, חדר 218) מתרגלים: ניר שרוני, מיכאל אוקון, מעאוויה עקש אתר הקורס: www.cs.huji.ac.il/~intro2cs ספר הקורס: Java software solutions / Lewis & Loftus.

ilar
Download Presentation

מבוא למדעי המחשב

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. מבוא למדעי המחשב

  2. Lesson A - Introduction Unit A1 – About This Course

  3. מבוא למדעי המחשב מרצה: נעם ניסן שעת קבלה: ג’ 2:00-3:00 (בנין רוס, חדר 218) מתרגלים: ניר שרוני, מיכאל אוקון, מעאוויה עקש אתר הקורס:www.cs.huji.ac.il/~intro2cs ספר הקורס: Java software solutions / Lewis & Loftus

  4. רמות הפשטה מרובות: ממשק ומימוש הנדסת תוכנה קורסים:מעבדת תכנות, מבני נתונים מערכות חישוב ותוכנה קורסים:מיתוג, מסדי נתונים, מערכות הפעלה אלגוריתמים קורסים:אלגוריתמים, חישוביות מבני נתונים קורסים:מבני נתונים, מסדי נתונים שפה ומשמעות קורסים:מתמטיקה, לוגיקה, חישוביות, שפות תכנות, מהדרים תוכן הקורס:תכנות נכון בשפת Java. מטרות הקורס:

  5. תכנות מונחה עצמים: שימוש באובייקטים כתיבת אובייקטים ירושה ממשקים שיטות תכנות: רקורסיה מבני נתונים דינמיים תבניות ממשק משתמש אלמנטים בסיסיים: מבנה התוכנית וניסוחה משתנים וביטוים פקודות בחירות לולאות מערכים חריגות תיאוריה: ניתוח זמן ריצה מה ניתן לחישוב נושאי הקורס

  6. דרישות הקורס • תרגיל תכנות כל שבוע (לפעמים כל שבועיים). • הרבה עבודה. אין ברירה. • מומלץ לדון עם חברים • אסור!!!!! להעתיק • הבחנה: דיון = דיבורים בעל פה -- אין הכנסה או הוצאה של חומר כתוב או מודפס. • מבחן • ציון סופי: 50/50 • ציון תרגילים יחושב בהתעלמות מציון תרגיל נמוך ביותר

  7. תלמידים ללא רקע תכנותי • הקורס מיועד לכם (וגם למי שיש לו רקע) • חודש ראשון יהיה קשה מאוד (קצת משעמם למי שיש רקע) • עד סוף הקורס צפוי "יישור קו" של כולם • מנגנוני עזרה: • שעור עזר במהלך חודש ראשון • שלישי 20:00-18:00 פלדמן א • ייעוץ במעבדות • רשימת תורנות http://www.cs.huji.ac.il/~intro2cs/toranot.html • שעות קבלה • קבוצת דיון

  8. Lesson A - Introduction Unit A2 - Introduction to Hardware

  9. Our abstraction of a computer Screen Keyboard Java Program Data CPU Memory

  10. Computer Organization Overview Modem Screen Keyboard Disk Bus Software Operating System Compiler Our Program CPU … Data Random Access Memory

  11. Binary Representations • Digital Computers only deal with 0 and 1 • We don’t care (mostly) • Anything can be represented by sequences of 0 and 1: • Integers: • 13 = “0000 1101”, 14 = “0000 1110” … • Characters: • ‘A’ = “0010 0001”, ‘B’ = “0010 0010” ... • The number of bits determines the number of items that can be represented • 2 bits give 4 combinations (00, 01, 10, 11) • 8 bits (a byte) give 256 combinations • 32 bits (a word) give more than 4,000,000,000 combinations

  12. An Example PC Specification • 1.1 GHz Pentium IV Processor • 256 MB RAM • 20 GB Hard Disk • 17” Display with 1280 x 1024 resolution • 56 KB Modem

  13. More about Hardware • Much more to learn • Not the topic of this course • Other courses deal with computer hardware • Digital Systems course • Computer Architecture course • Digital Communications course • Advanced courses • In this course, we stick with our abstraction

  14. Lesson A - Introduction Unit A3 – Introduction to Software

  15. Problems and Algorithms • We need to solve a computational problem • “Simulate an Boeing 767 airplane” • “Convert a weight in pounds to Kg” • An algorithm specifies how to solve it, e.g.: 1. Read weight-in-pounds 2. Calculate weight-in-Kg = weight-in-pounds * 0.455 3. Print weight-in-Kg • Computers must be given exact instructions • A computer program is a computer-executable description of an algorithm

  16. Machine languages • Each processor has its own machine language • An assembly language is a human-readable form of the machine language load R7, value jgt label3 add R7, bonus 0100 0111 1101 0011 ... 0101 1011 0110 0111 ... 0110 0111 1010 1100 ...

  17. High Level Languages • Humans prefer programming in a high level language • A compiler can translate to machine language • A Interpreter can execute high-level code load R7, value jgt label3 add R7, bonus If (value < 0) value = value + bonus Compilation

  18. Operating Systems • Provides hardware-dependant services in a hardware-independent way • Used by application programs • OS services to users • Files • Printing • Communication • Running programs • OS services to application programs • All of the above • Memory Management • User Interface • Processes

  19. Lesson A - Introduction Unit A4 – First Java Program

  20. The Java Programming Language • Invented 1995 by James Gosling at Sun Microsystems. • Based on previous languages: C, C++, Objective-C, … • Intended to be a safe programming language for the Internet • Common choice for first programming language • Object oriented • Encourages good programming habits • Very popular commercially • Simpler and more elegant than C++, but similar to it • Cool

  21. Hello World Program // My First Program!! publicclass HelloWorld { public static void main(String[] args){ System.out.println(“Hello World!”); } }

  22. Java Program Elements • Words • Keywords • Identifiers • Constants • Numbers • Strings • Symbols • ( ) [ ] { } , . ; + - * / • Comments

  23. Java Elements Comment Symbols Identifier // My First Program!! publicclass HelloWorld { public static void main(String[] args){ System.out.println(“Hello World!”); } } Keywords String Constant

  24. Java Program Structure • A program is composed of a collection of classes • Each class contains a collection of methods • Each method is composed of a sequence of instructions (commands, statements)

  25. Java Program Structure Class Method // My First Program!! publicclass HelloWorld { public static void main(String[] args){ System.out.println(“Hello World!”); } } Instruction

  26. Lesson A - Introduction Unit A5 – Running Your Program

  27. Running a Java Program • Use an editor to enter (type) the program • Save to a file named HelloWorld.java • Use the compiler to translate the program into bytecode • javac HelloWorld.java • This produces a file named HelloWorld.class • Run the program using the Interpreter • java HelloWorld

  28. Java Compilation Xxx.java Xxx.class Compiler Interpreter Output

  29. Entering a Java Program into an Editor

  30. Running a Java Program

  31. Integrated Development Environments (IDE) • Include a combination of: • Editor • Compiler • Debugger • Project Management • Some Commercial IDEs • Sun Forte • IBM Visual Age • Borland Jbuilder • …

  32. Forte – Screen Capture

  33. Debugging • You will make many errors! • Most of your time will be spent finding them and correcting them -- debugging. • There are several types of errors: • Syntax errors • detected at compilation time • Run-time errors • the program runs and crashes • Logical errors • the program does something other than what you want it to do • It does exactly what you told it to do • The earlier an error is caught, the easier it is to correct

  34. Lesson 1 - Introduction Unit A6 – Introduction to Objects

  35. Large Programs • Commercial software may require millions of lines of code • Humans can only handle about 7 things together • To construct large programs: • break the program into components • then break each component, etc. • When you use a component you only use its abstraction. • When you construct a component you forget about the rest of the program.

  36. Interfaces • The interface of a software component is an exact definition of what it can do • It does not address how it does what it does • When you use a component you only consider its interface • A good component will have a clear, narrow interface

  37. Objects • Objects are the basic components in Java • An object has an interface and an internal state. • The interface encapsulates (hides) the internal operation • The interface specifies the services the object provides Object A that uses Object B Object B

  38. A Turtle Object

  39. A Turtle Object • A Turtle object represents a turtle that walks on the screen with a pen on its tail • Turtle object interface: • moveForward(distance) • moveRight(degrees) • moveLeft(degrees) • tailUp() • tailDown() • Turtle object internal state • Location on screen • Direction facing • Tail is up or down

  40. Using a Turtle public class TurtleDrawing { public static void main(String[] args){ Turtle leonardo = new Turtle(); leonardo.tailDown(); leonardo.moveForward(100); leonardo.turnRight(60); leonardo.moveForward(100); } }

More Related