comp 110 computer basics luv kohli august 25, 2008 mwf 2-2:50 pm sitterson 014 1
TRANSCRIPT
![Page 1: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/1.jpg)
COMP 110COMP 110Computer BasicsComputer Basics
Luv KohliAugust 25, 2008
MWF 2-2:50 pmSitterson 014
1
![Page 2: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/2.jpg)
AnnouncementsAnnouncementsjGRASP
Office Hours◦Link to survey on web site
Honor Code document
2
![Page 3: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/3.jpg)
Questions?Questions?
3
![Page 4: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/4.jpg)
Today in COMP 110Today in COMP 110
4
Hardware and MemoryPrograms and CompilingYour first program
![Page 5: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/5.jpg)
Before ProgrammingBefore ProgrammingNeed to know basics of a
computer◦ If you drive a car you should
know it runs on gasolineWhat’s in the box?
5
![Page 6: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/6.jpg)
Hardware vs. SoftwareHardware vs. SoftwareHardware - physical machine
◦CPU, MemorySoftware - programs that give
instructions to the computer◦Windows XP, Games, jGRASP
6
![Page 7: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/7.jpg)
HardwareHardware
An aside: there is a computer museum in the first floor lobby of Sitterson Hall
![Page 8: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/8.jpg)
Hardware Hardware CPU (Central Processing Unit) - the
“Brain”◦Executes your instructions◦GHz - number of instructions per second, how
fast is the computer◦Dual Core - multiple processing units per CPU,
multiple brains
8
![Page 9: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/9.jpg)
MemoryMemoryHolds data for the computerHow much the “Brain” can rememberMain Memory
◦Memory computer uses for intermediate calculations (program you are running)
◦ExpensiveAuxiliary Memory (Secondary Memory)
◦Disk drives, CDs, Flash drives◦Cheap
9
![Page 10: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/10.jpg)
RAM (random access memory)RAM (random access memory)Your main memoryRandom access?
◦Fast access◦Access any location in memory in constant
time
10
![Page 11: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/11.jpg)
Measuring memoryMeasuring memory2 gigabytes (GB) of RAM
◦Bytes - measurement of memory◦Megabyte (MB) = 1 million (106) bytes (or
1,048,576 = 220 bytes)◦Gigabyte (GB) = 1 billion (109) bytes (or
1,073,741,824 = 230 bytes)
11
![Page 12: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/12.jpg)
What is a byte?What is a byte?1 byte = 8 bits (thanks to Dr. Brooks)Bit = 0 or 1 (off or on)Language of the computer is bits 0 0 1 1 1 0 1 0 - 1 byte of 8 bits
Characters, numbers, encoded as series of bits – a byte:◦ 0: 00110000 ◦ A: 01000001◦ a: 01100001
12
![Page 13: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/13.jpg)
ProgramProgramSet of instructions for a CPU to follow
You will be writing programs◦We will look at one soon
13
public class Hello{ public static void main(String[] args) { System.out.println("Hello world!"); }}
![Page 14: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/14.jpg)
Programming LanguagesProgramming Languages
Your Program
Compiler
Machine Language (Bits)
High-level language (human readable)
Low-level language(computer readable)
14
![Page 15: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/15.jpg)
JavaJavaObject-oriented programming (OOP)
languageBased on the world
around us
15
![Page 16: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/16.jpg)
Objects, Methods, and Classes (oh my!)Objects, Methods, and Classes (oh my!)
Object – program construction that has data and methods
Methods – actions performed by objectsClass – a type of object (e.g. Vehicle, Television)
– objects in same class have same kinds of data and methods
16
Class: Car Object: myCar
Data Make Honda
Model Civic
Methods Accelerate() Accelerate
Brake() Decelerate
![Page 17: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/17.jpg)
Java: three main design principlesJava: three main design principles
Encapsulation
Polymorphism
Inheritance
17
![Page 18: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/18.jpg)
EncapsulationEncapsulationInformation hidingPackaging things up, only part of what is
going on is visible◦myCar.accelerate()◦yourCar.accelerate()
Just call these methods, the car will execute them
18
![Page 19: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/19.jpg)
PolymorphismPolymorphism“Many forms”One method call can cause different
actions in different contexts◦Class Airplane
Object: myAirplane.accelerateToMaxSpeed() 550mph
◦Class Car Object: myCar.accelerateToMaxSpeed() 100mph
19
![Page 20: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/20.jpg)
InheritanceInheritanceWay of organizing classesAt each level, classification becomes
more specific
20
Vehicle
Automobile Bus
Family car Sports car School Bus Luxury Bus
![Page 21: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/21.jpg)
Sample Java Program (section 1.3)Sample Java Program (section 1.3)
import java.util.*;public class FirstProgram{ public static void main(String[] args) { System.out.println("Hello out there."); System.out.println("I will add two numbers for you."); System.out.println("Enter two whole numbers on a line:");
int n1, n2;
Scanner keyboard = new Scanner(System.in); n1 = keyboard.nextInt(); n2 = keyboard.nextInt();
System.out.println("The sum of those two numbers is"); System.out.println(n1 + n2); }}
21
![Page 22: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/22.jpg)
java.util Packagejava.util Packageimport java.util.*;
Package = library of classes (standard programs)Different libraries have different classes and
functions◦ Physics library = Newtonian Physics◦ java.util.* = Java utility classes, used for many things
including reading data from keyboard
22
![Page 23: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/23.jpg)
Begin the programBegin the program
public class FirstProgram{ public static void main(String[] args) {
Begin a program named FirstProgramProgram names should make senseA program is also a class in Java
◦ A program class has a unique method ‘main’
23
![Page 24: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/24.jpg)
Output to screenOutput to screenSystem.out.println("Hello out there.");System.out.println("I will add two numbers for
you.");System.out.println("Enter two whole numbers on a
line:");
Write what is in quotes to screen
24
![Page 25: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/25.jpg)
Invoke methods on objectsInvoke methods on objects
myCar.start();
airplane.land();
System.out.println(“Hi”);
Object
Method
Invoke Method25
Arguments
![Page 26: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/26.jpg)
VariableVariableint n1, n2;
Variable - store piece of datan1 - store integern2 - store integer
26
![Page 27: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/27.jpg)
Create Scanner ObjectCreate Scanner ObjectScanner keyboard = new Scanner(System.in);
Create object or instance (keyboard) of Scanner class
Car myCar = new Car();
Class Object Not always System.in
27
![Page 28: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/28.jpg)
Call method on objectCall method on object
n1 = keyboard.nextInt();
Read an integer from the keyboard and store it in n1
Object Method
Invoke/Call
28
![Page 29: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/29.jpg)
Output to screenOutput to screenSystem.out.println("The sum of those two numbers
is");
System.out.println(n1 + n2);
Add n1 and n2Print the sum to the screen
29
![Page 30: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/30.jpg)
Sample Java Program (section 1.3)Sample Java Program (section 1.3)
import java.util.*;public class FirstProgram{ public static void main(String[] args) { System.out.println("Hello out there."); System.out.println("I will add two numbers for you."); System.out.println("Enter two whole numbers on a line:");
int n1, n2;
Scanner keyboard = new Scanner(System.in); n1 = keyboard.nextInt(); n2 = keyboard.nextInt();
System.out.println("The sum of those two numbers is"); System.out.println(n1 + n2); }}
30
![Page 31: COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson 014 1](https://reader036.vdocument.in/reader036/viewer/2022062516/56649e3f5503460f94b30762/html5/thumbnails/31.jpg)
WednesdayWednesdayDesigning Programs (Read 1.2)If time, start primitive types (start
reading 2.1)
Come to office hours if jGRASP is not working
31