first few sections of chap. 5 Classes
Review
Basic Data Types
Integer:
byte :1byte
short : 2bytes
int : 4bytes
long : 8bytes
Floating Point Values: (IEEE 754)
float : 4bytes +-3.4 * 10^38 to 7 digit decimal
double: 8bytes +-1.7 * 10^308 to 15 digit decimal
Char:
for characters
each 2 byte Unicode
12:41
Boolean:
Two values: true, False
size is implementation- dependent
---------------------
narrowing conversion : does risk loss of information
conversion from a signed byte/short to char
12:53
booleans not convertable
narow -> big to small
widening conversion -> small to big
long -->bigInt
big Int = smallInt // widening-ok
if i want to write:
smallInt = bigInt; //narrowing error
smallInt(byte) BigInt; // narrowing w/
// explicitcast - OK
-------------------------
Assignment conversion: conversion to match right-hand data type to left hand
bigInt = Smallint converts smallInt to bigInt
casting: explicit conversion specified by the programmer
Promotion: when evaluating expressions, the java compiler tries to make bothoperands be the same dara tyoe using widening conversions.
int a, b;
float c,d;
a = 3
b = 4
c = (a/b); --> zero
d= ((float)a)/b) --> 0.75
long a;
float b;
c = a+ b
1:14
Two values: true, False
size is implementation- dependent
---------------------
Conversion Between Data Types
widening conversion: does not risk loss of informationnarrowing conversion : does risk loss of information
conversion from a signed byte/short to char
12:53
booleans not convertable
narow -> big to small
widening conversion -> small to big
12:57
byte --> smallItlong -->bigInt
big Int = smallInt // widening-ok
if i want to write:
smallInt = bigInt; //narrowing error
smallInt(byte) BigInt; // narrowing w/
// explicitcast - OK
1:03
-------------------------
Assignment conversion: conversion to match right-hand data type to left hand
bigInt = Smallint converts smallInt to bigInt
casting: explicit conversion specified by the programmer
Promotion: when evaluating expressions, the java compiler tries to make bothoperands be the same dara tyoe using widening conversions.
int a, b;
float c,d;
a = 3
b = 4
c = (a/b); --> zero
d= ((float)a)/b) --> 0.75
long a;
float b;
c = a+ b
1:14
Arrays
Many instances of a single basic types.
- Strings are arrays of characters
- Grocery bill is an array of numbers
Java provides arrays as a basic part of the language
-indexed from 0
- all entries are of the same type
- space required for n items of size k is n*k
- indexed by entry
byte[] = arrayeofbyte[5] ;
- Strings are arrays of characters
- Grocery bill is an array of numbers
Java provides arrays as a basic part of the language
-indexed from 0
- all entries are of the same type
- space required for n items of size k is n*k
- indexed by entry
byte[] = arrayeofbyte[5] ;
1:20
diagrams
diagrams
No comments:
Post a Comment