Contents

Preface

Before You Begin

1 Introduction to Android

1.1 Introduction

1.2 Android—The World’s Leading Mobile Operating System

1.3 Android Features

1.4 Android Operating System

1.4.1 Android 2.2 (Froyo)

1.4.2 Android 2.3 (Gingerbread)

1.4.3 Android 3.0 through 3.2 (Honeycomb)

1.4.4 Android 4.0 through 4.0.4 (Ice Cream Sandwich)

1.4.5 Android 4.1–4.3 (Jelly Bean)

1.4.6 Android 4.4 (KitKat)

1.4.7 Android 5.0 and 5.1 (Lollipop)

1.4.8 Android 6 (Marshmallow)

1.5 Downloading Apps from Google Play

1.6 Packages

1.7 Android Software Development Kit (SDK)

1.8 Object-Oriented Programming: A Quick Refresher

1.8.1 The Automobile as an Object

1.8.2 Methods and Classes

1.8.3 Instantiation

1.8.4 Reuse

1.8.5 Messages and Method Calls

1.8.6 Attributes and Instance Variables

1.8.7 Encapsulation

1.8.8 Inheritance

1.8.9 Object-Oriented Analysis and Design (OOAD)

1.9 Test-Driving the Tip Calculator App in an Android Virtual Device (AVD)

1.9.1 Opening the Tip Calculator App’s Project in Android Studio

1.9.2 Creating Android Virtual Devices (AVDs)

1.9.3 Running the Tip Calculator App on the Nexus 6 Smartphone AVD

1.9.4 Running the Tip Calculator App on an Android Device

1.10 Building Great Android Apps

1.11 Android Development Resources

1.12 Wrap-Up

2 Welcome App

Android Studio: Introducing Visual GUI Design, Layouts, Accessibility and Internationalization

2.1 Introduction

2.2 Technologies Overview

2.2.1 Android Studio

2.2.2 LinearLayout, TextView and ImageView

2.2.3 Extensible Markup Language (XML)

2.2.4 App Resources

2.2.5 Accessibility

2.2.6 Internationalization

2.3 Creating an App

2.3.1 Launching Android Studio

2.3.2 Creating a New Project

2.3.3 Create New Project Dialog

2.3.4 Target Android Devices Step

2.3.5 Add an Activity to Mobile Step

2.3.6 Customize the Activity Step

2.4 Android Studio Window

2.4.1 Project Window

2.4.2 Editor Windows

2.4.3 Component Tree Window

2.4.4 App Resource Files

2.4.5 Layout Editor

2.4.6 Default GUI

2.4.7 XML for the Default GUI

2.5 Building the App’s GUI with the Layout Editor

2.5.1 Adding an Image to the Project

2.5.2 Adding an App Icon

2.5.3 Changing RelativeLayout to a LinearLayout

2.5.4 Changing the LinearLayout’s id and orientation

2.5.5 Configuring the TextView’s id and text Properties

2.5.6 Configuring the TextView’s textSize Property—Scaled Pixels and Density-Independent Pixels

2.5.7 Setting the TextView’s textColor Property

2.5.8 Setting the TextView’s gravity Property

2.5.9 Setting the TextView’s layout:gravity Property

2.5.10 Setting the TextView’s layout:weight Property

2.5.11 Adding an ImageView to Display the Image

2.5.12 Previewing the Design

2.6 Running the Welcome App

2.7 Making Your App Accessible

2.8 Internationalizing Your App

2.8.1 Localization

2.8.2 Naming the Folders for Localized Resources

2.8.3 Adding String Translations to the App’s Project

2.8.4 Localizing Strings

2.8.5 Testing the App in Spanish on an AVD

2.8.6 Testing the App in Spanish on a Device

2.8.7 TalkBack and Localization

2.8.8 Localization Checklist

2.8.9 Professional Translation

2.9 Wrap-Up

3 Tip Calculator App

Introducing GridLayout, EditText, SeekBar, Event Handling, NumberFormat, Customizing the App’s Theme and Defining App Functionality with Java

