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 . 1 byte = 8 bits = 2 10 bytes 1 kilobyte (kb) 1 megabyte (mb) = 2 20 bytes = 2 30 bytes 1 gigabyte (gb) = 2 40 bytes 1 terabyte (tb)
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 We will Application program here Operating System Hardware
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 Machine Assembly Low High C C++ Java Python Code Language
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
Source Machine Code Code Hardware 010101010 Computer! Solve a 010100101 Execute problem; 001110010
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
Java Source Java Machine Hardware Code Code Bytecode class A { 101110101 010101010 Problem p; 101011010 010100101 JVM p.solve(); 110010011 001110010 }
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 of a computer What does that all really mean? Using semiconductor physics, we can make a tiny little piece of 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
Ten thousands Hundreds 3,482,931 Millions Ones Hundred Tens thousands 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
Sixty fours 256's Sixteens Fours 11111100100 1024's Ones 512's Twos 128's Eights Thirty twos
11111100100 = 1∙2 10 + 1∙2 9 + 1∙2 8 + 1∙2 7 + 1∙2 6 + + 1∙2 5 + 0∙2 4 + 0∙2 3 + 1∙2 2 + 0∙2 1 + 0∙2 0 = 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
Recommend
More recommend