Learn Spring for Android Application Development

Book description

A hands-on guide to Android programming with Spring MVC, Spring Boot, and Spring Security

Key Features

  • Build native Android applications with Spring for Android
  • Explore Reactive programming, concurrency, and multithreading paradigms for building fast and efficient applications
  • Write more expressive and robust code with Kotlin using its coroutines and other latest features

Book Description

As the new official language for Android, Kotlin is attracting new as well as existing Android developers. As most developers are still working with Java and want to switch to Kotlin, they find a combination of these two appealing. This book addresses this interest by bringing together Spring, a widely used Java SE framework for building enterprise-grade applications, and Kotlin.

Learn Spring for Android Application Development will guide you in leveraging some of the powerful modules of the Spring Framework to build lightweight and robust Android apps using Kotlin. You will work with various modules, such as Spring AOP, Dependency Injection, and Inversion of Control, to develop applications with better dependency management. You'll also explore other modules of the Spring Framework, such as Spring MVC, Spring Boot, and Spring Security. Each chapter has practice exercises at the end for you to assess your learning.

By the end of the book, you will be fully equipped to develop Android applications with Spring technologies.

What you will learn

  • Get to grips with the basics of the Spring Framework
  • Write web applications using the Spring Framework with Kotlin
  • Develop Android apps with Kotlin
  • Connect a RESTful web service with your app using Retrofilt
  • Understand JDBC, JPA, MySQL for Spring and SQLite Room for Android
  • Explore Spring Security fundamentals, Basic Authentication, and OAuth2
  • Delve into Concurrency and Reactive programming using Kotlin
  • Develop testable applications with Spring and Android

Who this book is for