3.1 Introduction

3.2 Test-Driving the Tip Calculator App

3.3 Technologies Overview

3.3.1 Class Activity

3.3.2 Activity Lifecycle Methods

3.3.3 AppCompat Library and Class AppCompatActivity

3.3.4 Arranging Views with a GridLayout

3.3.5 Creating and Customizing the GUI with the Layout Editor and the Component Tree and Properties Windows

3.3.6 Formatting Numbers as Locale-Specific Currency and Percentage Strings

3.3.7 Implementing Interface TextWatcher for Handling EditText Text Changes

3.3.8 Implementing Interface OnSeekBarChangeListener for Handling SeekBar Thumb Position Changes

3.3.9 Material Themes

3.3.10 Material Design: Elevation and Shadows

3.3.11 Material Design: Colors

3.3.12 AndroidManifest.xml

3.3.13 Searching in the Properties Window

3.4 Building the GUI

3.4.1 GridLayout Introduction

3.4.2 Creating the TipCalculator Project

3.4.3 Changing to a GridLayout

3.4.4 Adding the TextViews, EditText and SeekBar

3.4.5 Customizing the Views

3.5 Default Theme and Customizing Theme Colors

3.5.1 parent Themes

3.5.2 Customizing Theme Colors

3.5.3 Common View Property Values as Styles

3.6 Adding the App’s Logic

3.6.1 package and import Statements

3.6.2 MainActivity Subclass of AppCompatActivity

3.6.3 Class Variables and Instance Variables

3.6.4 Overriding Activity Method onCreate

3.6.5 MainActivity Method calculate

3.6.6 Anonymous Inner Class That Implements Interface OnSeekBarChangeListener

3.6.7 Anonymous Inner Class That Implements Interface TextWatcher

3.7 AndroidManifest.xml

3.7.1 manifest Element

3.7.2 application Element

3.7.3 activity Element

3.7.4 intent-filter Element

3.8 Wrap-Up

4 Flag Quiz App

Fragments, Menus, Preferences, Explicit Intents, Handler, AssetManager, Tweened Animations, Animators, Toasts, Color State Lists, Layouts for Multiple Device Orientations, Logging Error Messages for Debugging

4.1 Introduction

4.2 Test-Driving the Flag Quiz App

4.2.1 Configuring the Quiz’s Settings

4.2.2 Taking the Quiz

4.3 Technologies Overview

4.3.1 Menus

4.3.2 Fragments

4.3.3 Fragment Lifecycle Methods

4.3.4 Managing Fragments

4.3.5 Preferences

4.3.6 assets Folder

4.3.7 Resource Folders

4.3.8 Supporting Different Screen Sizes and Resolutions

4.3.9 Determining the Device Orientation

4.3.10 Toasts for Displaying Messages

4.3.11 Using a Handler to Execute a Runnable in the Future

4.3.12 Applying an Animation to a View

4.3.13 Using ViewAnimationUtils to Create a Circular Reveal Animator

4.3.14 Specifying Colors Based on a View’s State Via a Color State List

4.3.15 AlertDialog

4.3.16 Logging Exception Messages

4.3.17 Launching Another Activity Via an Explicit Intent

4.3.18 Java Data Structures

4.3.19 Java SE 7 Features

4.3.20 AndroidManifest.xml

4.4 Creating the Project, Resource Files and Additional Classes

4.4.1 Creating the Project

4.4.2 Blank Activity Template Layouts

4.4.3 Configuring Java SE 7 Support

4.4.4 Adding the Flag Images to the Project

4.4.5 strings.xml and Formatted String Resources

4.4.6 arrays.xml

4.4.7 colors.xml

4.4.8 button_text_color.xml

4.4.9 Editing menu_main.xml

4.4.10 Creating the Flag Shake Animation

4.4.11 preferences.xml for Specifying the App’s Settings

4.4.12 Adding Classes SettingsActivity and SettingsActivityFragment to the Project

