Difference between revisions of "CIS 3020 Part 1"
Jump to navigation
Jump to search
m (CIS 3020 moved to CIS 3020 Part 1: More structured this way) |
|||
(75 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | + | ==Introduction to CIS== | |
− | |||
Introduction to: | Introduction to: | ||
* The art and science of programming | * The art and science of programming | ||
Line 36: | Line 35: | ||
{| | {| | ||
| | | | ||
− | 15% | + | Option 1<br> |
− | 20% | + | 15%<br> |
− | 30% | + | 20%<br> |
− | - | + | 30%<br> |
− | 20% | + | -<br> |
− | 15% | + | 20%<br> |
+ | 15%<br> | ||
| | | | ||
− | 15% | + | Option 2<br> |
− | 15% | + | 15%<br> |
− | 15% | + | 15%<br> |
− | 20% | + | 15%<br> |
− | 20% | + | 20%<br> |
− | 15% | + | 20%<br> |
+ | 15%<br> | ||
| | | | ||
− | Examination 1 | + | <br> |
− | Examination 2 | + | Examination 1<br> |
− | Examination 3 | + | Examination 2<br> |
− | Final | + | Examination 3<br> |
− | Pop quizzes and in class exercises | + | Final<br> |
− | Group/Ind Homework Assignments | + | Pop quizzes and in class exercises<br> |
+ | Group/Ind Homework Assignments<br> | ||
|} | |} | ||
+ | ====What to Expect==== | ||
+ | * Difficulty: This course has had a drop rate as high as 33% | ||
+ | * Effort Required: Expect to spend a minimum of 10 hours/week | ||
+ | * Intended for: Those needing a firm foundation in CS principles (majors) | ||
+ | * Education Value: Understanding the vocabulary of CS and concepts of OOP (Object-Oriented Programming) | ||
+ | ====Necessary Skills==== | ||
+ | * Helpful to know Java, but not a requirement | ||
+ | * Prior programming experience is helpful | ||
+ | * Willingness to work outside of class | ||
+ | * Willingness to work in groups | ||
+ | * Self discipline | ||
+ | * Ability to tolerate frustration | ||
+ | * Ability to switch between high and low level views | ||
+ | * Ability to think abstractly | ||
+ | * Ability to see what is actually there: | ||
+ | <pre> | ||
+ | This is the | ||
+ | the answer | ||
+ | </pre> | ||
+ | ** The computer executes exactly what you give it | ||
+ | ** The ability to see the duplicate "the" can greatly help in debugging code | ||
+ | ====Self Test==== | ||
+ | {| border="1" | ||
+ | | | ||
+ | # If (a<b) then x=a & y=b otherwise x=b & y=a | ||
+ | # z=0 | ||
+ | # if (x<=0) goto step 7 | ||
+ | # z=z+y | ||
+ | # x=x-1 | ||
+ | # goto step 3 | ||
+ | # print z | ||
+ | | | ||
+ | * What did the author of this algorithm intend for it to do? | ||
+ | * For what values of a & b does the algorithm work as intended? | ||
+ | * How many times is step 3 executed? | ||
+ | |} | ||
+ | |||
+ | ====Should I stay?==== | ||
+ | * If you found the self test to be easy or not difficult in spite of no prior programming experience, then this course should not be too difficult for you. | ||
+ | ==What is Computer Science?== | ||
+ | <pre> | ||
+ | "...the science of abstraction - creating the right model for a problem and devising the appropriate mechanizable techniques to solve it" | ||
+ | - Aho and Ullman | ||
+ | </pre> | ||
+ | * Not the "science of computers" | ||
+ | * The study of computation: | ||
+ | ** Systems that produce the solutions | ||
+ | ** Methods used to develop solution strategies for these systems to follow | ||
+ | ** Application areas in which automated problem solving is useful | ||
+ | ====Foundations ([[COT 3100]])==== | ||
+ | * Formal mathematical structures forming the basis of Computer Science | ||
+ | * Questions: | ||
+ | ** What types of problems can be solved. | ||
+ | ** What syntax and semantics | ||
+ | ** Meaure complexity -- How? | ||
+ | ** How to verify correctness | ||
+ | ====Algorithms & Data ([[COP 3530]])==== | ||
+ | * Structures for representing data | ||
+ | ** Space complexity | ||
+ | * Fundamental and basic algorithms for manipulating these structures | ||
+ | ** Time complexity | ||
+ | * Advantages and disadvantages of representations | ||
+ | * Tradeoffs between space and time | ||
+ | ====Systems==== | ||
+ | * Architecture ([[CDA 3101]]) | ||
+ | ** Organization and structure of hardware | ||
+ | ** Design of computing hardware | ||
+ | * Operating Systems ([[COP 4600]]) | ||
+ | ** Design of resource management software | ||
+ | ** Management of disks, memory, processors... | ||
+ | * Networking ([[COP 4500C]]) | ||
+ | ** Connecting machines together to share resources | ||
+ | ** Highly related to operating systems | ||
+ | ====Applications==== | ||
+ | * Artificial Intelligence ([[CAP 4621]]) | ||
+ | ** Attacking problems viewed as requiring "human intelligence" | ||
+ | * Database Management ([[COP 4720]]) | ||
+ | ** Organizing large quantities of data so items can be easily extracted | ||
+ | * Graphics ([[CAP 4730]]) | ||
+ | ** Rendering | ||
+ | ====Methods==== | ||
+ | Design and assessment of techniques and software tools for creating solutions | ||
+ | * What is required within a programming language? ([[COP 4620]] - Translators) | ||
+ | * What methods are required for producing and evaluating software? ([[CEN 3031]] - Introduction to Software Engineering) | ||
+ | ==Changing Face of Computer Science== | ||
+ | Through the years, computer science has seen many changes: | ||
+ | * 1950's: Expensive hardware, programming in machine and assembly language. | ||
+ | * 1960's: Development of imperative languages | ||
+ | * 1970's: Decreasing hardware cost, microprocessors, introduction of software engineering, and rising programming costs. | ||
+ | * 1980's: Personal computers, object oriented programming. | ||
+ | * 1990's: Visual languages. | ||
+ | ====Hardware vs Software Costs==== | ||
+ | ====Shift in Emphasis==== | ||
+ | * 1950's: How computers are designed | ||
+ | * 1970's: Higher level languages | ||
+ | * 1990's: Problem modeling | ||
+ | ==What is a computer?== | ||
+ | ====Types of Computers==== | ||
+ | * Representation of information: Digital or analog | ||
+ | * Execution: Synchronous or asynchronous | ||
+ | * Composition: Biological, electronic, optical, quantum | ||
+ | ====What is a computer?==== | ||
+ | * CPU: Where all the calculation are performed | ||
+ | * I/O: Allow communication with outside world | ||
+ | * Memory: Stores program and data | ||
+ | ====Numbering system==== | ||
+ | ======Decimal Numbers====== | ||
+ | * We use base 10 | ||
+ | * 10 unique glyphs - digits 0 through 9 | ||
+ | * Meaning of a number is based on the symbols used and their position | ||
+ | ** 123 = 1x10^2 + 2x10^1 + 3x10^0 | ||
+ | ======Binary Numbers====== | ||
+ | * Computers use Base 2 | ||
+ | * 2 unique glyphs - 0 and 1 | ||
+ | * Meaning of a number is based on the symbols used and their position | ||
+ | ** 1011 = 1x2^3 + 0x2^2 + 1x2^1 + 1x2^0 | ||
+ | * A single digit binary number is called a bit | ||
+ | * 8 bits = byte and 4 bits = nibble | ||
+ | * Number of bits determines how many symbols can be represented | ||
+ | * These symbols might represent numbers, letters, instructions, etc. | ||
+ | ** ASCII (American Standard Code for Information Exchange) uses 7 bits | ||
+ | ** Unicode uses 16 bits | ||
+ | ====Units of Storage==== | ||
+ | {| border="1" | ||
+ | |- | ||
+ | ! Unit !! Symbol !! Size | ||
+ | |- | ||
+ | | Byte || || 8 bits | ||
+ | |- | ||
+ | | Kilobyte || KB || 2^10 = 1024 bytes | ||
+ | |- | ||
+ | | Megabyte || MB || 2^20 = 1048576 bytes | ||
+ | |- | ||
+ | | Gigabyte || GB || 2^30 = 1,073,741,824 bytes | ||
+ | |- | ||
+ | | Terabyte || TB || 2^40 bytes | ||
+ | |} | ||
+ | |||
+ | ====Main Memory==== | ||
+ | Series of memory locations. In each location is data, instructions or garbage. Somve values are stored in consecutive locations. Can be read (non-destructive) or writte (destructive). | ||
+ | ====CPU Components (Simplified)==== | ||
+ | * ALU (Arithmatic and Logic Unit) - Performs specified operations on information stored in the registers | ||
+ | * Control Unit | ||
+ | ** Determines what operations should be performed | ||
+ | ** Controls transfer of information between the ALU and registers | ||
+ | * Registers | ||
+ | ** Program Counter: Holds address of next instruction | ||
+ | ** Instruction Register: Holds current instruction | ||
+ | ** General Purpose Registers: Store results of arithmatic calculations | ||
+ | ====Fetch-Decode-Execute Cycle==== | ||
+ | # Fetch: Get instruction at address in Program Counter (PC). Load it into Instruction Register (IR). | ||
+ | # Increment: Increment the program counter. | ||
+ | # Decode: Decode the instruction. | ||
+ | # Execute: Activate the circuitry in ALU to perform instruction. | ||
+ | # Repeat. | ||
+ | ==Programming== | ||
+ | ====Properties of High Level Languages (HLL)==== | ||
+ | * Tend to look like English | ||
+ | * Easier to express ideas in HLL | ||
+ | * Easier to understand than programs in machine/assembly language | ||
+ | * Support Abstraction | ||
+ | * HLL Code is more platform independent than machine/assembly language | ||
+ | * HLL Code cannot be executed directly | ||
+ | ====Compiler==== | ||
+ | * Translates a program (written in a particular programming language) into a target language (usually machine or assembly) | ||
+ | * Often the target language is a machine language but sometimes is another HLL | ||
+ | <pre> | ||
+ | SNOBOL -> C -> Machine language | ||
+ | </pre> | ||
+ | * This translation is performed once - the result can be executed many times | ||
+ | <pre> | ||
+ | Program P in Language L -> Compiler -> P', an equivalent program in machine language | ||
+ | </pre> | ||
+ | ====Interpreter==== | ||
+ | * Translates a program written in a particular language | ||
+ | * Translation is performed while the program is executing | ||
+ | * Each time a statement is encountered it is re-interpreted | ||
+ | * Execution is typically slower than with compiled code | ||
+ | * Eliminates the need for a seperate compilation phase | ||
+ | * Can make program development easier | ||
+ | * Interpreter is easier to write than compiler | ||
+ | ====Java Design Goal==== | ||
+ | * Platform independence | ||
+ | * "Write once, run anywhere" | ||
+ | * Solution 1: (not used) | ||
+ | ** Distribute source code and let end-user compile on their machine | ||
+ | ** Pro: Is platform independent | ||
+ | ** Cons: | ||
+ | *** Reveals intellectual property/trade secrets | ||
+ | *** Source code is bulky | ||
+ | *** Recipient is forced to compile or interpret | ||
+ | * Solution 2: (used) | ||
+ | ** Use both interpreter and compiler | ||
+ | ** Pro: | ||
+ | *** Platform independent | ||
+ | *** Source is not distributed | ||
+ | *** Code is compact | ||
+ | *** Code can be executed fairly fast | ||
+ | ** Con: | ||
+ | *** Usually does not run as fast as compiled code | ||
+ | ====Java==== | ||
+ | * Java source code is compiled into instructions called java byte code, designed for a Java Virtual Machine (JVM) | ||
+ | * This byte code is interpreted by a JVM - a simulator | ||
+ | * Provides better performance than a typical interpreter because byte code is closer to machine language | ||
+ | ====What can be done with Java Byte Code?==== | ||
+ | * Interpret it with a program that acts like a CPU that uses the Java Virtual Machine instructions | ||
+ | * Translate it into machine code for a particular hardware CPU (JIT - Just In Time compilers) | ||
+ | * Execute it on a CPU designed to use JVM instructions (Java Chip) | ||
+ | ====Virtual Machines==== | ||
+ | * An emulated computer system or emulated ISA (Instruction Set Architecture) | ||
+ | * Can be software or hardware VM | ||
+ | * Software examples: | ||
+ | ** Pascal: Imperative language | ||
+ | *** Intermediate code called "P" code, byte code for "P" machine | ||
+ | ** LISP: Functional language | ||
+ | *** Both interpreted and compiled (native or byte) | ||
+ | ** Smalltalk: Object oriented language - interpreted or byte compiled. | ||
+ | * Hardware: | ||
+ | ** CISC: Complex instruction set computing | ||
+ | *** Instructions do a lot | ||
+ | *** Complex | ||
+ | ** RISC: Reduced instruction set computing | ||
+ | *** Very simple set of instructons | ||
+ | * Examples: | ||
+ | ** Pentium Pro: Looks like CISC, but was RISC | ||
+ | ** Pentium II, III, and IV | ||
+ | ** AMD K-5, K6, and K6-2 | ||
+ | ====Abstraction==== | ||
+ | * Keep what is essential while discarding everything else | ||
+ | * What is essential depends on the context | ||
+ | * Cat: | ||
+ | ** Sound: | ||
+ | *** Meow, Hiss, purring | ||
+ | ** Visual: | ||
+ | ====Data Abstraction==== | ||
+ | * Use programming language construct to model information | ||
+ | ** Age: integer | ||
+ | ** Name: sequence of letters | ||
+ | ** Time: HH:MM or milliseconds since 1/1/1970 | ||
+ | * Represent single conceptual entity | ||
+ | * Giving symbolic names to pieces of data | ||
+ | ** Done for communication: | ||
+ | *** "Call me at home" vs "Call me at 555-1235" | ||
+ | ** Facilitates communication | ||
+ | ====Procedural Abstraction==== | ||
+ | * Capture and name a computational process | ||
+ | * Allows us to state ''what'' not ''how'' | ||
+ | ** "Give me a call" | ||
+ | ** "Add the numbers three and seven" -- Use of arguments | ||
+ | * Allows hiding details of process | ||
+ | * We invoke a process through its' interface | ||
+ | * Allows us to reuse abstractions by building libraries | ||
+ | ==Programming Paradigms== | ||
+ | ====Imperative==== | ||
+ | * Program consists of sequence of commands describing how to perform desired computational process | ||
+ | * Programmer describes how to do task | ||
+ | * Example: Brewing coffee | ||
+ | # Gather coffee, filter, and water | ||
+ | # Take ingredients to coffee maker | ||
+ | # Put filter in basket | ||
+ | # Put coffee in basket | ||
+ | # Put basket in coffee maker | ||
+ | # Add water to coffee maker | ||
+ | # Put pot under basket | ||
+ | # Turn on coffee maker | ||
+ | ====Declarative (Logic Programming)==== | ||
+ | * Given a set of facts, rules, and a goal | ||
+ | * Use inference engine to satisfy goal | ||
+ | * Programmer states what they want to do | ||
+ | {| border="1" | ||
+ | |||
+ | ! '''Facts''' !! '''Rules''' | ||
+ | |- | ||
+ | | mother (marge, lisa) || parent (X,Y) :- mother (X,Y) | ||
+ | |- | ||
+ | | father (homer, lisa) || parent (X,Y) :- father (X,Y) | ||
+ | |- | ||
+ | | father (abe, homer) || gparent (X,Z) :- parent (X,Y), parent (Y,Z) | ||
+ | |- | ||
+ | | mother (marge, bart) | ||
+ | ! '''Goal''' | ||
+ | |- | ||
+ | | father (homer, bart) || gparent (X, lisa) | ||
+ | |} | ||
+ | |||
+ | ====Functional==== | ||
+ | * Emphasizes the evaluation of expressions, not the evaluation of commands | ||
+ | * Compute the sum of 1, 3, 7, and 9: | ||
+ | ** Imperative: 1+3+7+9 | ||
+ | ** Functional: (+ 1 3 7 9) | ||
+ | * Program consists of functons built from simpler functions | ||
+ | * Encourages "black box" approach of modular programming in software engineering | ||
+ | ====Object Oriented==== | ||
+ | * Objects are responsible for performing computations | ||
+ | * The program is a collaborative effort between a set of specialized agents (objects), each with a well defined role | ||
+ | * The interaction between objects cause the computations to be performed | ||
+ | * Objects communicate by passing messages | ||
+ | * A message is given to an object to identify what it must do | ||
+ | * Message consists of: | ||
+ | ** What to do | ||
+ | ** What to do it with | ||
+ | * Recipient of a message must have ability to perform the required action | ||
+ | * Objects encapsulate (contain and control) | ||
+ | ** State: What the object knows | ||
+ | ** Behavior: What the object can do | ||
+ | * Every object is an instance of exactly one class | ||
+ | * State and behavior are defined by object's class | ||
+ | * All instances of a class respond similarly when their behavior is involved | ||
+ | * Objects exhibit behavior when you invoke them by sending them a message | ||
+ | * Try to reuse code whenever possible | ||
+ | * A good parallel to draw is to compare Object Oriented programming to building a house: | ||
+ | ** There are a large number of sub-contractors (objects) involved: | ||
+ | *** Plumbers | ||
+ | *** Carpenters | ||
+ | *** Dry wall installers | ||
+ | *** etc. | ||
+ | ** All of these are coordinated by the general contractor (the main program/procedure) who specifies what will be done when | ||
+ | ==Continue with [[CIS 3020 Part 2]]== |
Latest revision as of 10:40, 22 February 2007
Contents
Introduction to CIS
Introduction to:
- The art and science of programming
- The fundamentals of computer science
- The basic concepts of Object Orientation:
- Abstraction - representing the key features
- Polymorphism - "many forms"
- Inheritance - reuse of existing code from ancestors
- Encapsulation - containing and controlling access to
What this course entails
- This course is not a Java programming course
- "Introduction" does not mean "easy"
- Prior programming experience is strongly recommended
- in none, take CIS 3022/3023
- This course moves quickly, so attempt assignments early
- Don't get discouraged if you feel confused after one week of class. You hopefull will feel more comfortable by the 3rd week.
Philosophy
- Goal is to learn fundamental principles of programming and obtain an overview of the field of computer science.
- This goal is independant of any language
- Java is used to make these principles concrete but "learning Java" is not the primary goal of the course.
- We will not cover most or all of Java.
- We will teach the basics with emphasis on thinking and analysis.
Class Web Page
WebCT/Vista
Douglas Denkel's Homepage
- Announcements, homework assignments, etc. will be posted here.
- You are responsible to be aware of what information is there.
- Check it frequently -- no less than every other day!
Lecture Notes
- Copies of the lecture slides are available in the Lectures folder in WebCT/Vista
- These slides do NOT contain everything on my slides to encourage you to come to class.
- You are strongly encouraged to print a copy of these notes.
- Having a copy will make taking notes significantly easier!
Grading
Option 1 |
Option 2 |
|
What to Expect
- Difficulty: This course has had a drop rate as high as 33%
- Effort Required: Expect to spend a minimum of 10 hours/week
- Intended for: Those needing a firm foundation in CS principles (majors)
- Education Value: Understanding the vocabulary of CS and concepts of OOP (Object-Oriented Programming)
Necessary Skills
- Helpful to know Java, but not a requirement
- Prior programming experience is helpful
- Willingness to work outside of class
- Willingness to work in groups
- Self discipline
- Ability to tolerate frustration
- Ability to switch between high and low level views
- Ability to think abstractly
- Ability to see what is actually there:
This is the the answer
- The computer executes exactly what you give it
- The ability to see the duplicate "the" can greatly help in debugging code
Self Test
|
|
Should I stay?
- If you found the self test to be easy or not difficult in spite of no prior programming experience, then this course should not be too difficult for you.
What is Computer Science?
"...the science of abstraction - creating the right model for a problem and devising the appropriate mechanizable techniques to solve it" - Aho and Ullman
- Not the "science of computers"
- The study of computation:
- Systems that produce the solutions
- Methods used to develop solution strategies for these systems to follow
- Application areas in which automated problem solving is useful
Foundations (COT 3100)
- Formal mathematical structures forming the basis of Computer Science
- Questions:
- What types of problems can be solved.
- What syntax and semantics
- Meaure complexity -- How?
- How to verify correctness
Algorithms & Data (COP 3530)
- Structures for representing data
- Space complexity
- Fundamental and basic algorithms for manipulating these structures
- Time complexity
- Advantages and disadvantages of representations
- Tradeoffs between space and time
Systems
- Architecture (CDA 3101)
- Organization and structure of hardware
- Design of computing hardware
- Operating Systems (COP 4600)
- Design of resource management software
- Management of disks, memory, processors...
- Networking (COP 4500C)
- Connecting machines together to share resources
- Highly related to operating systems
Applications
- Artificial Intelligence (CAP 4621)
- Attacking problems viewed as requiring "human intelligence"
- Database Management (COP 4720)
- Organizing large quantities of data so items can be easily extracted
- Graphics (CAP 4730)
- Rendering
Methods
Design and assessment of techniques and software tools for creating solutions
- What is required within a programming language? (COP 4620 - Translators)
- What methods are required for producing and evaluating software? (CEN 3031 - Introduction to Software Engineering)
Changing Face of Computer Science
Through the years, computer science has seen many changes:
- 1950's: Expensive hardware, programming in machine and assembly language.
- 1960's: Development of imperative languages
- 1970's: Decreasing hardware cost, microprocessors, introduction of software engineering, and rising programming costs.
- 1980's: Personal computers, object oriented programming.
- 1990's: Visual languages.
Hardware vs Software Costs
Shift in Emphasis
- 1950's: How computers are designed
- 1970's: Higher level languages
- 1990's: Problem modeling
What is a computer?
Types of Computers
- Representation of information: Digital or analog
- Execution: Synchronous or asynchronous
- Composition: Biological, electronic, optical, quantum
What is a computer?
- CPU: Where all the calculation are performed
- I/O: Allow communication with outside world
- Memory: Stores program and data
Numbering system
Decimal Numbers
- We use base 10
- 10 unique glyphs - digits 0 through 9
- Meaning of a number is based on the symbols used and their position
- 123 = 1x10^2 + 2x10^1 + 3x10^0
Binary Numbers
- Computers use Base 2
- 2 unique glyphs - 0 and 1
- Meaning of a number is based on the symbols used and their position
- 1011 = 1x2^3 + 0x2^2 + 1x2^1 + 1x2^0
- A single digit binary number is called a bit
- 8 bits = byte and 4 bits = nibble
- Number of bits determines how many symbols can be represented
- These symbols might represent numbers, letters, instructions, etc.
- ASCII (American Standard Code for Information Exchange) uses 7 bits
- Unicode uses 16 bits
Units of Storage
Unit | Symbol | Size |
---|---|---|
Byte | 8 bits | |
Kilobyte | KB | 2^10 = 1024 bytes |
Megabyte | MB | 2^20 = 1048576 bytes |
Gigabyte | GB | 2^30 = 1,073,741,824 bytes |
Terabyte | TB | 2^40 bytes |
Main Memory
Series of memory locations. In each location is data, instructions or garbage. Somve values are stored in consecutive locations. Can be read (non-destructive) or writte (destructive).
CPU Components (Simplified)
- ALU (Arithmatic and Logic Unit) - Performs specified operations on information stored in the registers
- Control Unit
- Determines what operations should be performed
- Controls transfer of information between the ALU and registers
- Registers
- Program Counter: Holds address of next instruction
- Instruction Register: Holds current instruction
- General Purpose Registers: Store results of arithmatic calculations
Fetch-Decode-Execute Cycle
- Fetch: Get instruction at address in Program Counter (PC). Load it into Instruction Register (IR).
- Increment: Increment the program counter.
- Decode: Decode the instruction.
- Execute: Activate the circuitry in ALU to perform instruction.
- Repeat.
Programming
Properties of High Level Languages (HLL)
- Tend to look like English
- Easier to express ideas in HLL
- Easier to understand than programs in machine/assembly language
- Support Abstraction
- HLL Code is more platform independent than machine/assembly language
- HLL Code cannot be executed directly
Compiler
- Translates a program (written in a particular programming language) into a target language (usually machine or assembly)
- Often the target language is a machine language but sometimes is another HLL
SNOBOL -> C -> Machine language
- This translation is performed once - the result can be executed many times
Program P in Language L -> Compiler -> P', an equivalent program in machine language
Interpreter
- Translates a program written in a particular language
- Translation is performed while the program is executing
- Each time a statement is encountered it is re-interpreted
- Execution is typically slower than with compiled code
- Eliminates the need for a seperate compilation phase
- Can make program development easier
- Interpreter is easier to write than compiler
Java Design Goal
- Platform independence
- "Write once, run anywhere"
- Solution 1: (not used)
- Distribute source code and let end-user compile on their machine
- Pro: Is platform independent
- Cons:
- Reveals intellectual property/trade secrets
- Source code is bulky
- Recipient is forced to compile or interpret
- Solution 2: (used)
- Use both interpreter and compiler
- Pro:
- Platform independent
- Source is not distributed
- Code is compact
- Code can be executed fairly fast
- Con:
- Usually does not run as fast as compiled code
Java
- Java source code is compiled into instructions called java byte code, designed for a Java Virtual Machine (JVM)
- This byte code is interpreted by a JVM - a simulator
- Provides better performance than a typical interpreter because byte code is closer to machine language
What can be done with Java Byte Code?
- Interpret it with a program that acts like a CPU that uses the Java Virtual Machine instructions
- Translate it into machine code for a particular hardware CPU (JIT - Just In Time compilers)
- Execute it on a CPU designed to use JVM instructions (Java Chip)
Virtual Machines
- An emulated computer system or emulated ISA (Instruction Set Architecture)
- Can be software or hardware VM
- Software examples:
- Pascal: Imperative language
- Intermediate code called "P" code, byte code for "P" machine
- LISP: Functional language
- Both interpreted and compiled (native or byte)
- Smalltalk: Object oriented language - interpreted or byte compiled.
- Pascal: Imperative language
- Hardware:
- CISC: Complex instruction set computing
- Instructions do a lot
- Complex
- RISC: Reduced instruction set computing
- Very simple set of instructons
- CISC: Complex instruction set computing
- Examples:
- Pentium Pro: Looks like CISC, but was RISC
- Pentium II, III, and IV
- AMD K-5, K6, and K6-2
Abstraction
- Keep what is essential while discarding everything else
- What is essential depends on the context
- Cat:
- Sound:
- Meow, Hiss, purring
- Visual:
- Sound:
Data Abstraction
- Use programming language construct to model information
- Age: integer
- Name: sequence of letters
- Time: HH:MM or milliseconds since 1/1/1970
- Represent single conceptual entity
- Giving symbolic names to pieces of data
- Done for communication:
- "Call me at home" vs "Call me at 555-1235"
- Facilitates communication
- Done for communication:
Procedural Abstraction
- Capture and name a computational process
- Allows us to state what not how
- "Give me a call"
- "Add the numbers three and seven" -- Use of arguments
- Allows hiding details of process
- We invoke a process through its' interface
- Allows us to reuse abstractions by building libraries
Programming Paradigms
Imperative
- Program consists of sequence of commands describing how to perform desired computational process
- Programmer describes how to do task
- Example: Brewing coffee
- Gather coffee, filter, and water
- Take ingredients to coffee maker
- Put filter in basket
- Put coffee in basket
- Put basket in coffee maker
- Add water to coffee maker
- Put pot under basket
- Turn on coffee maker
Declarative (Logic Programming)
- Given a set of facts, rules, and a goal
- Use inference engine to satisfy goal
- Programmer states what they want to do
Facts | Rules |
---|---|
mother (marge, lisa) | parent (X,Y) :- mother (X,Y) |
father (homer, lisa) | parent (X,Y) :- father (X,Y) |
father (abe, homer) | gparent (X,Z) :- parent (X,Y), parent (Y,Z) |
mother (marge, bart) | Goal |
father (homer, bart) | gparent (X, lisa) |
Functional
- Emphasizes the evaluation of expressions, not the evaluation of commands
- Compute the sum of 1, 3, 7, and 9:
- Imperative: 1+3+7+9
- Functional: (+ 1 3 7 9)
- Program consists of functons built from simpler functions
- Encourages "black box" approach of modular programming in software engineering
Object Oriented
- Objects are responsible for performing computations
- The program is a collaborative effort between a set of specialized agents (objects), each with a well defined role
- The interaction between objects cause the computations to be performed
- Objects communicate by passing messages
- A message is given to an object to identify what it must do
- Message consists of:
- What to do
- What to do it with
- Recipient of a message must have ability to perform the required action
- Objects encapsulate (contain and control)
- State: What the object knows
- Behavior: What the object can do
- Every object is an instance of exactly one class
- State and behavior are defined by object's class
- All instances of a class respond similarly when their behavior is involved
- Objects exhibit behavior when you invoke them by sending them a message
- Try to reuse code whenever possible
- A good parallel to draw is to compare Object Oriented programming to building a house:
- There are a large number of sub-contractors (objects) involved:
- Plumbers
- Carpenters
- Dry wall installers
- etc.
- All of these are coordinated by the general contractor (the main program/procedure) who specifies what will be done when
- There are a large number of sub-contractors (objects) involved: