Welcome to CISC 101 Elements of Computing Science

  • Slides: 48
Download presentation
Welcome to CISC 101 Elements of Computing Science I ILC 213, Tuesdays and Thursdays

Welcome to CISC 101 Elements of Computing Science I ILC 213, Tuesdays and Thursdays 9: 00 am, May 2 to June 10 Prof. Alan Mc. Leod (mcleod@cs. queensu. ca) Goodwin Hall Rm. 550 TA – Lili Barbour (4 lb 3@qlink. queensu. ca) Spring 2006 CISC 101 - Prof. Mc. Leod 1

Course Web Site • Note that all my lecture slides are (or will be!)

Course Web Site • Note that all my lecture slides are (or will be!) on the web site: http: //www. cs. queensu. ca/home/cisc 101 spring • Site also has syllabus, lab exercises, and will have links to assignments when they have been written. Spring 2006 CISC 101 - Prof. Mc. Leod 2

Today • Introduction to course – – – Introduce TA? Introduce students! Overview of

Today • Introduction to course – – – Introduce TA? Introduce students! Overview of Syllabus Grading Textbook • What’s an algorithm? • What’s a program? • What is “Java” and why use it? Spring 2006 CISC 101 - Prof. Mc. Leod 3

Introductions All Round! • Can you log in? Go to course web site: www.

Introductions All Round! • Can you log in? Go to course web site: www. cs. queensu. ca/home/cisc 101 spring • (Later – try logging into Web. CT site). • Who wants to use a computer at home? • Who will use a textbook? • What’s your computer background? • What do you want to get out of this course? Spring 2006 CISC 101 - Prof. Mc. Leod 4

Lab/Tutorial • Lab is Jeffrey Hall 155 (basement) • When? Up to you! –

Lab/Tutorial • Lab is Jeffrey Hall 155 (basement) • When? Up to you! – Tuesday afternoon? – Wednesday? – Thursday afternoon? • No lab this week before our Thursday lecture. Spring 2006 CISC 101 - Prof. Mc. Leod 5

What is the Course About? • How to create algorithms. • How to build

What is the Course About? • How to create algorithms. • How to build a program from an algorithm. • How to use programming elements common to modern computer languages. • Provide a basic foundation for further development of your programming skills. • Having fun, whenever possible! Spring 2006 CISC 101 - Prof. Mc. Leod 6

Course Topics - Programming • Java basics – – – – Variable declaration Expressions

Course Topics - Programming • Java basics – – – – Variable declaration Expressions Conditionals Loops Input/Output (“I/O”) Methods Arrays … Spring 2006 CISC 101 - Prof. Mc. Leod 7

Course Topics - Generic • How to express a sequence of steps as an

Course Topics - Generic • How to express a sequence of steps as an algorithm. • How to code an algorithm so that a computer can carry out the steps. • Learn good coding style and how to create documentation. • Learn debugging techniques. • Writing efficient code. • Learn some useful algorithms. Spring 2006 CISC 101 - Prof. Mc. Leod 8

Grading • The scheme: 25% assignments 25% midterm 50% final exam Spring 2006 CISC

Grading • The scheme: 25% assignments 25% midterm 50% final exam Spring 2006 CISC 101 - Prof. Mc. Leod 9

What Else? • Keep an eye on the web site - especially the main

What Else? • Keep an eye on the web site - especially the main page. New content is frequently added, and the main page contains announcements. • Make sure I have your preferred E-mail address. • Any questions? Spring 2006 CISC 101 - Prof. Mc. Leod 10

What is an Algorithm? • An experiment: – Suppose we need to tell someone

What is an Algorithm? • An experiment: – Suppose we need to tell someone who has never washed socks before (like my 18 yr old son…) how to roll them up. – We know they have two hands and understand English. – No graphics allowed! Spring 2006 CISC 101 - Prof. Mc. Leod 11

Socks - Cont. • Observations – Not always easy to provide precise instructions! –

Socks - Cont. • Observations – Not always easy to provide precise instructions! – Parts of the instructions are repetitious - it is nice to have some mechanism to allow us to repeat some “blocks” of instructions. – Suppose we did such a good job with these instructions that we were hired to write similar instructions for other clothing items - it would be nice to re-use some parts of these instructions… – Anything else? Spring 2006 CISC 101 - Prof. Mc. Leod 12

So, What is an Algorithm? • We just developed one! • A set of

So, What is an Algorithm? • We just developed one! • A set of precise, unambiguous instructions that lead to the solution of a problem. Spring 2006 CISC 101 - Prof. Mc. Leod 13

What is a Program? • The sock instructions were in English. • If we

