2.19. Review Questions

 
[Page 59 ( continued )]

Chapter Summary

  • Java provides four integer types ( byte , short , int , long ) that represent integers of four different sizes, and two floating-point types ( float , double ) that represent floating-point numbers of two different precisions. Character type ( char ) represents a single character. These are called primitive data types. Java's primitive types are portable across all computer platforms. They have exactly the same values on all platforms. When they are declared, the variables of these types are created and assigned memory space.


    [Page 60]
  • Java provides operators that perform numeric operations: + (addition), (subtraction), * (multiplication), / (division), and % (remainder). Integer division ( / ) yields an integer result. The remainder operator ( % ) yields the remainder of the division.

  • The increment operator ( ++ ) and the decrement operator ( “ “ ) increment or decrement a variable by 1 . If the operator is prefixed to the variable, the variable is first incremented or decremented by 1 , then used in the expression. If the operator is a suffix to the variable, the variable is incremented or decremented by 1 , but then the original old value is used in the expression.

  • All the numeric operators can be applied to characters . When an operand is a character, the character's Unicode value is used in the operation.

  • You can use casting to convert a value of one type into another type. Casting a variable of a type with a small range to a variable of a type with a larger range is known as widening a type . Casting a variable of a type with a large range to a variable of a type with a smaller range is known as narrowing a type . Widening a type can be performed automatically without explicit casting. Narrowing a type must be performed explicitly.

  • Programming errors can be categorized into three types: syntax errors, runtime errors, and logic errors. Errors that occur during compilation are called syntax errors or compilation errors. Runtime errors are errors that cause a program to terminate abnormally. Logic errors occur when a program does not perform the way it was intended to.

 


Introduction to Java Programming-Comprehensive Version
Introduction to Java Programming-Comprehensive Version (6th Edition)
ISBN: B000ONFLUM
EAN: N/A
Year: 2004
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net