ch02 - Java Programming Fourth Edition Chapter 2 Using Data...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
Java Programming Fourth Edition Chapter 2 Using Data Within a Program
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java Programming, Fourth Edition 2 Objectives • Use constants and variables • Learn about the int data type • Display variables • Write arithmetic statements • Use the Boolean data type
Background image of page 2
Java Programming, Fourth Edition 3 Objectives (continued) • Learn about floating-point data types • Understand numeric type conversion • Work with the char data type • Use the JOptionPane class for GUI input
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java Programming, Fourth Edition 4 Using Constants and Variables • Constant – Cannot be changed while program running • Variable – Might change while programming running • Literal constant – Value taken literally at each use
Background image of page 4
Java Programming, Fourth Edition 5 Using Constants and Variables (continued) • Variable – Named memory location – Use to store value – Can hold only one value at a time – Value can change • Data type – Type of data that can be stored – How much memory item occupies – What types of operations can be performed on data
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java Programming, Fourth Edition 6 Using Constants and Variables (continued) • Primitive type – Simple data type • Reference types – More complex data types
Background image of page 6
Java Programming, Fourth Edition 7 Java Primitive Data Types
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java Programming, Fourth Edition 8 Declaring Variables • Name variables – Using naming rules for legal class identifiers • Variable declaration – Statement that reserves named memory location – Includes • Data type • Identifier • Optional assignment operator and assigned value • Ending semicolon
Background image of page 8
Java Programming, Fourth Edition 9 Declaring Variables (continued) • Assignment operator – Equal sign (=) – Value to right assigned to variable on left • Initialization – Assignment made when declaring variable • Assignment – Assignment made after variable declared • Associativity – Order in which operands used with operators
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10 Declaring Variables (continued) • Declare multiple variables of same type in separate statements on different lines int myAge = 25; int yourAge = 19; • Declare variables of different types – Must use separate statement for each type
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/13/2011 for the course 332 351 taught by Professor Staff during the Fall '08 term at Rutgers.

Page1 / 40

ch02 - Java Programming Fourth Edition Chapter 2 Using Data...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online