Download presentation
Presentation is loading. Please wait.
Published byChester Newman Modified over 8 years ago
1
FUNADAMENTAL DATA TYPES LEARNING OBJECTIVES: TO UNDERSTAND INTEGEr AND FLOATING POINT NUMBERS TO RECOGNIZE THE LIMITATIONS OF THE NUMERIC TYPES TO UNDERSTAND THE USE OF CONSTANTS
2
NUMBER TYPES TYPEDESCRIPTIONSIZE intThe integer type with range -2,147,483,648 – 2,147483,647 4 bytes byteA single byte, with range -128 ….1271 byte short the short integer type, with range - 32,768 - 32,767 2 bytes longThe long integer type, with range - 9,223,372,036,854,775,808 …9,223,372,036,854,775,807 8 bytes floatThe double-precision floating-point the with range of about 1038 4 bytes charThe character type represent code units in the Unicode encoding scheme 2 bytes booleanThe type with the two truth values false and true 1 bit
3
Overflow using ints Calculations involving integers can overflow. This happens if the result of the computation exceeds the range for the number type. For example:int n=1000000; System.out.println(n*n); //prints -727379968 the result is truncated to fit into an int,
4
Floating point number limitations The double type has about 15 significant digits, and there are many numbers that cannot be accurately represented as double numbers. Not every value can be represented prisely. Therefore numbers are rounded to the nearest match. For example: double f=4.35; System.out.println(100*f); prints 434.9999999999994
5
How do computers represent numbers? Binary There is no exact representation to the fractional parts of a number. 1/3=0.33333333. Therefore the double type is not appropriate for financial calculations. Professional Programmers usethe BigDecimal type
6
Big Numbers Big numbers are objects of the BigInteger and BigDecimal classes in the java.math package. Big number objects have essentially no limits on their size and precision. Computation is slower than those that involve number types. You cannot use (+,*,-), instead you have to use methods called add, subtract, and multiply
7
Constants Constant values do not change and have special significance for computation. Once the value is set, it cannot change. Constants are declared using all CAPs final double QUARTER_VALUE =.025; final double DIME_VALUE=0.1;
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.