Chapter 7. Names, Operators, and Accuracy

  • Keywords

  • Punctuation Terminology

  • Names

  • Identifiers

  • Expressions

  • Arrays

  • Operators

  • Associativity

  • How Accurate Are Calculations?

  • Widening and Narrowing Conversions

  • What Happens on Overflow?

  • Some Light Relief—Furby's Brain Transplant

This chapter covers more of the language basics. The information here follows a progression: first, the basics of names and identifiers, then how names are connected in expressions by operators, followed by the rules to evaluate expressions.

The last part of the chapter describes practical limits on accuracy, casting and conversions. If you are new to floating point arithmetic, some of this may come as a bit of a shock. The chapter finishes up by presenting the standard class java.lang.Math.

Keywords

image

Keywords are reserved words, which means they cannot be used as identifiers. Java now has 50 keywords (“enum” became a keyword in JDK 1.5). These are the keywords.

abstract   continue    for          new         switch
assert     default     goto         package     synchronized
boolean    do          if           private     this
break      double      implements   protected   throw
byte       else        import       public      throws
case       enum        instanceof   return      transient
catch      extends     int          short       try
char       final       interface    static      void
class      finally     long         strictfp    volatile
const      float       native       super       while

The keywords const and goto are reserved words, even though they are not used anywhere in Java. This allows future expansion, or (unlikely but claimed) better diagnostic messages if a programmer uses them in a way they might be used in C++.

The words “true” and “false” look like keywords, but technically they are boolean literals. Similarly,”null” looks like it should be in the keyword list, but it is technically the null literal for reference types. The classification of these three words as literals, not keywords, doesn't have any subtle side effects, and it keeps the type system a bit cleaner.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.24.106