Computer Science 111 Fundamentals of Computer Programming I - PowerPoint PPT Presentation

1 / 29
About This Presentation
Title:

Computer Science 111 Fundamentals of Computer Programming I

Description:

The computer in my office is currently a Dell Optiplex GX150. The next shows a web page where I have done a ... If a bullfrog had. wings, he wouldn't ... – PowerPoint PPT presentation

Number of Views:97
Avg rating:3.0/5.0
Slides: 30
Provided by: tomwh
Category:

less

Transcript and Presenter's Notes

Title: Computer Science 111 Fundamentals of Computer Programming I


1
Computer Science 111Fundamentals of Computer
Programming I
  • Memory
  • Basic Java Syntax
  • and Semantics

2
Shopping for Memory
  • The computer in my office is currently a Dell
    Optiplex GX150.
  • The next slide shows a web page where I have done
    a search to buy memory for this machine.
  • As we discuss memory, well learn the meaning of
    some of the information on this page.

3
(No Transcript)
4
Memory
  • Stores Numbers, text, programs, addresses,
    graphics, sound, video, etc. that are currently
    in use.
  • Divided into fixed size cells (fixed number of
    bits).
  • This size is commonly 8 bits, and this 8-bit unit
    is called a byte. A bit is a binary digit, either
    a 0 or 1.

5
Memory Addresses
Address Cell Content
  • Each cell has an address, an unsigned integer.
  • All accesses to memory are via a specific address

0
1
2
3
6
Basic Memory Operations
  • Memory Fetch
  • Given a specific memory address.
  • Retrieve the content stored at that address.
  • Memory Store
  • Given a specific memory address and
  • a specific value,
  • store the given value in the cell with the
    specified address.

7
Memory Facts and Terminology
  • A cell is the minimum unit of access.
  • Access time is same for all cells - Random Access
    Memory or RAM (nanoseconds - billionths of
    second)
  • ROM - Read only Memory (fetch but not store)
  • Some data items require more than one cell. For
    example, an instruction might need four cells.

8
More on Memory
  • All addresses are of some fixed number of bits,
    say N. Addresses would be 00000 ? 0 00001 ? 1
    Total of 2N cells 11111 ?
    2N 1
  • So, when computer is designed or built, the units
    that hold the memory addresses are of a fixed
    size. This determines the maximum amount of
    memory the machine can have.

9
Terminology
  • Storage capacity
  • K ? 210 1024 ? Kilo as in Kb
  • M ? 220 1,048,576 ? Mega as in Mb
  • G ? 230 1,073,741,824 ?Giga as in Gb
  • Speed
  • 1 ? 1 microsecond 1 millionth of second
  • 1 ms 1 millisecond 1 thousandth of second
  • 1 ns 1 nanosecond 1 billionth of second

10
Back to My Machine
  • Standard memory 64M ? 64 million bytes (cells)
    or character
  • Maximum memory 512M tells us that if the address
    size is N bits then 2N 512M 29
    220 229so the addresses must be 29 bits
    long.

11
My machine (cont.)
  • The page also showed that there are two memory
    slots in my machine. These two slots can be
    filled with memory modules of various sizes. For
    example 64M 0M 64M 64M 64M 256M 256M 256M

12
My machine (cont.)
  • One other fact on the sheet indicated a processor
    speed of 1GHz.
  • This is referred to as the cycle time.
  • A Hertz is one cycle per second.
  • Very roughly, the machine might execute one
    instruction per cycle.
  • So, at 1GHz were talking on the order of a
    billion instructions per second.

13
New Technology?
14
Back to Java Terminology
  • Syntax the formal rules for combining words and
    symbols to form legal statements within the
    language.
  • Semantics the meaning of the statements i.e.,
    what the statement does when executed.

15
Literals
  • Literals are items whose values do not change.
  • "Hello World!" is a string literal234 is an
    integer literal-3145 is also an integer
    literal3.14 is a floating point literal5.25E7
    is also a floating point literal

16
Numeric Data Types and Variables
  • We use the type int for integers (4 bytes)
  • We use the type double for floating point numbers
    (8 bytes)
  • A variable is an item whose value can change
    during the execution of the program. A variable
    has
  • A name
  • A type
  • A location in memory
  • A value stored in this location

17
Declaring Variables
  • Before a variable can be used in a program, it
    must be declared. This consists of giving first
    the type of the variable and then its name.
  • double fahrenheitint age, countKeyboardReader
    readerint num20

18
Object Instantiation.
  • When we declare a variable, memory space is
    created for the value of the variable. For a
    variable which is a reference to an object, the
    object is not created simply by declaring the
    variable, only space for the pointer to the
    object.
  • Creating the object itself is called
    instantiating the object. This is done by
    asking for a new object of the given type.

19
Object Instantiation (cont.)
  • KeyboardReader reader
  • reader new KeyboardReader()
  • OrKeyboardReader reader new KeyboardReader()

20
Comments
  • We often need to put comments into the source
    code of a program. A comment has no effect on the
    execution it is there for the benefit of
    someone who reads the program.
  • Examples would be programmers name, purpose of
    the program, explanations to clarify parts of the
    program, etc.
  • Anything following a // on a single line is a
    comment.
  • Anything between / and / , even many lines,
    is a comment.

21
Identifiers in Java
  • Identifiers are used for naming variables,
    methods, objects, etc.
  • Identifiers are strings of
  • Letters
  • Digits
  • Underscores
  • Dollar signs
  • Can not start with digit
  • No spaces
  • Can not be one of Javas Reserved Words

22
Naming Conventions
  • Names should be meaningful
  • Begin names of variables and methods with lower
    case letter.
  • If name is combination of words, run the words
    together and capitalize all but the first.
  • Class names usually begin with capital.

23
Assignment Statements
  • ltvariablegt ltexpressiongt
  • Note single variable on left hand side
  • Expression should yield result which is of type
    appropriate for the variable.
  • Expression created with literals, variables,
    operators, parentheses to form well-formed
    expression
  • Semantics
  • Expression is evaluated using current values of
    variables
  • Resulting value is stored as new value of the
    variable.

24
Common Operators
 
 
 
25
Examples with integer operations
  • Integer division yields the whole number part of
    the result
  • 6/3 yields 2
  • 6/4 yields 1
  • 5/9 yields 0 (hmm)
  • Modulus gives the remainder upon division
  • 6 3 yields 0
  • 6 4 yields 2
  • 5 9 yields 5

26
Examples with precedence
  • 6 4 5 10 5 5
  • 6 4 5 6 20 26
  • (6 4) 5 10 5 50
  • 10 5 6 1 5 6 1 -1 1 -2
  • 10 (5 6 1) 10 (-1 1) 10 (-2) 12
  • 4 11 6 / 2 4 5 / 2 4 2 6

27
Types of Errors
  • Syntax Errors caught by compiler
  • Run-time occur while program is executing
    (maybe divide by 0)
  • Logic errors runs but gives incorrect results.
    celsius (fahrenheit 32.0) (5/9)

28
Testing as you go
  • As you develop more complex programs, a piece of
    advice is to develop small pieces of the program
    at a time and test each before moving on.
  • This avoids having a large piece of code with an
    errror (bug) and trying to locate it within a big
    program.
  • To do this, you can put in extra output
    statements (writer.print) to see values of
    intermediate results, etc.
  • This technique can also be used to find errors.
    Put in statements that print messages and
    variables at various points in the program to
    trace changes.

29
If a bullfrog had wings, he wouldn't ...
Write a Comment
User Comments (0)
About PowerShow.com