What is a Program? • The sock instructions were in English. • If we have to communicate an algorithm to a computer, we’ll need to use a language that is more easily interpreted than English. • A computer “language” is a very small subset of the human communication language. • That’s because computers are very stupid!! • They only do exactly what you tell them. Spring 2006 CISC 101 - Prof. Mc. Leod 14

Computer Architecture (PC) Spring 2006 CISC 101 - Prof. Mc. Leod 15

Computer Architecture (PC) Spring 2006 CISC 101 - Prof. Mc. Leod 15

Acronyms!! • CPU - “Central Processing Unit” – The heart of the computer. –

Acronyms!! • CPU - “Central Processing Unit” – The heart of the computer. – Consists of millions of transistors on a single chip. – Next slide shows the physical layout of a pentium chip. Spring 2006 CISC 101 - Prof. Mc. Leod 16

Spring 2006 CISC 101 - Prof. Mc. Leod 17

Spring 2006 CISC 101 - Prof. Mc. Leod 17

CPU - Cont. • The latest: Dual Core – two processors on one chip!

CPU - Cont. • The latest: Dual Core – two processors on one chip! • As hardware, they are characterized by their clock speed, which controls the number of operations per second that they can carry out. • The first PC contained an 8080 chip, introduced in 1979 that had a clock speed of 2 MHz or (2, 000 cycles per second). • Now Pentium IV’s operate at at least 2 GHz! Spring 2006 CISC 101 - Prof. Mc. Leod 18

CPU - Cont. • Responsible for: – Locating and carrying out program instructions from

CPU - Cont. • Responsible for: – Locating and carrying out program instructions from RAM. – Carrying out arithmetic operations on data stored temporarily in a few “registers”. – Moving data between RAM and other storage devices (except for those devices that can use “DMA” - Direct Memory Access). Spring 2006 CISC 101 - Prof. Mc. Leod 19

CPU - Cont. • A CPU can only carry out machine language instructions. •

CPU - Cont. • A CPU can only carry out machine language instructions. • All high level program instructions must be reduced to machine code before the CPU can do anything with them. Spring 2006 CISC 101 - Prof. Mc. Leod 20

RAM and ROM • “Random Access Memory” – Volatile memory - when the power

RAM and ROM • “Random Access Memory” – Volatile memory - when the power goes off, bye -bye go the bits! – Ultimately, numbers are stored in binary format (1 or 0) - more on this topic later! – RAM holds data and program instructions. • “Read Only Memory” – Not volatile. – Contains code and (BIOS) data used to start (“boot”) the computer. Spring 2006 CISC 101 - Prof. Mc. Leod 21

Other Components • Disk storage: – Data stored on magnetic or optical media. –

Other Components • Disk storage: – Data stored on magnetic or optical media. – Not volatile! (Hopefully!) – Disk read/write operations are much slower than operations carried out in RAM by the CPU. – Program code is first loaded from the disk to RAM and then executed. Spring 2006 CISC 101 - Prof. Mc. Leod 22

Other Components • Data ports – Serial (RS 232), Parallel, USB, PS 2, etc.

Other Components • Data ports – Serial (RS 232), Parallel, USB, PS 2, etc. – Providing input/output for the user via the keyboard, mouse, monitor, sound card, microphone, printer, scanner, joystick, webcam (etc. - you get the idea!) • Modem, Network card and/or Wireless Adapter – Provide a means of connecting to other computers. Spring 2006 CISC 101 - Prof. Mc. Leod 23

What is a Program? - Cont. • A program is an algorithm expressed using

What is a Program? - Cont. • A program is an algorithm expressed using a language that can be understood (interpreted) by a computer. • Many such languages exist: – Some are closest to how the computer “thinks” (in binary!), such as machine language: 582134 6 A 2204 6 B 2311 502132 (means “X = Y + Z - W”) Spring 2006 CISC 101 - Prof. Mc. Leod 24

