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
SMART_READER_LITE
LIVE PREVIEW

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 .


slide-1
SLIDE 1

Week 1 - Friday

slide-2
SLIDE 2

 What did we talk about last time?  Our first Java program  Hardware

slide-3
SLIDE 3
slide-4
SLIDE 4
slide-5
SLIDE 5
slide-6
SLIDE 6

 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

slide-7
SLIDE 7

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
slide-8
SLIDE 8

Monitor

  • Common visual output device

Speakers

  • Common audio output device

Mouse

  • Common input device

Keyboard

  • Common input device
slide-9
SLIDE 9
slide-10
SLIDE 10

 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
slide-11
SLIDE 11

 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

slide-12
SLIDE 12

 Computer science is built out of layers

(like a burrito)

 No one can understand everything  People tend to focus on a particular level

slide-13
SLIDE 13

User Application

Operating System Hardware

We will program here

slide-14
SLIDE 14
slide-15
SLIDE 15

 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!

slide-16
SLIDE 16

 There are many different programming languages:

  • Java
  • C/C++
  • ML
  • …thousands more

 Each has different advantages in different situations

slide-17
SLIDE 17

 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

slide-18
SLIDE 18

 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

slide-19
SLIDE 19

Computer! Solve a problem; 010101010 010100101 001110010

Execute

Source Code Machine Code Hardware

slide-20
SLIDE 20

 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

slide-21
SLIDE 21

class A { Problem p; p.solve(); } 101110101 101011010 110010011

JVM

010101010 010100101 001110010

Java Source Code Machine Code Hardware Java Bytecode

slide-22
SLIDE 22
  • 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)

slide-23
SLIDE 23

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!

slide-24
SLIDE 24
slide-25
SLIDE 25

 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

slide-26
SLIDE 26

 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?

slide-27
SLIDE 27

 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

slide-28
SLIDE 28

3,482,931

Ones Millions Hundreds Thousands Tens Hundred thousands Ten thousands

slide-29
SLIDE 29

 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

slide-30
SLIDE 30

11111100100

Ones 1024's Sixteens Thirty twos Eights Sixty fours Twos Fours 256's 128's 512's

slide-31
SLIDE 31

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

slide-32
SLIDE 32

 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

slide-33
SLIDE 33
slide-34
SLIDE 34

 We'll talk more about data representation

slide-35
SLIDE 35

 Read Chapter 3