If you're an aspiring Android developer or an existing developer who wants to learn how to use Spring to build robust Android applications in Kotlin, this book is for you. Though not necessary, basic knowledge of Spring will assist with understanding key concepts covered in this book.

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Learn Spring for Android Application Development
  3. Dedication
  4. About Packt
    1. Why subscribe?
    2. Packt.com
  5. Contributors
    1. About the authors
    2. About the reviewers
    3. Packt is searching for authors like you
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  7. About the Environment
    1. Technical requirements
    2. Setting up the environment
      1. Spring
      2. Java
      3. Kotlin
      4. Apache Tomcat
        1. Configuring Tomcat
        2. Verifying Tomcat
      5. Integrated development environment
        1. IntelliJ IDEA
        2. Eclipse
    3. Android
    4. Summary
    5. Questions
    6. Further reading
  8. Overview of Kotlin
    1. Technical requirements
    2. Introduction to Kotlin
    3. Setting up the environment
    4. Build tools
    5. Basic syntax
      1. Defining packages
      2. Defining variables
      3. Defining functions
      4. Defining classes
    6. Object-oriented programming
    7. Functions
      1. Functional programming
        1. Declarative and imperative styles
        2. Extension functions
        3. Collections in Kotlin
      2. Higher-order functions
      3. Lambdas
    8. Control flow elements
      1. The if { ... } else { ... } expression
      2. The when { ... } expression
      3. Loops
        1. for loops
        2. while loops
    9. Ranges
    10. String templates
    11. Null safety, reflection, and annotations
      1. Null safety
      2. Reflection
      3. Annotations
    12. Summary
    13. Questions
    14. Further reading
  9. Overview of Spring Framework
    1. Technical requirements
    2. Introduction to Spring
      1. The advantages of Spring
      2. Spring Architecture
        1. Core containers
        2. Data Access/Integration
        3. Web 
        4. Aspect-oriented programming
        5. Instrumentation
        6. Test
    3. Configuring beans
      1. Spring configuration metadata
        1. XML-based configuration
        2. Bean scopes
          1. Singleton scope
          2. Prototype scope
          3. Bean life cycle
          4. Dependency injection
          5. Auto-wiring beans
      2. Annotation-based configuration
        1. The @Required annotation
        2. The @Autowired annotation
        3. The @Qualifier annotation
      3. Code-based configuration
        1. The @Configuration and @Bean annotations
        2. Dependency injection bean
        3. The @Import annotation
        4. Life cycle callbacks
        5. Creating a scope bean
    4. Spring MVC
      1. DispatcherServlet
      2. Creating a project
        1. Converting to a Maven project
        2. Spring MVC dependencies to pom.xml
        3. Creating Spring configuration beans
        4. Creating a controller class
        5. The view 
          1. IntelliJ Ultimate
          2. Eclipse
    5. SpringBoot 
      1. Creating a project
        1. Creating an application class
    6. Summary
    7. Questions
    8. Further reading
  10. Spring Modules for Android
    1. Technical requirements
    2. REST client module
    3. The RestTemplate module
    4. Gradle and Maven repository
      1. Gradle
      2. Maven
      3. RestTemplate constructors
      4. RestTemplate functions
        1. HTTP GET
        2. HTTP POST
        3. HTTP PUT
        4. HTTP DELETE
        5. HTTP OPTIONS
        6. HTTP HEAD
    5. Retrofit
      1. The use of Retrofit
      2. Advantages of Retrofit
      3. Configuring Retrofit
      4. Downloading Retrofit
      5. HTTP request functions
        1. GET
        2. PUT
        3. DELETE
        4. HEAD
    6. Creating an Android app
      1. Gradle information
      2. Gradle dependencies
      3. Creating a model
      4. Implementing a service
      5. Calling callback
      6. Creating an interface
      7. Mobile applications
    7. Summary
    8. Questions
    9. Further reading
  11. Securing Applications with Spring Security
    1. Technical requirements
    2. Spring Security architecture
      1. Authentication
        1. Modifying authentication managers
      2. Authorization
      3. Web security
      4. Method Security
    3. The advantages of Spring Security
    4. Spring Security features
    5. Spring Security modules
      1. Implementing Spring Security
        1. Maven
        2. Gradle
    6. Securing REST with basic authentication
      1. What is basic authentication?
      2. Creating a project
        1. Configuring pom.xml
        2. Configuring a Spring bean
        3. Configuration for Spring Security
        4. Configuring an authentication entry point
        5. Configuring Spring WebApplicationInitializer
        6. Creating a user model
        7. Creating a controller
        8. Using the HTTP client
    7. Creating an Android app
      1. Gradle information
      2. Gradle dependencies
      3. Creating a user model
      4. Implementing the user service
      5. Authenticating with OkHttp interceptors
      6. Calling callbacks
      7. Creating the UI
        1. Creating a custom list adapter
      8. Mobile applications
    8. Securing REST with Spring Security OAuth2
      1. What is OAuth2?
        1. OAuth2 Roles
        2. OAuth2 grant types
      2. Creating a project
        1. Maven dependencies
        2. Configuring the resource server
        3. Configuring the authorization server
        4. Creating the security config
        5. Creating the controller class
        6. Creating the application class
        7. Application properties
        8. Checking the output
          1. Checking unprotected URLs
          2. Getting access tokens
          3. Accessing the protected URL
        9. Common mistakes and errors
    9. Summary
    10. Questions
    11. Further reading
  12. Accessing the Database
    1. Technical requirements
    2. Database
      1. Types of database
        1. Personal database
        2. Relational database
        3. Distributed database
        4. Object-oriented database
        5. NoSQL database
        6. Graph database
        7. Cloud database
    3. Database management system
    4. Data access in the Spring
    5. Java database connectivity in Spring
    6. Creating a sample project using JDBC
      1. Maven dependencies
      2. Creating DataSource
      3. Creating a table in database
      4. Creating a model
      5. Creating row mapper
      6. Creating an API interface
      7. Creating a user repository
        1. JdbcTemplate implementation
        2. Creating HTTP methods for RESTful APIs
          1. Create
          2. READ
          3. UPDATE
          4. DELETE
      8. Creating service
      9. Creating controller
        1. Autowired service
        2. Getting the user list
        3. Getting one user by ID
        4. Inserting a new user
        5. Updating a user
        6. Deleting a user 
      10. Testing the output
        1. Getting the user list
        2. Getting one user by ID
        3. Inserting a new user
        4. Updating a user
        5. Deleting a user 
    7. Java Persistence API
      1. Architecture of JPA
    8. Creating a project using JPA
      1. Maven dependencies
      2. Creating the DataSource
      3. Creating a model
      4. Creating a user repository
      5. Creating controller
        1. Autowired repository
        2. Getting the user list
        3. Getting one user by ID
        4. Inserting new user
        5. Updating a user
        6. Deleting a user 
      6. Seeing the output
    9. Database of client-side application
    10. Architecture components
    11. Creating an Android app
      1. Gradle information
      2. Gradle dependencies
      3. Creating entity
      4. Creating the DAO
      5. Creating the LiveData class
      6. Creating a Room database
      7. Populating the database
      8. Implementing the repository
      9. Creating the ViewModel
      10. Creating new activity
      11. Creating custom RecyclerView adapter
        1. Implementing RecyclerView
      12. Modifying main activity
        1. Getting data from another activity
        2. Adding XML layouts
        3. Switching another activity
      13. Run the app
    12. Summary
    13. Questions
    14. Further reading
  13. Concurrency
    1. Technical requirements
    2. Coroutines
      1. Coroutine basics
      2. Call stacks
      3. Coroutine testing
      4. Coroutine scope
      5. Channels
        1. The producer function
        2. The actor function
    3. Sequential operations
    4. Callback hell
      1. What is a callback?
    5. Thread pools
    6. Summary
    7. Questions
    8. Further reading
  14. Reactive Programming
    1. Technical requirements
    2. Reactive programming with Spring Reactor
      1. The Observer pattern
      2. The Flux publisher
        1. The filter operator
        2. The map operator
        3. The flatMap operator
        4. The reduce operator
        5. The from static method
        6. Cancellation
      3. The Mono publisher
    3. Blocking and non-blocking
    4. RxJava
      1. Flowable
      2. Observable
        1. The debounce operator
        2. The throttle operator
      3. Single
      4. Maybe
      5. Completable
    5. RxJava in Android
      1. The RxAndroid library
      2. The RxBinding library
    6. Summary
    7. Questions
    8. Further reading
  15. Creating an Application
    1. Technical requirements
    2. Project idea
    3. Server side
      1. Creating the design
      2. Developing a database model
      3. Creating a project
      4. Creating entities
        1. Creating a Profile entity
        2. Creating a Post entity
        3. Creating a Comment entity
        4. Creating like entity
      5. Creating repositories
      6. Creating a controller
        1. Creating a profile's HTTP requests
        2. Creating a post's HTTP requests
        3. Creating a comment's HTTP requests
      7. Implementing security
      8. Modified application.properties
    4. Client side
      1. Creating the design
      2. Creating a project
      3. Implementing dependencies 
      4. Creating HomeActivity
        1. Modifying the layout
      5. Creating models
        1. Creating profile model
        2. Creating post model
        3. Creating a comment model
      6. Creating services
        1. Creating the profile service
        2. Creating the post service
        3. Creating the comment service
        4. Creating an API service
      7. Creating a login activity
        1. Modifying the layout
        2. Modifying activity
        3. Login request
      8. Creating the registration activity
        1. Modifying layout
        2. Modifying the activity
        3. Registering a new profile 
      9. Modifying the main activity
        1. Modifying the layout
        2. Modifying the activity
        3. Fetching a post
        4. Submitting a post
        5. Implementing the menu
      10. Modifying the post adapter
        1. Modifying post adapter layouts
        2. Creating the adapter for posts
        3. Modifying the profile layout
        4. Modifying a profile activity
        5. Fetching the profile details
      11. Post details activity
        1. Modifying the post details layout
        2. Modifying the post details activity
        3. Fetching post details
        4. Submitting comment
        5. Modifying the comment adapter
      12. Checking the output
    5. Summary
    6. Questions
    7. Further reading
  16. Testing an Application
    1. Technical requirements
    2. Software testing
    3. JUnit
      1. Advantages of JUnit
      2. Basic annotations of JUnit
      3. Creating a project
      4. Test a project using JUnit 
        1. Creating a test case for a Rest API 
    4. UI testing on Android
    5. Espresso
      1. Creating an application
      2. Injecting dependencies
      3. Modifying the application
      4. Creating testing files
    6. Summary
    7. Questions
    8. Further reading
  17. Assessments
    1. Chapter 1
    2. Chapter 2
    3. Chapter 3
    4. Chapter 4
    5. Chapter 5
    6. Chapter 6
    7. Chapter 7
    8. Chapter 8
    9. Chapter 9
    10. Chapter 10
  18. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Learn Spring for Android Application Development
  • Author(s): S. M. Mohi Us Sunnat, Igor Kucherenko
  • Release date: January 2019
  • Publisher(s): Packt Publishing
  • ISBN: 9781789349252