4.5 Building the App’s GUI

4.5.1 content_main.xml Layout for Devices in Portrait Orientation

4.5.2 Designing fragment_main.xml Layout

4.5.3 Graphical Layout Editor Toolbar

4.5.4 content_main.xml Layout for Tablet Landscape Orientation

4.6 MainActivity Class

4.6.1 package Statement and import Statements

4.6.2 Fields

4.6.3 Overridden Activity Method onCreate

4.6.4 Overridden Activity Method onStart

4.6.5 Overridden Activity Method onCreateOptionsMenu

4.6.6 Overridden Activity Method onOptionsItemSelected

4.6.7 Anonymous Inner Class That Implements OnSharedPreferenceChangeListener

4.7 MainActivityFragment Class

4.7.1 package and import Statements

4.7.2 Fields

4.7.3 Overridden Fragment Method onCreateView

4.7.4 Method updateGuessRows

4.7.5 Method updateRegions

4.7.6 Method resetQuiz

4.7.7 Method loadNextFlag

4.7.8 Method getCountryName

4.7.9 Method animate

4.7.10 Anonymous Inner Class That Implements OnClickListener

4.7.11 Method disableButtons

4.8 SettingsActivity Class

4.9 SettingsActivityFragment Class

4.10 AndroidManifest.xml

4.11 Wrap-Up

5 Doodlz App

2D Graphics, Canvas, Bitmap, Accelerometer, SensorManager, Multitouch Events, MediaStore, Printing, Android 6.0 Permissions, Gradle

5.1 Introduction

5.2 Test-Driving the Doodlz App in an Android Virtual Device (AVD)

5.3 Technologies Overview

5.3.1 Activity and Fragment Lifecycle Methods

5.3.2 Custom Views

5.3.3 Using SensorManager to Listen for Accelerometer Events

5.3.4 Custom DialogFragments

5.3.5 Drawing with Canvas, Paint and Bitmap

5.3.6 Processing Multiple Touch Events and Storing Lines in Paths

5.3.7 Saving to the Device

5.3.8 Printing and the Android Support Library’s PrintHelper Class

5.3.9 New Android 6.0 (Marshmallow) Permissions Model

5.3.10 Adding Dependencies Using the Gradle Build System

5.4 Creating the Project and Resources

5.4.1 Creating the Project

5.4.2 Gradle: Adding a Support Library to the Project

5.4.3 strings.xml

5.4.4 Importing the Material Design Icons for the App’s Menu Items

5.4.5 MainActivityFragment Menu

5.4.6 Adding a Permission to AndroidManifest.xml

5.5 Building the App’s GUI

5.5.1 content_main.xml Layout for MainActivity

5.5.2 fragment_main.xml Layout for MainActivityFragment

5.5.3 fragment_color.xml Layout for ColorDialogFragment

5.5.4 fragment_line_width.xml Layout for LineWidthDialogFragment

5.5.5 Adding Class EraseImageDialogFragment

5.6 MainActivity Class

5.7 MainActivityFragment Class

5.7.1 package Statement, import Statements and Fields

5.7.2 Overridden Fragment Method onCreateView

5.7.3 Methods onResume and enableAccelerometerListening

5.7.4 Methods onPause and disableAccelerometerListening

5.7.5 Anonymous Inner Class for Processing Accelerometer Events

5.7.6 Method confirmErase

5.7.7 Overridden Fragment Methods onCreateOptionsMenu and onOptionsItemSelected

5.7.8 Method saveImage

5.7.9 Overridden Method onRequestPermissionsResult

5.7.10 Methods getDoodleView and setDialogOnScreen

5.8 DoodleView Class

5.8.1 package Statement and import Statements

5.8.2 static and Instance Variables

5.8.3 Constructor

5.8.4 Overridden View Method onSizeChanged

5.8.5 Methods clear, setDrawingColor, getDrawingColor, setLineWidth and getLineWidth

5.8.6 Overridden View Method onDraw

