notes0-topost

advertisement
CS1101Z: A/P Tan Tiow Seng (tants@comp.nus.edu.sg),
S15-06-03, or consultation on Wednesday by appointment (through email)
Refer to course webpage at www.comp.nus.edu.sg/~cs1101z and IVLE.
Course Objective:
This module introduces programming to beginners, with the perspective of object
oriented programming. This is one of the two fundamental courses in programming.
Student Goal:
At the end of the course, students should be able to:
- model computational problem in an object manner
- program with Java SDK
Topics: Follow the textbook closely – I have my interpretation of the powerpoint
provided by the publisher – so, please check out also the notes of the day after the
lecture (on Sat/Sun).
Text book: Thomas Wu, An Introduction to Object-Oriented Programming with Java.
Fourth Edition.
All tests/exam are open book. i.e. Books are useless.
Discussion and Recitation start on 3rd week.
Lab #1 available on 30 August due on 6 September (Wednesday, 23:59).
Chapter 0 & 1.
I. History
Which is a better invention: car or computer?
- Computer. Why? Car should be just a few cents if it develops the way computer
developed.
- CPU doubling the speed every 18 months. Moore’s Law.
When was computer invented?
- After Car? Or Before Car?
- Charles Babbage, at 1823, conceptualized the precursor to the modern
computer called the difference engine. The project was ahead of its time. He
subsequently designed analytical engine – which was also ahead of its time. The
concept of Programmability appeared then.
- Ada Lovelace wrote the first demonstration program for the analytical engine.
The programming language Ada was named in honour of lady Lovelace. The first
programmer was lady – and many boss in the industry today are ladies too
- John Atanasoff (Iowa State University) together with his student Clifford Berry
built the prototype of the first automatic electronic calculator in the late 1930s.
- Howard Aiken of Harvard University, at around the same time, was working on
the Automatic Sequence-Controlled Calculator, known more commonly as MARK
CS1101z (Lecture 0/1)
1
-
-
I, with support from IBM and the US Navy. MARK I was very similar to the
analytical engine in design and was described as “Babbage’s dream come true.”.
John W. Mauchly and J. Presper Eckert of the University of Pennsylvania
built the first completely electronic computer, ENIAC I (Electronic Numerical
Integrator and Calculator). It was programmed laboriously by plugging wires into
a control panel that resembled an old telephone switchboard.
John von Neumann of Princeton University proposed storing programs in the
computer’s memory. This stored program scheme not only improved computation
speed but also allowed far more flexible ways of writing programs.
The text considers 4 generations of computers:
- First generation computers are characterized with those early computers with
vacuum tubes.
- Second generation with transistors replacing the vacuum tubes, started
appearing in the late 1950s.
- Third generation computers emerged in the early 1960s where transistors were
replaced by integrated circuits. We had then minicomputer.
- Fourth generation computers emerged in the mid-1970s using large-scale
integrated circuits. We had then personal computer.
What is now here and ahead of us?
- Interconnection of computers
- Multiple processors on your desktop
- GPU doubling the speed every ½ year. Moore’s Law Cube.
- Mobility is the norm / trend – Java going to dominate the world?
II. Programming
Programming is a (manual) process to write instruction to ask computer to perform some
computational tasks.
There are many ways to ask computer to do a computation:
- Tell it in 0s and 1s as it understands – machine language or object codes. For
example, 00010001101101110…
- Tell it at some slightly higher but still low level called assembly code (then use
assembler to make it into machine executable codes). For example, Add A, B, C.
- Tell it in some high level called high level language, such as Java or C or
Scheme. For example, c := c + 1;
We are interested in writing in high level language – easier to understand and modify.
High level language programs (source programs) must be translated into machine code
for execution. Two possible ways:
- Compiler : a translator whose source language is a high-level language
- Interpreter : a translator that both translates and executes a source program.
Javac is a java code compiler that compile a source language (java) to java bytecodes.
Bytecodes are architecturally neutral object code, and it is stored in a file with extension
.class
Java virtual machine (java) is an interpreter that translates and executes a java
bytecodes in the target machine running the java virtual machine.
CS1101z (Lecture 0/1)
2
III. Problem Solving with Programming
Question: Can we ask computer to perform all kind of computational tasks possible in
the world? This is left to another course to answer….
Let’s solve some common tasks:
1. Cook a 10 course dinner for 500 guests, giving a team of 80 people.
2. Piece up a puzzle of 1000 pieces, giving a team of 80 people.
What do we learn from the above tasks? Think for yourself in solving other tasks within a
large team. What do you see now?
PROCEEDINGS
Dinner: analysis, design, cooking, tasting, cleaning
Puzzle: (unwrap the box!) analysis, design, piecing, testing integration, operation and
maintenance.
Software: analysis, design, coding, testing, operation and maintenance.
APPROACHES
Dinner: by dish or by expertise
Puzzle: by part, by random chance, by feature
Software: by operation/computation, by object
Computer Science = Algorithm + Data Structure + Protocol
(Algorithm: recipe of steps; Data structure: store of ingredient; Protocol: manner of
conduct of recipe to recipe)
A well-known reference book: George Polya: How to Solve it.
IV. Powerful Object-oriented Concepts
Encapsulation: known with this personality
Just do it and I don’t care what is inside (assume it is efficient)
Inheritance: known with personality from your ancestors
Don’t have to say so much as it is already known from ancestors.
Polymorphism: known with multiple personality (same message to objects from different
classes)
Can behavior differently in different situations
Inheritance is a mechanism in OOP to design two or more entities that are different but
share many common features.
-
Features common to all classes are defined in the superclass.
-
The classes that inherit common features from the superclass are called
subclasses
o
We also call the superclass an ancestor and the subclass a descendant
CS1101z (Lecture 0/1)
3
Download