CHAPTER 2
FUNDAMENTAL DATA TYPES 
CHAPTER GOALS
To declare and initialize variables and constants
To understand the properties and limitations of integers and floating-point numbers
To appreciate the importance of comments and good code layout
To write arithmetic expressions and assignment statements
To create programs that read and process inputs, and display the results
To learn how to use the Java String type
CHAPTER CONTENTS
Syntax 2.1: Variable Declaration
Syntax 2.3: Constant declaration
Common Error 2.1: Using undeclared or uninitialized Variables
Programming Tip 2.1: Choose descriptive Variable names
Common Error 2.3: Roundoff Errors
Programming Tip 2.2: DO not use Magic numbers
Special Topic 2.1: Numeric Types in Java
Special Topic 2.2: Big numbers
Common Error 2.4: Unintended Integer Division
Common Error 2.5: Unbalanced Parentheses
Programming Tip 2.3: Spaces in Expressions
Special Topic 2.3: Combining Assignment and Arithmetic
Video Example 2.1: using Integer division ![]()
Random Fact 2.1: The Pentium Floating-Point Bug
Programming Tip 2.4: use the API documentation
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access