5.8.7 Overridden View Method onTouchEvent

5.8.8 touchStarted Method

5.8.9 touchMoved Method

5.8.10 touchEnded Method

5.8.11 Method saveImage

5.8.12 Method printImage

5.9 ColorDialogFragment Class

5.9.1 Overridden DialogFragment Method onCreateDialog

5.9.2 Method getDoodleFragment

5.9.3 Overridden Fragment Lifecycle Methods onAttach and onDetach

5.9.4 Anonymous Inner Class That Responds to the Events of the Alpha, Red, Green and Blue SeekBars

5.10 LineWidthDialogFragment Class

5.10.1 Method onCreateDialog

5.10.2 Anonymous Inner Class That Responds to the Events of the widthSeekBar

5.11 EraseImageDialogFragment Class

5.12 Wrap-Up

6 Cannon Game App

Manual Frame-By-Frame Animation, Graphics, Sound, Threading, SurfaceView and SurfaceHolder, Immersive Mode and Full-Screen

6.1 Introduction

6.2 Test-Driving the Cannon Game App

6.3 Technologies Overview

6.3.1 Using the Resource Folder res/raw

6.3.2 Activity and Fragment Lifecycle Methods

6.3.3 Overriding View Method onTouchEvent

6.3.4 Adding Sound with SoundPool and AudioManager

6.3.5 Frame-by-Frame Animation with Threads, SurfaceView and SurfaceHolder

6.3.6 Simple Collision Detection

6.3.7 Immersive Mode

6.4 Building the GUI and Resource Files

6.4.1 Creating the Project

6.4.2 Adjusting the Theme to Remove the App Title and App Bar

6.4.3 strings.xml

6.4.4 Colors

6.4.5 Adding the Sounds to the App

6.4.6 Adding Class MainActivityFragment

6.4.7 Editing activity_main.xml

6.4.8 Adding the CannonView to fragment_main.xml

6.5 Overview of This App’s Classes

6.6 MainActivity Subclass of Activity

6.7 MainActivityFragment Subclass of Fragment

6.8 Class GameElement

6.8.1 Instance Variables and Constructor

6.8.2 Methods update, draw, and playSound

6.9 Blocker Subclass of GameElement

6.10 Target Subclass of GameElement

6.11 Cannon Class

6.11.1 Instance Variables and Constructor

6.11.2 Method align

6.11.3 Method fireCannonball

6.11.4 Method draw

6.11.5 Methods getCannonball and removeCannonball

6.12 Cannonball Subclass of GameElement

6.12.1 Instance Variables and Constructor

6.12.2 Methods getRadius, collidesWith, isOnScreen, and reverseVelocityX

6.12.3 Method update

6.12.4 Method draw

6.13 CannonView Subclass of SurfaceView

6.13.1 package and import Statements

6.13.2 Instance Variables and Constants

6.13.3 Constructor

6.13.4 Overriding View Method onSizeChanged

6.13.5 Methods getScreenWidth, getScreenHeight, and playSound

6.13.6 Method newGame

6.13.7 Method updatePositions

6.13.8 Method alignAndFireCannonball

6.13.9 Method showGameOverDialog

6.13.10 Method drawGameElements

6.13.11 Method testForCollisions

6.13.12 Methods stopGame and releaseResources

6.13.13 Implementing the SurfaceHolder.Callback Methods

6.13.14 Overriding View Method onTouchEvent

6.13.15 CannonThread: Using a Thread to Create a Game Loop

6.13.16 Methods hideSystemBars and showSystemBars

6.14 Wrap-Up

7 WeatherViewer App

REST Web Services, AsyncTask, HttpUrlConnection, Processing JSON Responses, JSONObject, JSONArray, ListView, ArrayAdapter, ViewHolder Pattern, TextInputLayout, FloatingActionButton

7.1 Introduction

7.2 Test-Driving the WeatherViewer App

7.3 Technologies Overview

7.3.1 Web Services

