Chapter 1b - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Chapter 1b

Description:

Chapter 1b Using Data ... Arithmetic Operators Priority Type Operator Example 1 Unary - -A + +A cast (type) (float) 2 Multiplicative ... – PowerPoint PPT presentation

Number of Views:92
Avg rating:3.0/5.0
Slides: 18
Provided by: KimC78
Category:
Tags: chapter | example | unary

less

Transcript and Presenter's Notes

Title: Chapter 1b


1
Chapter 1b
  • Using Data

2
Primitive Data Types
  • Type Bytes Constant
  • boolean 1 bit true / false
  • byte 1 127
  • char 2 a
  • double 8 3.14159
  • float 4 3.14159F
  • int 4 10
  • long 8 9223372036L
  • short 2 32767

3
Integer Types
  • Integer characteristics
  • byte, short, int long are all integers
  • Ranges
  • byte -128 to 127
  • short -32,768 to 32,767
  • int -2,147,483,648 to 2,147,483,647
  • long -9,223,372,036,854,775,808 to
  • 9,223,372,036,854,775,807

4
Floating Point Types
  • Floating point characteristics
  • float (6-7 significant digits)
  • range -/1.4023984610-45
  • to
  • -/3.402823471038
  • double (15 significant digits)
  • range -/1.7976931348623157010308 to
  • -/4.9406564584124654410-324

5
Variable Definitions
  • boolean condition true
  • byte age 23
  • char character a
  • double target 123.23
  • float volume 3.12F
  • int counter 0
  • long lightSpeed 186000L
  • short ton 2000

6
Variable Naming Rules Conventions
  • Rules
  • Variable names follow the same rules as those for
    classes
  • Conventions
  • Variable names begin with lowercase letters
  • Each following word is uppercase
  • float volume
  • float totalVolume

7
Arithmetic Operators
  • Priority Type Operator Example
  • 1 Unary - -A
  • A
  • cast (type) (float)
  • 2 Multiplicative AB
  • / A/B
  • AB
  • 4 Additive AB
  • - A-B
  • 13 Assignment AB

8
Relational Logical Operators
  • Operator Description Example
  • lt Less than A lt B
  • gt Greater than A gt B
  • Equal to A B
  • lt Less than or equal to A lt B
  • gt Greater than or equal to A gt B
  • ! Not equal to A ! B
  • Or A B
  • And A B
  • ! Not !A

9
Boolean Operators
  • Operator Description Example
  • And operator x y
  • Or operator x y
  • Exclusive or x y
  • ltlt Shift left x ltlt 1
  • gtgt Signed shift right x gtgt 1
  • gtgtgt Unsigned shift right x gtgtgt 1

10
Type Conversion
  • Type conversion happen in two ways
  • Implicit
  • Explicit
  • Implicit
  • Promotion process float int
  • Explicit
  • type cast (float) x
  • Going from a higher to a lower data type requires
    a type cast

11
Promotion Order
  • Promotion order (highest to lowest)
  • 1. double
  • 2. float
  • 3. long
  • 4. int
  • 5. short
  • 6. byte

12
Unicodes
  • Java characters are represented using Unicode
  • 16 bit coding scheme
  • represented using hexadecimal value
  • char letter \u0041 // A decimal 65
  • Unicode info
  • www.unicode.org

13
Character Escape Sequences
  • Sequences
  • \b backspace \u0008
  • \t tab \u0009
  • \n newline \u000a
  • \f form feed \u000c
  • \r carriage return \u000d
  • \ quotation mark \u0022
  • \ single quotation mark \u0027
  • \\ backslash \u005c

14
Variable Initialization
  • Local variables (variables defined inside
    methods) must be initialized by the programmer
    before using them
  • Instance and class variables are automatically
    initialized by the compiler when declared by the
    programmer

15
FYI
  • All Java floating point data types follow the
    IEEE 754 specification

16
FYI
  • Precedence Chart
  • ( ) Parenthesis
  • ( ) Function call
  • Array subscript
  • . Object member access
  • Prefix increment
  • -- Prefix decrement
  • Unary plus
  • - Unary minus
  • ! Unary logical negation
  • ( type ) Unary casting
  • new Creating Object
  • Multiplication
  • / Division
  • Integer modulus
  • Addition
  • - Subtraction

17
FYI
  • Precedence Chart - cont.
  • lt Less then
  • lt Less than or equal to
  • gt Greater than
  • gt Greater than or equal to
  • instanceof Checking object type
  • Equal comparison
  • ! Not equal
  • Logical AND
  • Logical OR
  • ? Ternary condition
  • Assignment
  • Addition assignment
  • - Subtraction assignment
  • Multiplication assignment
  • / Division assignment
  • Integer modulus assignment
  • Postfix increment
  • -- Postfix decrement
Write a Comment
User Comments (0)
About PowerShow.com