COMP 110 Computer Basics - PowerPoint PPT Presentation

About This Presentation
Title:

COMP 110 Computer Basics

Description:

An aside: there is a computer museum in the first floor lobby of Sitterson Hall. Hardware ... Create Scanner Object. Scanner keyboard = new Scanner(System.in) ... – PowerPoint PPT presentation

Number of Views:73
Avg rating:3.0/5.0
Slides: 32
Provided by: michele9
Learn more at: http://www.cs.unc.edu
Category:
Tags: comp | basics | computer | created | first | the | who

less

Transcript and Presenter's Notes

Title: COMP 110 Computer Basics


1
COMP 110Computer Basics
  • Luv Kohli
  • August 25, 2008
  • MWF 2-250 pm
  • Sitterson 014

1
2
Announcements
  • jGRASP
  • Office Hours
  • Link to survey on web site
  • Honor Code document

2
3
Questions?
3
4
Today in COMP 110
  • Hardware and Memory
  • Programs and Compiling
  • Your first program

4
5
Before Programming
  • Need to know basics of a computer
  • If you drive a car you should know it runs on
    gasoline
  • Whats in the box?

5
6
Hardware vs. Software
  • Hardware - physical machine
  • CPU, Memory
  • Software - programs that give instructions to the
    computer
  • Windows XP, Games, jGRASP

6
7
Hardware
  • An aside there is a computer museum in the first
    floor lobby of Sitterson Hall

8
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
9
Memory
  • Holds data for the computer
  • How much the Brain can remember
  • Main Memory
  • Memory computer uses for intermediate
    calculations (program you are running)
  • Expensive
  • Auxiliary Memory (Secondary Memory)
  • Disk drives, CDs, Flash drives
  • Cheap

9
10
RAM (random access memory)
  • Your main memory
  • Random access?
  • Fast access
  • Access any location in memory in constant time

10
11
Measuring memory
  • 2 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
12
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
13
Program
  • Set of instructions for a CPU to follow
  • You will be writing programs
  • We will look at one soon

public class Hello public static void
main(String args)
System.out.println("Hello world!")
13
14
Programming Languages
High-level language (human readable)
Your Program
Compiler
Low-level language (computer readable)
Machine Language (Bits)
14
15
Java
  • Object-oriented programming (OOP) language
  • Based on the worldaround us

15
16
Objects, Methods, and Classes (oh my!)
  • Object program construction that has data and
    methods
  • Methods actions performed by objects
  • Class a type of object (e.g. Vehicle,
    Television) objects in same class have same
    kinds of data and methods

Class Car Object myCar
Data Make Honda
Model Civic
Methods Accelerate() Accelerate
Brake() Decelerate
16
17
Java three main design principles
  • Encapsulation
  • Polymorphism
  • Inheritance

17
18
Encapsulation
  • Information hiding
  • Packaging 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
19
Polymorphism
  • 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
20
Inheritance
  • Way of organizing classes
  • At each level, classification becomes more
    specific

Vehicle
Automobile
Bus
Luxury Bus
School Bus
Family car
Sports car
20
21
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("T
    he sum of those two numbers is")
    System.out.println(n1 n2)

21
22
java.util Package
  • import 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
23
Begin the program
  • public class FirstProgram public static
    void main(String args)
  • Begin a program named FirstProgram
  • Program names should make sense
  • A program is also a class in Java
  • A program class has a unique method main

23
24
Output to screen
  • 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")
  • Write what is in quotes to screen

24
25
Invoke methods on objects
Method
  • myCar.start()
  • airplane.land()
  • System.out.println(Hi)

Arguments
Object
Invoke Method
25
26
Variable
  • int n1, n2
  • Variable - store piece of data
  • n1 - store integer
  • n2 - store integer

26
27
Create Scanner Object
  • Scanner keyboard new Scanner(System.in)
  • Create object or instance (keyboard) of Scanner
    class
  • Car myCar new Car()

Class
Object
Not always System.in
27
28
Call method on object
Method
Object
n1 keyboard.nextInt() Read an integer from
the keyboard and store it in n1
Invoke/Call
28
29
Output to screen
  • System.out.println("The sum of those two numbers
    is")
  • System.out.println(n1 n2)

Add n1 and n2 Print the sum to the screen
29
30
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("T
    he sum of those two numbers is")
    System.out.println(n1 n2)

30
31
Wednesday
  • Designing Programs (Read 1.2)
  • If time, start primitive types (start reading
    2.1)
  • Come to office hours if jGRASP is not working

31
Write a Comment
User Comments (0)
About PowerShow.com