7.3.2 JavaScript Object Notation (JSON) and the org.json Package

7.3.3 HttpUrlConnection Invoking a REST Web Service

7.3.4 Using AsyncTask to Perform Network Requests Outside the GUI Thread

7.3.5 ListView, ArrayAdapter and the View-Holder Pattern

7.3.6 FloatingActionButton

7.3.7 TextInputLayout

7.3.8 Snackbar

7.4 Building the App’s GUI and Resource Files

7.4.1 Creating the Project

7.4.2 AndroidManifest.xml

7.4.3 strings.xml

7.4.4 colors.xml

7.4.5 activity_main.xml

7.4.6 content_main.xml

7.4.7 list_item.xml

7.5 Class Weather

7.5.1 package Statement, import Statements and Instance Variables

7.5.2 Constructor

7.5.3 Method convertTimeStampToDay

7.6 Class WeatherArrayAdapter

7.6.1 package Statement and import Statements

7.6.2 Nested Class ViewHolder

7.6.3 Instance Variable and Constructor

7.6.4 Overridden ArrayAdapter Method getView

7.6.5 AsyncTask Subclass for Downloading Images in a Separate Thread

7.7 Class MainActivity

7.7.1 package Statement and import Statements

7.7.2 Instance Variables

7.7.3 Overridden Activity Method onCreate

7.7.4 Methods dismissKeyboard and createURL

7.7.5 AsyncTask Subclass for Invoking a Web Service

7.7.6 Method convertJSONtoArrayList

7.8 Wrap-Up

8 Twitter® Searches App

SharedPreferences, SharedPreferences.Editor, Implicit Intents, Intent Choosers, RecyclerView, RecyclerView.Adapter, RecyclerView.ViewHolder, RecyclerView.ItemDecoration

8.1 Introduction

8.2 Test-Driving the App

8.2.1 Adding a Favorite Search

8.2.2 Viewing Twitter Search Results

8.2.3 Editing a Search

8.2.4 Sharing a Search

8.2.5 Deleting a Search

8.2.6 Scrolling Through Saved Searches

8.3 Technologies Overview

8.3.1 Storing Key–Value Data in a SharedPreferences File

8.3.2 Implicit Intents and Intent Choosers

8.3.3 RecyclerView

8.3.4 RecyclerView.Adapter and RecyclerView.ViewHolder

8.3.5 RecyclerView.ItemDecoration

8.3.6 Displaying a List of Options in an AlertDialog

8.4 Building the App’s GUI and Resource Files

8.4.1 Creating the Project

8.4.2 AndroidManifest.xml

8.4.3 Adding the RecyclerView Library

8.4.4 colors.xml

8.4.5 strings.xml

8.4.6 arrays.xml

8.4.7 dimens.xml

8.4.8 Adding the Save Button Icon

8.4.9 activity_main.xml

8.4.10 content_main.xml

8.4.11 RecyclerView Item’s Layout: list_item.xml

8.5 MainActivity Class

8.5.1 package and import Statements

8.5.2 MainActivity Fields

8.5.3 Overriden Activity Method onCreate

8.5.4 TextWatcher Event Handler and Method updateSaveFAB

8.5.5 saveButton’s OnClickListener

8.5.6 addTaggedSearch Method

8.5.7 Anonymous Inner Class That Implements View.OnClickListener to Display Search Results

8.5.8 Anonymous Inner Class That Implements View.OnLongClickListener to Share, Edit or Delete a Search

8.5.9 shareSearch Method

8.5.10 deleteSearch Method

8.6 SearchesAdapter Subclass of RecyclerView.Adapter

8.6.1 package Statement, import statements, Instance Variables and Constructor

8.6.2 Nested ViewHolder Subclass of RecyclerView.ViewHolder

8.6.3 Overridden RecyclerView.Adapter Methods

8.7 ItemDivider Subclass of RecyclerView.ItemDecoration

8.8 A Note on Fabric: Twitter’s New Mobile Development Platform

