Book 2
Programming Basics
Contents at a Glance
Chapter 1: Java Programming Basics
Looking at the Infamous Hello, World! Program
Dealing with Keywords
Working with Statements
Working with Blocks
Creating Identifiers
Crafting Comments
Introducing Object-Oriented Programming
Importing Java API Classes
Chapter 2: Working with Variables and Data Types
Declaring Variables
Initializing Variables
Using Final Variables (Constants)
Working with Primitive Data Types
Working with Strings
Converting and Casting Numeric Data
Thinking Inside the Box
Understanding Scope
Shadowing Variables
Printing Data with System.out
Getting Input with the Scanner Class
Getting Input with the JOptionPane Class
Using enum to Create Your Own Data Types
Chapter 3: Working with Numbers and Expressions
Working with Arithmetic Operators
Dividing Integers
Combining Operators
Using the Unary Plus and Minus Operators
Using Increment and Decrement Operators
Using the Assignment Operator
Using Compound Assignment Operators
Using the Math Class
Formatting Numbers
Recognizing Weird Things about Java Math
Chapter 4: Making Choices
Using Simple Boolean Expressions
Using if Statements
Using Mr. Spock’s Favorite Operators (Logical Ones, of Course)
Using the Conditional Operator
Comparing Strings
Chapter 5: Going Around in Circles (Or, Using Loops)
Using Your Basic while Loop
Breaking Out of a Loop
Looping Forever
Using the continue Statement
Running do-while Loops
Validating Input from the User
Using the Famous for Loop
Nesting Your Loops
Chapter 6: Pulling a Switcheroo
Battling else-if Monstrosities
Using the switch Statement
Creating Character Cases
Intentionally Leaving Out a Break Statement
Switching with Strings
Enhanced Switch Features with Java 13
Chapter 7: Adding Some Methods to Your Madness
The Joy of Methods
The Basics of Making Methods
Methods That Return Values
Methods That Take Parameters
Chapter 8: Handling Exceptions
Understanding Exceptions
Catching Exceptions
Handling Exceptions with a Preemptive Strike
Catching All Exceptions at Once
Displaying the Exception Message
Using a finally Block
Handling Checked Exceptions
Throwing Your Own Exceptions