Computer Languages • Each hexadecimal “byte” (8 bits, where a bit is either 1

Computer Languages • Each hexadecimal “byte” (8 bits, where a bit is either 1 or 0) of this language is translated into binary code that can be used at the microprocessor level. Spring 2006 CISC 101 - Prof. Mc. Leod 25

Computer Languages - Cont. • Machine language requires very little interpretation by the computer,

Computer Languages - Cont. • Machine language requires very little interpretation by the computer, but has very little resemblance to anything that a human can understand. • Next comes Assembler language: Spring 2006 CISC 101 - Prof. Mc. Leod 26

Assembler Language Example BEEPSEG BEEPSEG SEGMENT ASSUME PROC MOV INT ENDP ENDS END BYTE

Assembler Language Example BEEPSEG BEEPSEG SEGMENT ASSUME PROC MOV INT ENDP ENDS END BYTE PUBLIC CS: BEEPSEG ‘PROG’ DL, 7 AH, 2 33 32 • Any guess as to what this does? Spring 2006 CISC 101 - Prof. Mc. Leod 27

Computer Languages - Cont. • Each assembly language command would need to be interpreted

Computer Languages - Cont. • Each assembly language command would need to be interpreted to several machine language commands. • The next generation of computer languages went up one more level, getting closer to something readable - for example: Fortran, Cobol and Lisp. • These languages led to an explosion of over 200 languages being developed in the 60’s and 70’s, such as Basic, Pascal, C, Ada and Smalltalk. Spring 2006 CISC 101 - Prof. Mc. Leod 28

Java • Java was developed about 15 years ago! • Java is an Object-Oriented

Java • Java was developed about 15 years ago! • Java is an Object-Oriented language that is very high level - meaning that it is close to being easily readable. • This means that one command in Java could require many, many machine language instructions to execute. Spring 2006 CISC 101 - Prof. Mc. Leod 29

A Very Brief History of Java • The language was first developed by James

A Very Brief History of Java • The language was first developed by James Gosling at Sun Microsystems in 1991. – He was designing a language, called “Oak”, for the “Green Project”. – The Green Project envisaged the centralized control of many processorbased devices in the home. – “Oak” was designed to be a robust, efficient language with maximum portability to different processors. – The Green Project flopped… – But “Oak” was to soon become “Java”! Spring 2006 CISC 101 - Prof. Mc. Leod 30

Java History, Cont. • As soon as Internet use started to blossom in the

Java History, Cont. • As soon as Internet use started to blossom in the early 90’s, a need arose to have web pages do more than just display static text and graphics. • Web pages needed to be “programmable”, so that they could do more - especially so that they could interact with the viewer of the page. • The problem is that web pages are viewed on a wide variety of platforms, from Mac’s to Unix to IBM-PC’s. • So any page-embedded language would need to run on all these platforms. Spring 2006 CISC 101 - Prof. Mc. Leod 31

Java History, Cont. • In 1994, Sun demonstrated the use of Java in small

Java History, Cont. • In 1994, Sun demonstrated the use of Java in small bundles of code embedded in a web page called “applets”. • Netscape browsers started supporting applets in 1995, starting Java’s rise to fame. • Sun programmers continued to develop a code base for the language, demonstrating that Java could be used for more than just applets, and that full-blown applications could be written in this high -level language. Spring 2006 CISC 101 - Prof. Mc. Leod 32

How Java Works • The Java language standard (the “syntax”) is identical for all

How Java Works • The Java language standard (the “syntax”) is identical for all platforms. • A compiler (“JDK”, or “Java Development Kit”) which is designed to run on your development platform, compiles your source code to a “byte code” file (“*. class” file extension). • The byte code file is platform-independent, and is the thing you attach to your web page as an applet. • Every browser written for every platform and OS, can have an embedded code processor called a JVM, or “Java Virtual Machine”, built-in. Spring 2006 CISC 101 - Prof. Mc. Leod 33

How Java Works, Cont. • The JVM takes the byte code and executes it

How Java Works, Cont. • The JVM takes the byte code and executes it by generating the machine code that will be recognized by the platform that is running the browser. Remote Server (Unix) Local Client (Wintel PC) HTML File Netscape Browser Internet Applet Spring 2006 Applet Byte code files CISC 101 - Prof. Mc. Leod JVM 34

How Java Works, Cont. • Of course it did not take long before people

How Java Works, Cont. • Of course it did not take long before people took the JVM out of the browser so that they could run stand-alone Java applications. • The concept of “write once, run anywhere” is very appealing! • And, Sun distributes the JDK’s for free (see java. sun. com), making development on many platforms inexpensive. • Java now has 2. 5 million application programmers worldwide. No other language has ever grown this quickly! Spring 2006 CISC 101 - Prof. Mc. Leod 35

How Java Works, Cont. • So, Java can be used either to create applets

How Java Works, Cont. • So, Java can be used either to create applets for use in web pages or for stand-alone applications. • Most “Integrated Development Environments” or “IDE”’s will support the development of either kind of program. Spring 2006 CISC 101 - Prof. Mc. Leod 36

How Java Works, Cont. • All IDE’s (or “Integrated Development Environments”) must use the

How Java Works, Cont. • All IDE’s (or “Integrated Development Environments”) must use the appropriate JDK from Sun in the background. • Two components of the JDK are the programs “javac. exe” and “java. exe”. • javac. exe is the byte code compiler, and java. exe is the JVM which executes the byte code file. • “Compilation” is the process of converting the *. java file to a *. class file (the byte code file). This is done by calling javac. exe in the background, and supplying that program with all the required command line parameters. Spring 2006 CISC 101 - Prof. Mc. Leod 37

How Java Works, Cont. • The java. exe program: – – – accepts the

How Java Works, Cont. • The java. exe program: – – – accepts the byte code file, links in any required libraries, creates executable code in memory converts it to machine language and sends it to the CPU. • The java. exe program must know the right machine language commands only for the type of CPU it is designed for! Spring 2006 CISC 101 - Prof. Mc. Leod 38

Source text Text Editor successful Bytecode binary Eclipse or Blue. J Compiler Executable binary

Source text Text Editor successful Bytecode binary Eclipse or Blue. J Compiler Executable binary not successful Linker Errors javac. exe Loader Library binary Input Data java. exe Spring 2006 CISC 101 - Prof. Mc. Leod Output Data 39

How Java Works, Cont. • So, Java can be used either to create applets

How Java Works, Cont. • So, Java can be used either to create applets for use in web pages or for stand-alone applications. • Most “Integrated Development Environments” or “IDE”’s will support the development of either kind of program. Spring 2006 CISC 101 - Prof. Mc. Leod 40

Why Java for CISC 101? • The choice of the language is fairly arbitrary.

Why Java for CISC 101? • The choice of the language is fairly arbitrary. • Java is: – – – Multiplatform, Modern, Object - Oriented, Supported by a Large User Base, Not Vendor-Specific, Fundamentally Sound. • Other good languages: C, C++, C#, Delphi (pascal), Visual Basic, Turing, etc. Spring 2006 CISC 101 - Prof. Mc. Leod 41

Why Java? - Cont. • “IDE” - Integrated Development Environments (like those from Microsoft)

Why Java? - Cont. • “IDE” - Integrated Development Environments (like those from Microsoft) make it easier to build GUI Interfaces. • “GUI” - Graphical User Interface. • We don’t want to get hung up on all the GUI elements necessary to build a “Windows” program. • Learn structural programming first. • Need a simple development environment, not one that is oriented only towards Windows platform development. Spring 2006 CISC 101 - Prof. Mc. Leod 42

Why Java? - Cont. • Use Java to demonstrate your knowledge of programming. •

Why Java? - Cont. • Use Java to demonstrate your knowledge of programming. • In particular, we will use “Java II” which is also referred to as “JDK, version 1. 5” or “Java 5. 0”. • Two development tools are recommended: Blue. J and Eclipse. • Available here and in in Jeff Lab. Spring 2006 CISC 101 - Prof. Mc. Leod 43

Development Environments - Cont. • You can use any environment you wish (JBuilder, Sun

Development Environments - Cont. • You can use any environment you wish (JBuilder, Sun JDK, Blue. J, Eclipse, etc. ) - but we cannot be expected to support them all. • The programs you write and submit could be run on any platform in any environment. • Let “us” have a look at three possible development environments: – DOS command line (java. sun. com) – Blue. J (www. bluej. org) – Eclipse (www. eclipse. org) Spring 2006 CISC 101 - Prof. Mc. Leod 44

Three Environments • Which to use? • Use DOS if you like pain… •

Three Environments • Which to use? • Use DOS if you like pain… • Blue. J is simple but not realistic. • Eclipse is a “real” tool – this is the one I’m going to use in class most often. Spring 2006 CISC 101 - Prof. Mc. Leod 45

For Example - Hello. World. java • In Notepad: // The "Hello. World" class.

For Example - Hello. World. java • In Notepad: // The "Hello. World" class. public class Hello. World { public static void main (String[] args) { System. out. println("Hello World!"); } // end main method } // end Hello. World class Spring 2006 CISC 101 - Prof. Mc. Leod 46

For Example - Hello. World. class • In Notepad: Êþº¾ � - �� ��

For Example - Hello. World. class • In Notepad: Êþº¾ � - �� �� Hello. World� �� �java/lang/Object� �main� �([Ljava/lang/String; )V� �Code� �Line. Number. Table� � �Ljava/io/Print. Stream; � �out � �� �java/lang/System� �� �Hello World!� � �� �(Ljava/lang/String; )V� �println � �� �� �java/io/Print. Stream� �<init>� �()V� � �� �Hello. World. java� Source. File ! � � � � % � � ² ���¶ �± � � �*· �± � � � � � Spring 2006 CISC 101 - Prof. Mc. Leod 47

Next Time • Down to the business of learning Java: – – – Primitive

Next Time • Down to the business of learning Java: – – – Primitive types Variable declaration Operators Expressions Mixed type expressions Casting • A program “template” • Screen output • Screen input Spring 2006 CISC 101 - Prof. Mc. Leod 48