chapter11 - 1 1 2 PrimitiveDataTypes IntegerTypes...

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

View Full Document Right Arrow Icon
1 Chapter 11 – Type Details and Alternate Coding Mechanisms Primitive Data Types Integer Types Floating-Point Types char  Type ASCII Table Unicode Standard Type Conversions – Promotions, Type Casting Prefix/Postfix Modes for Increment/Decrement Operators Embedded Assignment Expressions Conditional Operator Expressions Expression Evaluation Practice Short-Circuit Evaluation Empty Statement break  Statement Within a Loop 1 2
Background image of page 1

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

View Full Document Right Arrow Icon
2 Primitive Data Types In Java, there are two basic categories of values -  primitive values and objects. For a while now, we've focused on objects. Now let's  return to primitive values and cover them in more  detail. Primitive values are categorized into these primitive  data types: byte short int long , float double , char , boolean 1
Background image of page 2
3 Integer Types To access a data type's minimum and maximum values, use the   MIN_VALUE  and  MAX_VALUE  named constants that come with the  data type's wrapper class. For example, here's how to print the  maximum  int  value: System.out.println("Largest int = " + Integer.MAX_VALUE); Type Storage Wrapper  Class's MIN_VALUE Wrapper  Class's MAX_VALUE byte 8 bits -128 127 short 16 bits -32768 32767 int 32 bits  -2 billion  2 billion long 64 bits  -9*10 18  9*10 18 1 2 3 4 5
Background image of page 3

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

View Full Document Right Arrow Icon
4 Integer Types Default integer constant type =  int . To explicitly force an integer constant to be a  long use an  l  or  L  suffix. This generates a compilation error: long ageOfPlanet = 4540000000; But this, with the L suffix, works just fine: long ageOfPlanet = 4540000000L; 1 2
Background image of page 4
5 Floating-Point Types –  float double Normally, the  double  type is preferred over the  float  type because the  double  type provides more  accuracy. For  double s , the number of significant digits is  approximately 15. For  float s , the number of  significant digits is approximately 6. 1 2 3 4 Type Storage Precisio n Wrapper Class's MIN_NORMAL Wrapper Class's MAX_VALUE float 32 bits 6 digits  1.2 * 10 -38  3.4*10 38 double 64 bits 15 digits  2.2 * 10 -308  1.8*10 308
Background image of page 5

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

View Full Document Right Arrow Icon
6 Floating-Point Types –  float double To access a floating-point data type's minimum and maximum  values, use the  MIN_NORMAL  and  MAX_VALUE  named constants  that come with the data type's wrapper class. Note that a floating-point  MIN_NORMAL  is qualitatively different  from an integer  MIN_VALUE . Instead of being the largest- magnitude negative value, it's the smallest-magnitude positive  value. For floating-point numbers, if you want the largest-magnitude 
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 38

chapter11 - 1 1 2 PrimitiveDataTypes IntegerTypes...

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

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