Chapter 2

Working with Variables and Data Types

In This Chapter

arrow Creating proper variable declarations

arrow Discovering the difference between primitive and reference types

arrow Looking at Java's built-in data types

arrow Introducing strings

arrow Getting input from the console

arrow Getting input if you're using an older version of Java

In this chapter, you find out the basics of working with variables in Java. Variables are the key to making Java programs general purpose. The Hello, World! programs in the previous chapter, for example, are pretty specific: The only thing they say is “Hello, World!” But with a variable, you can make this type of program more general. You could vary the greeting so that sometimes it would say “Hello, World!” and at other times it would say “Greetings, Foolish Mortals.” Or you could personalize the greeting, so that it said “Hello, Bob!” or “Hello, Amanda!”

Variables are also ...

Get Java All-in-One For Dummies, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.