8.9 Wrap-Up

9 Address Book App

FragmentTransactions and the Fragment Back Stack, SQLite, SQLiteDatabase, SQLiteOpenHelper, ContentProvider, ContentResolver, Loader, LoaderManager, Cursor and GUI Styles

9.1 Introduction

9.2 Test-Driving the Address Book App

9.2.1 Adding a Contact

9.2.2 Viewing a Contact

9.2.3 Editing a Contact

9.2.4 Deleting a Contact

9.3 Technologies Overview

9.3.1 Displaying Fragments with FragmentTransactions

9.3.2 Communicating Data Between a Fragment and a Host Activity

9.3.3 Manipulating a SQLite Database

9.3.4 ContentProviders and ContentResolvers

9.3.5 Loader and LoaderManager—Asynchronous Database Access

9.3.6 Defining Styles and Applying Them to GUI Components

9.3.7 Specifying a TextView Background

9.4 Building the GUI and Resource Files

9.4.1 Creating the Project

9.4.2 Creating the App’s Classes

9.4.3 Add the App’s Icons

9.4.4 strings.xml

9.4.5 styles.xml

9.4.6 textview_border.xml

9.4.7 MainActivity’s Layout

9.4.8 ContactsFragment’s Layout

9.4.9 DetailFragment’s Layout

9.4.10 AddEditFragment’s Layout

9.4.11 DetailFragment’s Menu

9.5 Overview of This Chapter’s Classes

9.6 DatabaseDescription Class

9.6.1 static Fields

9.6.2 Nested Class Contact

9.7 AddressBookDatabaseHelper Class

9.8 AddressBookContentProvider Class

9.8.1 AddressBookContentProvider Fields

9.8.2 Overridden Methods onCreate and getType

9.8.3 Overridden Method query

9.8.4 Overridden Method insert

9.8.5 Overridden Method update

9.8.6 Overridden Method delete

9.9 MainActivity Class

9.9.1 Superclass, Implemented Interfaces and Fields

9.9.2 Overridden Method onCreate

9.9.3 ContactsFragment.ContactsFragmentListener Methods

9.9.4 Method displayContact

9.9.5 Method displayAddEditFragment

9.9.6 DetailFragment.DetailFragmentListener Methods

9.9.7 AddEditFragment.AddEditFragmentListener Method

9.10 ContactsFragment Class

9.10.1 Superclass and Implemented Interface

9.10.2 ContactsFragmentListener

9.10.3 Fields

9.10.4 Overridden Fragment Method onCreateView

9.10.5 Overridden Fragment Methods onAttach and onDetach

9.10.6 Overridden Fragment Method onActivityCreated

9.10.7 Method updateContactList

9.10.8 LoaderManager.LoaderCallbacks<Cursor> Methods

9.11 ContactsAdapter Class

9.12 AddEditFragment Class

9.12.1 Superclass and Implemented Interface

9.12.2 AddEditFragmentListener

9.12.3 Fields

9.12.4 Overridden Fragment Methods onAttach, onDetach and onCreateView

9.12.5 TextWatcher nameChangedListener and Method updateSaveButtonFAB

9.12.6 View.OnClickListener saveContactButtonClicked and Method saveContact

9.12.7 LoaderManager.LoaderCallbacks<Cursor> Methods

9.13 DetailFragment Class

9.13.1 Superclass and Implemented Interface

9.13.2 DetailFragmentListener

9.13.3 Fields

9.13.4 Overridden Methods onAttach, onDetach and onCreateView

9.13.5 Overridden Methods onCreateOptionsMenu and onOptionsItemSelected

9.13.6 Method deleteContact and DialogFragment confirmDelete

9.13.7 LoaderManager.LoaderCallback<Cursor> Methods

9.14 Wrap-Up

10 Google Play and App Business Issues

10.1 Introduction

10.2 Preparing Your Apps for Publication

10.2.1 Testing Your App

10.2.2 End User License Agreement

10.2.3 Icons and Labels

