Skip to main content
main-content
Top

About this book

Learn Java for Android Development, Third Edition, is an update of a strong selling book that now includes a primer on Android app development (in Chapter 1 and Appendix C, which is distributed in the book’s code archive). This book teaches programmers the essential Java language skills necessary for effectively picking up and using the new Android SDK platform to build mobile, embedded, and even PC apps, especially game apps.

Android development is hot, and many programmers are interested in joining the fun. However, because this technology is based on Java, you should first obtain a solid grasp of the Java language and its APIs in order to improve your chances of succeeding as an effective Android app developer. This book helps you do that.

Each of the book’s 16 chapters provides an exercise section that gives you the opportunity to reinforce your understanding of the chapter’s material. Answers to the book’s more than 700 exercises are provided in an appendix. A second appendix provides a significant game-oriented Java application, which you can convert into an Android app.

Once you complete this one-of-a-kind book written by Jeff Friesen, an expert Java developer and JavaWorld.com columnist, you should be ready to begin your indie or professional Android app development journey.

Table of Contents

Chapter 1. Getting Started with Java

Abstract
Android apps are written in Java and use various Java application program interfaces (APIs). Because you’ll want to write your own apps, but may be unfamiliar with the Java language and these APIs, this book teaches you about Java as a first step into Android app development. It provides you with Java language fundamentals and Java APIs that are useful when developing apps.
Jeff Friesen

Chapter 2. Learning Language Fundamentals

Abstract
Aspiring Android app developers need to understand the Java language in which an app’s source code is written. This chapter introduces you to this language by focusing on its fundamentals. Specifically, you’ll learn about application structure, comments, identifiers (and reserved words), types, variables, expressions (and literals), and statements.
Jeff Friesen

Chapter 3. Discovering Classes and Objects

Abstract
In Chapter 2, I introduced you to the fundamentals of the Java language. You now know how to write simple applications by inserting statements into a class’s main() method. However, when you try to develop complex applications in this manner, you’re bound to find development tedious, slow, and prone to error. Classes and objects address these problems by simplifying application architecture.
Jeff Friesen

Chapter 4. Discovering Inheritance, Polymorphism, and Interfaces

Abstract
An object-based language is a language that encapsulates state and behaviors in objects. Java’s support for encapsulation (discussed in Chapter 3) qualifies it as an object-based language. However, Java is also an object-oriented language because it supports inheritance and polymorphism (as well as encapsulation). (Object-oriented languages are a subset of object-based languages.) In this chapter, I will introduce you to Java’s language features that support inheritance and polymorphism. Also, I will introduce you to interfaces, Java’s ultimate abstract type mechanism.
Jeff Friesen

Chapter 5. Mastering Advanced Language Features, Part 1

Abstract
In Chapters 2 through 4, I laid a foundation for learning the Java language. In Chapter 5, I will add to this foundation by introducing you to some of Java’s more advanced language features, specifically those features related to nested types, packages, static imports, and exceptions. Additional advanced language features are covered in Chapter 6.
Jeff Friesen

Chapter 6. Mastering Advanced Language Features, Part 2

Abstract
In Chapters 2 through 4, I laid a foundation for learning the Java language, and in Chapter 5, I built onto this foundation by introducing some of Java’s more advanced language features. In this chapter, I will continue to cover advanced language features by focusing on those features related to assertions, annotations, generics, and enums.
Jeff Friesen

Chapter 7. Exploring the Basic APIs, Part 1

Abstract
The standard class library’s java.lang and other packages provide many basic APIs that can benefit your Android apps. For example, you can perform mathematics operations and manipulate strings.
Jeff Friesen

Chapter 8. Exploring the Basic APIs, Part 2

Abstract
There are more basic APIs in the java.lang package and also in java.lang.ref, java.lang.reflect, and java.util to consider for your Android apps. For example, you can add timers to your games.
Jeff Friesen

Chapter 9. Exploring the Collections Framework

Abstract
Applications often must manage collections of objects. Although you can use arrays for this purpose, they are not always a good choice. For example, arrays have fixed sizes, making it tricky to determine an optimal size when you need to store a variable number of objects. Also, arrays can be indexed by integers only, making them unsuitable for mapping arbitrary objects to other objects.
Jeff Friesen

Chapter 10. Exploring the Concurrency Utilities

Abstract
Chapter 7 introduced Java’s Threads API. Significant problems with Threads resulted in the development of the more powerful Concurrency Utilities Framework. In this chapter, I take you on a tour of this framework from Android’s perspective. Note that you won’t find a discussion of newer features, such as the Fork/Join Framework, because Android doesn’t support them.
Jeff Friesen

Chapter 11. Performing Classic I/O

Abstract
Applications often input data for processing and output processing results. Data is input from a file or some other source and is output to a file or some other destination. Java supports I/O via the classic I/O APIs located in the java.io package and the new I/O APIs located in java.nio and related subpackages (and java.util.regex). This chapter introduces you to the classic I/O APIs.
Jeff Friesen

Chapter 12. Accessing Networks

Abstract
Applications often need to access networks to acquire resources (such as images) or to communicate with remote executable entities (such as web services). A network is a group of interconnected nodes (computing devices such as tablets, and peripherals such as scanners or laser printers) that can be shared among the network’s users.
Jeff Friesen

Chapter 13. Migrating to New I/O

Abstract
Chapters 11 and 12 introduced you to Java’s classic I/O APIs. Chapter 11 presented classic I/O in terms of java.io’s File, RandomAccessFile, stream, and writer/reader types. Chapter 12 presented classic I/O in terms of java.net’s socket and URL types.
Jeff Friesen

Chapter 14. Accessing Databases

Abstract
Applications often need to access databases to store and retrieve various kinds of data. A database ( http://en.wikipedia.org/wiki/Database ) is an organized collection of data. Although there are many kinds of databases (such as hierarchical, object-oriented, and relational), relational databases, which organize data into tables that can be related to each other, are common.
Jeff Friesen

Chapter 15. Parsing, Creating, and Transforming XML Documents

Abstract
Applications commonly use XML documents to store and exchange data. In Chapter 15, I introduce XML for the benefit of those who are unfamiliar with this technology.
Jeff Friesen

Chapter 16. Focusing on Odds and Ends

Abstract
I’ve covered much of what you need to know about Java to give you a solid foundation on which to build with Android app fundamentals. However, there still are a few topics that you should first understand. In this chapter, I introduce you to various language, API, and miscellaneous topics (such as design patterns and the Java Native Interface) that you’ll find helpful in an Android context. I also present additional APIs (such as Preferences) that are not as useful for Android apps, but are sure to be useful for non-Android applications.
Jeff Friesen

Chapter 17. Solutions to Exercises

Abstract
Each of Chapters 1 through 16 closes with an “Exercises” section that tests your understanding of the chapter’s material. Solutions to these exercises are presented in this appendix.
Jeff Friesen

Chapter 18. Four of a Kind

Abstract
Application development isn’t an easy task. If you don’t plan carefully before you develop an application, you’ll probably waste your time and money as you endeavour to create it, and waste your users’ time and money when it doesn’t meet their needs.
Jeff Friesen
Additional information