Introduction To Computer Science: Ryan Stansifer
Introduction To Computer Science: Ryan Stansifer
Introduction
Ryan Stansifer
11 April 2021
• Programming
• exciting to translate ideas into reality
• basics are simple, yet programming well is difficult; do not underestimate the
challenge
• delivery high-quality programs on time; be able to express control flow and
design data in Java
• problem solving is hard and difficult to teach
• Computer Science
• Computer Science is not just programming
• It is easy to lose sight of the big picture, so we have a general introduction
• Other (non-programming) topics from time to time: architecture, Monte Carlo
methods, O(N), invariants, and so on
Computer Science is not the study of computers, nor is it the practice of their use.
Sorting animation
A report from the United States General Accounting Office begins “On
February 25, 1991, a Patriot missile defense system operating at Dhahran,
Saudi Arabia, during Operation Desert Storm failed to track and intercept
an incoming Scud. This Scud subsequently hit an Army barracks, killing
28 Americans.” The report finds the failure to track the Scud missile was
caused by a precision problem in the software.
Nicholas J. Higham, Accuracy and Stability of Numerical Algorithms, SIAM, 1996,
ISBN13 9780898713558. Page 505.
http://www.ima.umn.edu/~arnold/disasters/disaster.html
In the sliding window protocol the window size is the amount of data a sender is
allowed to have sent into the network without having yet received an
acknowledgment for it.
In Internet routers, active queue management (AQM) is a technique that consists
in dropping packets before a router’s queue is full.
Historically, queues use a drop-tail discipline: a packet is put onto the queue if the
queue is shorter than its maximum size. Drop-tails queue have a tendency to
penalize bursty flows.
Active queue disciplines drop packets before the queue is full based on probabilities.
Active queue disciplines are able to maintain a shorter queue length than the
drop-tail queue which reduces network latency.
The Miracle Worker scene from Star Trek 4: The Voyage Home on YouTube.
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 44 / 1
The solution to vast complexity is layers. Good layers enable high-quality
specialization, bad layers just increase the complexity.
Software development—programming—is often about creating layers, even in small
programming projects.
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 45 / 1
Computing is complex. There are many layers of interesting stuff between the
person and the automaton.
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 46 / 1
Scale of the Universe 2
by Cary and Michael Huang
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 47 / 1
The vastness and minuteness of time and space is a challenge to comprehend.
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 48 / 1
SI Prefixes
A study of people in Nicaragua who were born deaf and never learned Spanish or a
formal sign language has concluded that humans need language in order to
understand large numbers. “Up to three, they’re fine," says Elizabet Spaepen, a
researcher at the University of Chicago and an author of the study. “But past
three, they start to fall apart."
http://www.npr.org/2011/02/09/
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 49 / 1
SI Prefixes
peta P quadrillion 1015 1 000 000 000 000 000
tera T trillion 1012 1 000 000 000 000
giga G billion 109 1 000 000 000
mega M million 106 1 000 000
kilo k thousand 103 1 000
hecto h hundred 102 100
deca da ten 101 10
(none) one 100 1
deci d tenth 10−1 0.1
centi c hundredth 10−2 0.01
milli m thousandth 10−3 0.001
micro µ millionth 10−6 0.000 001
nano n billionth 10−9 0.000 000 001
pico p trillionth 10−12 0.000 000 000 001
femto f quadrillionth 10−15 0.000 000 000 000 001
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 50 / 1
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 51 / 1
A Memory Aid for the SI Prefixes
Planets:
My very excellent mother just served us nachos.
Mary’s “Virgin” explanation made Joseph suspect upstairs neighbor.
Man very early made jars serve useful needs [period].
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 52 / 1
A computer is a remarkable tool and easily works at all scale. Now some early
history of technology and scientific computing...
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 53 / 1
By mid-1953, five distinct sets of problems were running on the MANIAC,
charactered by different scale of time: (1) nuclear explosions, over in microseconds;
(2) shock and blast waves, ranging fmr microseconds to minutes; (3) meteorology,
rnageing from minutes to years; (4) biological evolution, ranging from years to
millions of years; and (5) stellar evolution, ranging from millions to billions of years.
All this in 5 kilobytes—enough memory for about one-half second of audio, at the
rate we now compress music into MP3s.
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 54 / 1
Powers of Two
Because computers represent information in binary form, it is important to know
how many pieces of information can be represented in n (binary) bits. 2n pieces of
information can be stored in n bits, and so is it necessary to be familiar with
powers of two.
It is obvious that dlog2 ne bits are required to represent n things. Some bit patterns
might be unused.
20 1
21 2
22 4
23 8
24 16
25 32
(What does it mean that one thing can be represented with zero bits? There is no
need to represent one thing as there is nothing else which can be confused with it.)
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 55 / 1
In Java, the expression
32 - Math.numberOfLeadingZeros(n-1)
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 56 / 1
Because information is represented in ones and twos, doubling (exponential
growth) is an important concept in computing.
To grasp it better, we use an ancient Indian chess legend.
A picture of Krishna playing Chess from the National Museum, New Delhi
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 57 / 1
Legend of the Ambalappuzha Paal Payasam
According to the legend, Lord Krishna once appeared in the form of a sage in the
court of the king who ruled the region and challenged him for a game of chess (or
chaturanga).
The sage told the king that he would play for grains of rice—one grain of rice in
the first square, two grains in the second square, four in the third square, eight in
the fourth square, and so on. Every square would have double the number of grains
of its predecessor. The king lost the game and soon realized that even if he
provided all the rice in his kingdom, he would never be able to fulfill the promised
reward. The sage appeared to the king in his true form, that of Lord Krishna. and
said he could serve paal-payasam (sweet pudding made of milk and rice) in the
temple freely to the pilgrims every day until the debt was paid off.
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 58 / 1
How many squares in a checkerboard? How big is 264 ?
103 kilo k
106 mega M
109 giga G
1012 tera T
1015 peta P
1018 exa E
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 59 / 1
Maybe we can comprehend it better as weight or time. How much does a gain of
rice weigh? One grain of rice weighs about 0.029 grams. And, approximately 470
million tons of milled rice is harvested annually in the world today.
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 60 / 1
0 1 0.029g
1 2 0.058g
2 4 0.116g
3 8 0.232g
4 16 0.464g
5 32 0.928g
6 64 1.856g
7 128 3.712g
8 256 7.424g
9 512 14.848g
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 61 / 1
10 1 024 29.696g about an ounce
11 2 048 59.392g
12 4 096 118.784g
13 8 192 237.568g
14 16 384 475.136g about a pound
..
.
25 33 554 432 973.079kg about a ton
..
.
40 1 099 511 627 776 35 thousand tons
50 1 125 899 906 842 624 36 million tons
60 1 152 921 504 606 846 976 36 billion tons
64 18,446,744,073,709,551,616 589 billion tons
264 grains of rice is the total rice harvest for over 1200 years.
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 62 / 1
Powers of Two (Time in Seconds)
Suppose we double 1 second and double the amount of time again. And, we do
this again and again.
0 1 1 second
1 2 2 seconds
2 4 4 seconds
3 8 8 seconds
4 16 16 seconds
5 32 32 seconds
6 64 about a minute
7 128 about 2 minutes
8 256 about 4 minutes
9 512 about 8 minutes
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 63 / 1
Powers of Two
10 1 024 17 minutes
..
.
19 524 288 one week
20 1 048 576 two weeks
..
.
25 33 554 432 a year
..
.
30 1 073 741 824 34 years
40 1 099 511 627 776 37 millennia
50 125 899 906 842 624
60 1 152 921 504 606 846 976 age of universe
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 64 / 1
Powers of Two
SI prefixes are not supposed to be used for powers of 2 (just powers of 10).
Sadly, abuse of SI prefixes in compter technology has led to confusion. Whereas
1GHz usually means 109 instructions per second, 1GB usually means 29 bytes.
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 65 / 1
Powers of Two
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 66 / 1
One challenge in computer science is the vast scale of computing devices.
A computer may have a terabyte (1012 bytes) worth of storage. A computer may
execute ten instructions every nanosecond (10−9 seconds).
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 67 / 1
Layers
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 68 / 1
Car dashboard in an interface.
The details of the engine are immaterial to the user (but not to the mechanic).
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 69 / 1
Interface Layers
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 70 / 1
Computing is complex. There are many layers of interesting stuff between the
person and the automaton.
• person (user)
• user-interface (mouse, etc)
• application (program)
• high-level programming language
• machine language
• operating system (OS)
• hardware
• logical devices
• physics
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 71 / 1
Definitions
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 72 / 1
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 73 / 1
Simple View of Programming
files
keyboard
program monitor
computer
OS
mouse
The program controls the computer, yet it needs critical assistance (from the
operating system) to communicate with the outside environment and even to run
effectively.
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 74 / 1
Can a Java program print or display a ß (es-zet) character?
Can a Java program draw a red line on the display?
Can a Java program determined which button on the display was clicked or
touched?
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 75 / 1
Can a Java program print or display a ß (es-zet) character?
Can a Java program draw a red line on the display?
Can a Java program determined which button on the display was clicked or
touched?
No, not really; yet we write Java programs to these things all the time. In reality
the capbilites of the system are determined by the hardware and managed by the
operating system.
Nothing can happen without the support of the operating system.
Java APIs abstract external communication. How easy these API’s are to use is
determined by the skill of the software designers.
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 76 / 1
For a deeper appreciation of programming a computer, we should examine briefly
the many layers upon which the user depends.
An important lesson in organizing these complex systems is that the boundaries
should be well chosen. Rapidly changing technology, competing business interests,
and new insights make it impossible to settle these boundaries once and for all.
Whole college classes like computer architecture, operating systems, compiler
construction, and programming languages go into the subjects more deeply.
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 77 / 1
Hardware and Operating System Platform
Application
Memory management
File system
OS:
Process management Networking
CPU Memory
Hardware: Network interface
Monitor
Disk Keyboard
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 78 / 1
Example Platforms
Try:
The Java programming language (and other high-level languages) try to form a
high-level platform.
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 79 / 1
Good interfaces mean you don’t have to understand the lower layers. For example,
you don’t have to understand electronic flip-flops in order to program.
The point is:
• Many interfaces are software constructions, and software interfaces are an
important design problem for programmers
• Many existing interfaces are in flux requiring an understanding of the lower
layers.
Computer Science (Introduction) What is CS? (Layers of Software and Hardware) © 11 April 2021 80 / 1
Computer Hardware
Intel quad
control unit is the part of the cpu that controls all the internal actions of the cpu,
especially the fetch/execute cycle.
arithmetic/logic unit (ALU) is the part of the cpu that does operations: addition,
multiplication, etc.
memory data register (MDR) is the register of the cpu that contains the data to be
stored in the computer’s main storage, or the data after a fetch from the storage.
It acts like a buffer keeping the contents of storage ready for immediate use by the
cpu.
A final note about computers. The computing platform today is less concerned
about the individual computer and more concerned about the network of
interconnected computers on the Internet.
The subject of this course is programming and teaching programming without any
particular programming language does not seem possible.
There are good reasons to learn any programmming language. There is no good
reason to be proficient in one programming langauge over the rest.
There is no best language for learning the others. So a comprise of different
pegadogic, societal, practical, and scientific factors govern the chose of Java.
Computer Science (Introduction) The Java Platform (Why Java?) © 11 April 2021 90 / 1
“Buzz” about Java
Buzz about Java might mean more jobs, more student engagement.
• TIOBE based on search results
• RedMonk based on github/stack overflow
Computer Science (Introduction) The Java Platform (Why Java?) © 11 April 2021 91 / 1
Computer Science (Introduction) The Java Platform (Why Java?) © 11 April 2021 92 / 1
Computer Science (Introduction) The Java Platform (Why Java?) © 11 April 2021 93 / 1
History of Java
Computer Science (Introduction) The Java Platform (History of Java) © 11 April 2021 94 / 1
Versions
JDK 1.0 January 1996
JDK 1.1 February 1997
J2SE 1.2 December 1998
J2SE 1.3 May 2000
J2SE 1.4 February 2002
J2SE 5.0 September 2004
Java SE 6 December 2006
Java SE 7 July 2011
Java SE 8 March 2014
Java SE 9 September 2017
Java SE 10 March 2018
Java SE 11 September 2018
Java SE 12 March 2019
Java SE 13 September 2019
Java SE 14 March 2020
Java SE 15 September 2020
Computer Science (Introduction) The Java Platform (History of Java) © 11 April 2021 95 / 1
• 5 Generics, for-each loop, autoboxing, var args
• 8 Lambda
• 9 Modual system —project Jigsaw
• 10 Inferring the type of local variables from context
• 11 Local variable type inferenence with var
• 13 Switch expressions
• 15 Text blocks. Preview: sealed classes, record classes.
Computer Science (Introduction) The Java Platform (History of Java) © 11 April 2021 96 / 1
enterprise computing
networking
telecommunications
programs
WWW applications databases
• jaotc - static compiler that produces native code for compiled Java methods
• jaotc - static compiler that produces native code for compiled Java methods
• jar - create and manipulaes an archive for classes and resources
• jaotc - static compiler that produces native code for compiled Java methods
• jar - create and manipulaes an archive for classes and resources
• jarsigner - sign and verify Java Archive (JAR) files
• jaotc - static compiler that produces native code for compiled Java methods
• jar - create and manipulaes an archive for classes and resources
• jarsigner - sign and verify Java Archive (JAR) files
• java - launch a Java application
• jaotc - static compiler that produces native code for compiled Java methods
• jar - create and manipulaes an archive for classes and resources
• jarsigner - sign and verify Java Archive (JAR) files
• java - launch a Java application
• javac - read Java class definitions and compile them into bytecode code
• javac - read Java class definitions and compile them into bytecode code
• javadoc - generate HTML pages of API documentation from Java source files
• javap - disassemble one or more class files
• jcmd - send diagnostic command requests to a running JVM
• jconsole - start a graphical console to monitor and manage Java applications
• javadoc - generate HTML pages of API documentation from Java source files
• javap - disassemble one or more class files
• jcmd - send diagnostic command requests to a running JVM
• jconsole - start a graphical console to monitor and manage Java applications
• jdb - find and fix bugs in Java platform programs
• jdeprscan - static analysis tool that scans a jar file (or some other
aggregation of class files) for uses of deprecated API elements
• jdeps - launch the Java class dependency analyzer
• jfr - parse and print Flight Recorder files
• jhsdb - a postmortem debugger to analyze the content of a core dump from a
crashed JVM
• jinfo - generate Java configuration information for a specified Java process
• jlink - assemble set of modules and their dependencies into a runtime image
• jmap - print details of a specified process
• jmod - create JMOD files and list the content of existing JMOD files
• jpackage - package a self-contained Java application
• jps - list the instrumented JVMs on the target system
• jmod - create JMOD files and list the content of existing JMOD files
• jpackage - package a self-contained Java application
• jps - list the instrumented JVMs on the target system
• jrunscript - run a command-line script shell that supports interactive and
batch modes
• jshell - interactively evaluate declarations, statements, and expressions in a
read-eval-print loop (REPL)
• jstack - print Java stack traces of Java threads for a specified Java process
• jstat - monitor JVM statistics
• jstatd - monitor the creation and termination of instrumented Java HotSpot
VMs
• keytool - manage a keystore (database) of cryptographic keys, X.509
certificate chains, and trusted certificates
• rmid - start the activation system daemon that enables objects to be
registered and activated in a Java Virtual Machine (JVM)
• rmiregistry - create and start a remote object registry on the specified port
on the current host
• serialver - return the ‘serialVersionUID‘ for one or more classes in a form
suitable for copying into an evolving class