10.2.4 Versioning Your App

10.2.5 Licensing to Control Access to Paid Apps

10.2.6 Obfuscating Your Code

10.2.7 Getting a Private Key for Digitally Signing Your App

10.2.8 Featured Image and Screenshots

10.2.9 Promotional App Video

10.3 Pricing Your App: Free or Fee

10.3.1 Paid Apps

10.3.2 Free Apps

10.4 Monetizing Apps with In-App Advertising

10.5 Monetizing Apps: Using In-App Billing to Sell Virtual Goods

10.6 Registering at Google Play

10.7 Setting Up a Google Payments Merchant Account

10.8 Uploading Your Apps to Google Play

10.9 Launching Play Store from Within Your App

10.10 Managing Your Apps in Google Play

10.11 Other Android App Marketplaces

10.12 Other Mobile App Platforms and Porting Your Apps

10.13 Marketing Your Apps

10.14 Wrap-Up

A Introduction to Java Applications

A.1 Introduction

A.2 Your First Program in Java: Printing a Line of Text

A.3 Modifying Your First Java Program

A.4 Displaying Text with printf

A.5 Another Application: Adding Integers

A.6 Memory Concepts

A.7 Arithmetic

A.8 Decision Making: Equality and Relational Operators

A.9 Wrap-Up

B Introduction to Classes, Objects, Methods and Strings

B.1 Introduction

B.2 Declaring a Class with a Method and Instantiating an Object of a Class

B.3 Declaring a Method with a Parameter

B.4 Instance Variables, set Methods and get Methods

B.5 Primitive Types vs. Reference Types

B.6 Initializing Objects with Constructors

B.7 Floating-Point Numbers and Type double

B.8 Wrap-Up

C Control Statements

C.1 Introduction

C.2 Algorithms

C.3 Pseudocode

C.4 Control Structures

C.5 if Single-Selection Statement

C.6 if...else Double-Selection Statement

C.7 while Repetition Statement

C.8 Case Study: Counter-Controlled Repetition

C.9 Case Study: Sentinel-Controlled Repetition

C.10 Case Study: Nested Control Statements

C.11 Compound Assignment Operators

C.12 Increment and Decrement Operators

C.13 Primitive Types

C.14 Essentials of Counter-Controlled Repetition

C.15 for Repetition Statement

C.16 Examples Using the for Statement

C.17 do...while Repetition Statement

C.18 switch Multiple-Selection Statement

C.19 break and continue Statements

C.20 Logical Operators

C.21 Wrap-Up

D Methods: A Deeper Look

D.1 Introduction

D.2 Program Modules in Java

D.3 static Methods, static Fields and Class Math

D.4 Declaring Methods with Multiple Parameters

D.5 Notes on Declaring and Using Methods

D.6 Method-Call Stack and Activation Records

D.7 Argument Promotion and Casting

D.8 Java API Packages

D.9 Introduction to Random-Number Generation

D.9.1 Scaling and Shifting of Random Numbers

D.9.2 Random-Number Repeatability for Testing and Debugging

D.10 Case Study: A Game of Chance; Introducing Enumerations

D.11 Scope of Declarations

D.12 Method Overloading

D.13 Wrap-Up

E Arrays and ArrayLists

E.1 Introduction

E.2 Arrays

E.3 Declaring and Creating Arrays

E.4 Examples Using Arrays

E.5 Case Study: Card Shuffling and Dealing Simulation

E.6 Enhanced for Statement

E.7 Passing Arrays to Methods

E.8 Case Study: Class GradeBook Using an Array to Store Grades

E.9 Multidimensional Arrays

E.10 Case Study: Class GradeBook Using a Two-Dimensional Array

E.11 Class Arrays

E.12 Introduction to Collections and Class ArrayList

E.13 Wrap-Up

F Classes and Objects: A Deeper Look

F.1 Introduction

F.2 Time Class Case Study

F.3 Controlling Access to Members

F.4 Referring to the Current Object’s Members with the this Reference

