Week 1 - Friday
Week 1 - Friday What did we talk about last time? Our first Java - - PowerPoint PPT Presentation
Week 1 - Friday What did we talk about last time? Our first Java - - PowerPoint PPT Presentation
Week 1 - Friday What did we talk about last time? Our first Java program Hardware Storage for all the data and instructions on your computer Modern computers store everything as binary digits (bits) which have a value of 0 or 1 .
What did we talk about last time? Our first Java program Hardware
Storage for all the data and instructions on your computer Modern computers store everything as binary digits (bits)
which have a value of 0 or 1. 1 byte = 8 bits 1 kilobyte (kb) = 210 bytes 1 megabyte (mb) = 220 bytes 1 gigabyte (gb) = 230 bytes 1 terabyte (tb) = 240 bytes
Cache
- Actually on the CPU
- Fast and expensive
RAM
- Primary memory for a desktop computer
- Pretty fast and relatively expensive
Flash Drive
- Faster than hard drives
- Seen on USB drives but SSDs are becoming common too
Hard Drive
- Secondary memory for a desktop computer
- Slow and cheap
Optical Drive
- Secondary memory that can usually only be written once
- Very slow and very cheap
Monitor
- Common visual output device
Speakers
- Common audio output device
Mouse
- Common input device
Keyboard
- Common input device
Now that we've (sort of) defined computers, what is computer science? The study of information, computation, and solving problems with
programs
Subfields:
- Theoretical computer science
- Programming languages and compilers
- Operating systems and networking
- Graphics
- Numerical computing
- Information storage, retrieval, and security
- Architecture and hardware
- Artificial intelligence and machine learning
Computers are stupid, but fast Programming is the process of giving them very detailed
instructions about what to do
Usually, programming is done in a rigid, formalized language,
like Java
English is insufficient:
- E.g., "Computer! Solve my relationship problems!"
- Writing a program to solve your relationship problems in Java would
require you to be more detailed and explicit
Computer science is built out of layers
(like a burrito)
No one can understand everything People tend to focus on a particular level
User Application
Operating System Hardware
We will program here
The process of giving computers very detailed instructions
about what to do
How do we do that exactly? First, we need a programming language like Java How do we turn a set of instructions written so that a human
can read them into a set of instructions that a computer can read?
Magic, of course!
There are many different programming languages:
- Java
- C/C++
- ML
- …thousands more
Each has different advantages in different situations
We can classify languages as high or low level High level languages allow you to give more abstract
commands that are more like human thought processes or mathematics
Low level languages are closer to the computer world and give
explicit instructions for the hardware to follow
Python Java C++ C Assembly Language Machine Code
Low High
We use a program called a compiler to turn a high level
language into a low level language
Usually, the low level language is machine code With Java it's a little more complex
Computer! Solve a problem; 010101010 010100101 001110010
Execute
Source Code Machine Code Hardware
Java is more complicated Java runs on a virtual machine, called the JVM Java is compiled to an intermediate stage called bytecode,
which is platform independent
Then, the JVM runs a just-in-time compiler whenever you run
a Java program, to turn the bytecode into platform dependent machine code
class A { Problem p; p.solve(); } 101110101 101011010 110010011
JVM
010101010 010100101 001110010
Java Source Code Machine Code Hardware Java Bytecode
- 1. Write a program in Java
- 2. Compile the program into bytecode
- 3. Run the bytecode using the JVM (which automatically
compiles the bytecode to machine code)
Often goes through phases similar to the following:
- 1. Understand the problem
- 2. Plan a solution to the problem
- 3. Implement the solution in a programming language
- 4. Test the solution
- 5. Maintain the solution and do bug fixes
Factor of 10 rule!
You have heard people talking about all the 1's and 0's inside
- f a computer
What does that all really mean? Using semiconductor physics, we can make a tiny little piece
- f a microchip be in one of two states, say, OFF and ON, like a
switch
If we say that OFF is 0 and ON is 1, then, by using a lot of
these switches, we can represent a lot of 1's and 0's
What do we do with those 1's and 0's? To begin with, we represent numbers How many of you have heard of base 10? How many of you have heard of base 2? What's the definition of a number system with a given base?
Our normal number system is base 10 This means that our digits are: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 Base 10 means that you need 2 digits to represent ten, namely
1 and 0
Each place in the number as you move left corresponds to an
increase by a factor of 10
3,482,931
Ones Millions Hundreds Thousands Tens Hundred thousands Ten thousands
The binary number system is base 2 This means that its digits are: 0 and 1 Base 2 means that you need 2 digits to represent two, namely
1 and 0
Each place in the number as you move left corresponds to an
increase by a factor of 2 instead of 10
11111100100
Ones 1024's Sixteens Thirty twos Eights Sixty fours Twos Fours 256's 128's 512's
11111100100 =
1∙210 + 1∙29 + 1∙28 + 1∙27 + 1∙26 + + 1∙25 + 0∙24 + 0∙23 + 1∙22 + 0∙21 + 0∙20 =
1024 + 512 + 256 + 128 + 64 + 32 + 4 =
2020
You don't actually have to worry about doing binary
conversions when you're coding Java
You should know this information because it explains how
Java is different from math
In math, you can talk about an arbitrarily large number In Java, each number is stored with a specific number of
binary digits
There are limits on how big (or small) a given number can be
We'll talk more about data representation
Read Chapter 3