Chapter 4
Working with Variables and Data Types
IN THIS CHAPTER
Creating proper variable declarations
Discovering the difference between primitive and reference types
Looking at Java’s built-in data types
Introducing strings
In this chapter, you find out the basics of working with variables in Java. Variables are the key to making Java programs general purpose. Variables are also the key to creating programs that can perform calculations. Suppose that you want to create a program that calculates the area of a circle, given the circle’s radius. Such a program uses two variables: one to represent the radius of the circle and the other to represent the circle’s area. The program asks the user to enter a value for the first variable. Then it calculates the value of the second variable.
Declaring Variables
In Java, you must explicitly declare all variables before using them. This rule is in contrast to some languages — most notably Python, which lets you use variables that haven’t been explicitly declared.
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