F.5 Time Class Case Study: Overloaded Constructors

F.6 Default and No-Argument Constructors

F.7 Composition

F.8 Enumerations

F.9 Garbage Collection

F.10 static Class Members

F.11 final Instance Variables

F.12 Packages

F.13 Package Access

F.14 Wrap-Up

G Object-Oriented Programming: Inheritance and Polymorphism

G.1 Introduction to Inheritance

G.2 Superclasses and Subclasses

G.3 protected Members

G.4 Relationship between Superclasses and Subclasses

G.4.1 Creating and Using a CommissionEmployee Class

G.4.2 Creating and Using a BasePlusCommissionEmployee Class

G.4.3 Creating a CommissionEmployeeBasePlusCommissionEmployee Inheritance Hierarchy

G.4.4 CommissionEmployeeBasePlusCommissionEmployee Inheritance Hierarchy Using protected Instance Variables

G.4.5 CommissionEmployeeBasePlusCommissionEmployee Inheritance Hierarchy Using private Instance Variables

G.5 Class Object

G.6 Introduction to Polymorphism

G.7 Polymorphism: An Example

G.8 Demonstrating Polymorphic Behavior

G.9 Abstract Classes and Methods

G.10 Case Study: Payroll System Using Polymorphism

G.10.1 Abstract Superclass Employee

G.10.2 Concrete Subclass SalariedEmployee

G.10.3 Concrete Subclass HourlyEmployee

G.10.4 Concrete Subclass CommissionEmployee

G.10.5 Indirect Concrete Subclass BasePlusCommissionEmployee

G.10.6 Polymorphic Processing, Operator instanceof and Downcasting

G.10.7 Summary of the Allowed Assignments Between Superclass and Subclass Variables

G.11 final Methods and Classes

G.12 Case Study: Creating and Using Interfaces

G.12.1 Developing a Payable Hierarchy

G.12.2 Interface Payable

G.12.3 Class Invoice

G.12.4 Modifying Class Employee to Implement Interface Payable

G.12.5 Modifying Class SalariedEmployee for Use in the Payable Hierarchy

G.12.6 Using Interface Payable to Process Invoices and Employees Polymorphically

G.13 Common Interfaces of the Java API

G.14 Wrap-Up

H Exception Handling: A Deeper Look

H.1 Introduction

H.2 Example: Divide by Zero without Exception Handling

H.3 Example: Handling ArithmeticExceptions and InputMismatchExceptions

H.4 When to Use Exception Handling

H.5 Java Exception Hierarchy

H.6 finally Block

H.7 Stack Unwinding and Obtaining Information from an Exception Object

H.8 Wrap-Up

I GUI Components and Event Handling

I.1 Introduction

I.2 Nimbus Look-and-Feel

I.3 Text Fields and an Introduction to Event Handling with Nested Classes

I.4 Common GUI Event Types and Listener Interfaces

I.5 How Event Handling Works

I.6 JButton

I.7 JComboBox; Using an Anonymous Inner Class for Event Handling

I.8 Adapter Classes

I.9 Wrap-Up

J Other Java Topics

J.1 Introduction

J.2 Collections Overview

J.3 Type-Wrapper Classes for Primitive Types

J.4 Interface Collection and Class Collections

J.5 Lists

J.5.1 ArrayList and Iterator

J.5.2 LinkedList

J.5.3 Views into Collections and Arrays Method asList

J.6 Collections Methods

J.6.1 Method sort

J.6.2 Method shuffle

J.7 Interface Queue

J.8 Sets

J.9 Maps

J.10 Introduction to Files and Streams

J.11 Class File

J.12 Introduction to Object Serialization

J.13 Introduction to Multithreading

J.14 Creating and Executing Threads with the Executor Framework

J.15 Overview of Thread Synchronization

J.16 Concurrent Collections Overview

J.17 Multithreading with GUI

J.18 Wrap-Up

K Operator Precedence Chart

L Primitive Types

Index

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

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