Unit%203%20 %20 Lecture%20slides%20 %20 Simple%20programs
Upcoming SlideShare
Loading in...5
×
 

Unit%203%20 %20 Lecture%20slides%20 %20 Simple%20programs

on

  • 420 views

lecture nots

lecture nots

Statistics

Views

Total Views
420
Views on SlideShare
418
Embed Views
2

Actions

Likes
1
Downloads
1
Comments
0

1 Embed 2

http://www.slideshare.net 2

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Unit%203%20 %20 Lecture%20slides%20 %20 Simple%20programs Unit%203%20 %20 Lecture%20slides%20 %20 Simple%20programs Presentation Transcript

  • Primitive data types Values Bytes Type - 3.4028234663852886e+38 to - 1.4012984632481707e-45 (and +ve) 4 float -1.7976931348623157e+308 to -4.94065645841246544e-324 (and +ve) 8 double (- 2 63 to 2 63 -1) 8 long -2,147,483,648- +2,147,483,648 (2 31 ) 4 int -32,768 - +32,767 (- 2 15 to 2 7 -1) 2 short 0 to 65535 (-2 7 to 2 7 -1) 2 char false. true 2 boolean
    • int year;
    • Declares a variable to store a whole number
    • year
    • char initial;
    • Declares a variable to store a character
    • initial
    Declaring a variable ? ?
  • Declaring a constant final double TAXRATE = 17.5; Declares a named constant which will hold a decimal value, this is initialised as part of the declaration. The value may then not be changed during program execution. 17.5 TAXRATE
    • The assignment operator = places a value into a variable
    • year
    • int year = 1945;
    • Declares a variable to store a whole number and
    • Initialises its value to 1945
    • year = 1604;
    • The value on right is placed into the memory location
    • known by the identifier year any existing value is lost
    • year = 1604 + age;
    • The expression on right is evaluated and the result
    • placed into the memory location known by the identifier
    • year any existing value is lost (assume age was 25)
    Assigning values 1604 1945 1629
  • Arithmetic Operators
    • Java supports the following arithmetic operators and evaluates them in this order of precedence
      • * Multiplication
      • / Division
      • % Modulus (remainder after integer division)
      • + Addition
      • Subtraction
    • int age1 = 24;
    • int age 2 = 35;
    • int totalAge = 0;
    • float averageAge = 0.0;
    • age1 age2 totalAge averageAge
    Arithmetic Operators 24 35 0 0.0
    • totalAge = age1 + age2;
    • averageAge = totalAge /2;
    • Will these statements make a difference to the values stored in the variables?
    • age1 age2 totalAge averageAge
    Arithmetic Operators 24 35 0 0.0
    • Notice there has been no change to the values of age1 or age2
    • The assignment of new values to totalAge and averageAge has overwritten the original values
    • age1 age2 totalAge averageAge
    Arithmetic Operators 24 35 59 29.5