46,44 €
A hands-on guide to Android programming with Spring MVC, Spring Boot, and Spring Security
Key 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
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.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 329
Veröffentlichungsjahr: 2019
Copyright © 2019 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Commissioning Editor: Aaron LazarAcquisition Editor: Sandeep MishraContent Development Editor: Manjusha MantriTechnical Editor: Riddesh DawneCopy Editor: Safis EditingLanguage Support Editor: Storm MannProject Coordinator: Prajakta NaikProofreader: Safis EditingIndexer: Pratik ShirodkarGraphics: Jisha ChirayilProduction Coordinator: Arvindkumar Gupta
First published: January 2019
Production reference: 1310119
Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK.
ISBN 978-1-78934-925-2
www.packtpub.com
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.
At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
S. M. Mohi Us Sunnat is a passionate Android developer and trainer with over 4 years' experience. He has developed applications using Kotlin as the principal programming language. He is the founder of DreamOgrammerS, a small IT company. He is the organizer of Droidcon Dhaka. He loves community engagement and works on a number of open source projects, including Mozilla Firefox and Brave. He is also the community leader of the Bangladesh Kotlin user group and the Dhaka Twitter developer community of Bangladesh.
Igor Kucherenkois an Android developer at Techery, a software development company that uses Kotlin as the main language for Android development. Currently, he lives in Ukraine, where he is a speaker in the Kotlin Dnipro community, which promotes Kotlin, and shares his knowledge with audiences at meetups. You can find his articles concerning Kotlin and Android development on Medium and in a blog for Yalantis, where he worked previously.
Abid Khan is an application developer and test engineer with over 10 years of experience. He has worked with different programming languages, including C/C++ and Java, and is now working with Kotlin as a primary language for Android development. Abid is also the author of a book, Hands-On Object-Oriented Programming in Kotlin. He lives in Stockholm, Sweden, and spends most of his time reading books, learning new technologies, and blogging.
H. M.Mahedi Hasan Jisan is currently pursuing his master's degree in computer science at the University of Regina, Canada. He is working in the research field under the supervision of a professor. He completed his B.Sc. in computer science and engineering at BRAC University in 2017. He previously worked as a junior software engineer at Cramstack Ltd., from June 2017 to December 2018. Learn Spring for Android Application Development is the first book that he has worked on as a technical reviewer.
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Title Page
Copyright and Credits
Learn Spring for Android Application Development
Dedication
About Packt
Why subscribe?
Packt.com
Contributors
About the authors
About the reviewers
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Download the color images
Conventions used
Get in touch
Reviews
About the Environment
Technical requirements
Setting up the environment
Spring
Java
Kotlin
Apache Tomcat
Configuring Tomcat
Verifying Tomcat
Integrated development environment
IntelliJ IDEA
Eclipse
Android
Summary
Questions
Further reading
Overview of Kotlin
Technical requirements
Introduction to Kotlin
Setting up the environment
Build tools
Basic syntax
Defining packages
Defining variables
Defining functions
Defining classes
Object-oriented programming
Functions
Functional programming
Declarative and imperative styles
Extension functions
Collections in Kotlin
Higher-order functions
Lambdas
Control flow elements
The if { ... } else { ... } expression
The when { ... } expression
Loops
for loops
while loops
Ranges
String templates
Null safety, reflection, and annotations
Null safety
Reflection
Annotations
Summary
Questions
Further reading
Overview of Spring Framework
Technical requirements
Introduction to Spring
The advantages of Spring
Spring Architecture
Core containers
Data Access/Integration
Web 
Aspect-oriented programming
Instrumentation
Test
Configuring beans
Spring configuration metadata
XML-based configuration
Bean scopes
Singleton scope
Prototype scope
Bean life cycle
Dependency injection
Auto-wiring beans
Annotation-based configuration
The @Required annotation
The @Autowired annotation
The @Qualifier annotation
Code-based configuration
The @Configuration and @Bean annotations
Dependency injection bean
The @Import annotation
Life cycle callbacks
Creating a scope bean
Spring MVC
DispatcherServlet
Creating a project
Converting to a Maven project
Spring MVC dependencies to pom.xml
Creating Spring configuration beans
Creating a controller class
The view 
IntelliJ Ultimate
Eclipse
SpringBoot 
Creating a project
Creating an application class
Summary
Questions
Further reading
Spring Modules for Android
Technical requirements
REST client module
The RestTemplate module
Gradle and Maven repository
Gradle
Maven
RestTemplate constructors
RestTemplate functions
HTTP GET
HTTP POST
HTTP PUT
HTTP DELETE
HTTP OPTIONS
HTTP HEAD
Retrofit
The use of Retrofit
Advantages of Retrofit
Configuring Retrofit
Downloading Retrofit
HTTP request functions
GET
PUT
DELETE
HEAD
Creating an Android app
Gradle information
Gradle dependencies
Creating a model
Implementing a service
Calling callback
Creating an interface
Mobile applications
Summary
Questions
Further reading
Securing Applications with Spring Security
Technical requirements
Spring Security architecture
Authentication
Modifying authentication managers
Authorization
Web security
Method Security
The advantages of Spring Security
Spring Security features
Spring Security modules
Implementing Spring Security
Maven
Gradle
Securing REST with basic authentication
What is basic authentication?
Creating a project
Configuring pom.xml
Configuring a Spring bean
Configuration for Spring Security
Configuring an authentication entry point
Configuring Spring WebApplicationInitializer
Creating a user model
Creating a controller
Using the HTTP client
Creating an Android app
Gradle information
Gradle dependencies
Creating a user model
Implementing the user service
Authenticating with OkHttp interceptors
Calling callbacks
Creating the UI
Creating a custom list adapter
Mobile applications
Securing REST with Spring Security OAuth2
What is OAuth2?
OAuth2 Roles
OAuth2 grant types
Creating a project
Maven dependencies
Configuring the resource server
Configuring the authorization server
Creating the security config
Creating the controller class
Creating the application class
Application properties
Checking the output
Checking unprotected URLs
Getting access tokens
Accessing the protected URL
Common mistakes and errors
Summary
Questions
Further reading
Accessing the Database
Technical requirements
Database
Types of database
Personal database
Relational database
Distributed database
Object-oriented database
NoSQL database
Graph database
Cloud database
Database management system
Data access in the Spring
Java database connectivity in Spring
Creating a sample project using JDBC
Maven dependencies
Creating DataSource
Creating a table in database
Creating a model
Creating row mapper
Creating an API interface
Creating a user repository
JdbcTemplate implementation
Creating HTTP methods for RESTful APIs
Create
READ
UPDATE
DELETE
Creating service
Creating controller
Autowired service
Getting the user list
Getting one user by ID
Inserting a new user
Updating a user
Deleting a user 
Testing the output
Getting the user list
Getting one user by ID
Inserting a new user
Updating a user
Deleting a user 
Java Persistence API
Architecture of JPA
Creating a project using JPA
Maven dependencies
Creating the DataSource
Creating a model
Creating a user repository
Creating controller
Autowired repository
Getting the user list
Getting one user by ID
Inserting new user
Updating a user
Deleting a user 
Seeing the output
Database of client-side application
Architecture components
Creating an Android app
Gradle information
Gradle dependencies
Creating entity
Creating the DAO
Creating the LiveData class
Creating a Room database
Populating the database
Implementing the repository
Creating the ViewModel
Creating new activity
Creating custom RecyclerView adapter
Implementing RecyclerView
Modifying main activity
Getting data from another activity
Adding XML layouts
Switching another activity
Run the app
Summary
Questions
Further reading
Concurrency
Technical requirements
Coroutines
Coroutine basics
Call stacks
Coroutine testing
Coroutine scope
Channels
The producer function
The actor function
Sequential operations
Callback hell
What is a callback?
Thread pools
Summary
Questions
Further reading
Reactive Programming
Technical requirements
Reactive programming with Spring Reactor
The Observer pattern
The Flux publisher
The filter operator
The map operator
The flatMap operator
The reduce operator
The from static method
Cancellation
The Mono publisher
Blocking and non-blocking
RxJava
Flowable
Observable
The debounce operator
The throttle operator
Single
Maybe
Completable
RxJava in Android
The RxAndroid library
The RxBinding library
Summary
Questions
Further reading
Creating an Application
Technical requirements
Project idea
Server side
Creating the design
Developing a database model
Creating a project
Creating entities
Creating a Profile entity
Creating a Post entity
Creating a Comment entity
Creating like entity
Creating repositories
Creating a controller
Creating a profile's HTTP requests
Creating a post's HTTP requests
Creating a comment's HTTP requests
Implementing security
Modified application.properties
Client side
Creating the design
Creating a project
Implementing dependencies 
Creating HomeActivity
Modifying the layout
Creating models
Creating profile model
Creating post model
Creating a comment model
Creating services
Creating the profile service
Creating the post service
Creating the comment service
Creating an API service
Creating a login activity
Modifying the layout
Modifying activity
Login request
Creating the registration activity
Modifying layout
Modifying the activity
Registering a new profile 
Modifying the main activity
Modifying the layout
Modifying the activity
Fetching a post
Submitting a post
Implementing the menu
Modifying the post adapter
Modifying post adapter layouts
Creating the adapter for posts
Modifying the profile layout
Modifying a profile activity
Fetching the profile details
Post details activity
Modifying the post details layout
Modifying the post details activity
Fetching post details
Submitting comment
Modifying the comment adapter
Checking the output
Summary
Questions
Further reading
Testing an Application
Technical requirements
Software testing
JUnit
Advantages of JUnit
Basic annotations of JUnit
Creating a project
Test a project using JUnit 
Creating a test case for a Rest API 
UI testing on Android
Espresso
Creating an application
Injecting dependencies
Modifying the application
Creating testing files
Summary
Questions
Further reading
Assessments
Chapter 1
Chapter 2
Chapter 3
Chapter 4
Chapter 5
Chapter 6
Chapter 7
Chapter 8
Chapter 9
Chapter 10
Other Books You May Enjoy
Leave a review - let other readers know what you think
This book is designed to develop both server and client for an application. We have used the Kotlin language for both the server and client sides. In this book, Spring will be the server-side application, and Android the client-side application. Our primary focus is on those areas that will be able to help a developer develop a secure application with the latest architecture. This book describes the basics of Kotlin and Spring, which will be of benefit if you are unfamiliar with these platforms. We also designed the chapters for implementing security and database in a project. This book delves into the use of Retrofit for handling HTTP requests and SQLite Room for storing data in an Android device. You will also be able to find a way of how to develop a robust, reactive project. Then, you will learn how to test a project using JUnit and Espresso for developing a less bug-prone and stable project.
This book is designed for those developers who are new to Kotlin who wish to develop projects with Spring and Android. Spring for Android provides a functional REST client that supports marshaling objects from JSON. Developers depend on other language platforms, such as PHP and Python for REST API, but Spring comes with Java/Kotlin and a rich content that helps developers to use REST API with the maximum security. There are some dependencies in the application code and Spring removes these dependencies. Nowadays, Java is being replaced by Kotlin, which is lighter and requires fewer lines of code to finish the job.
Chapter 1, About the Environment, creates an environment for both the server side and client side. We will also look into the types of tools that will be needed for the project. We will also understand what we can create with a platform using Spring and Android.
Chapter 2, Overview of Kotlin, covers the basics of Kotlin and examines how to set up the environment and which tools or IDEs are available for Kotlin, including basic syntax and types. We will see the flow structures, including if-else statements, for loops, and while loops. We will also look into the object-oriented programming for Kotlin and cover classes, interfaces, objects, and so on. Functions will also be covered, along with parameters, constructors, and syntax. We will also explain null safety, reflection, and annotations, which are the core features of Kotlin.
Chapter 3, Overview of Spring Framework, covers the basics of Spring Framework and readers will learn how to configure Spring and beans. Dependency injection will be explained in this chapter, along with the architecture of Spring. Readers will learn about Spring MVC and Spring Boot, which are helpful for developing the application as quickly as possible. Spring Data modules will also be explained. We will also cover Spring Security, which provides authentication and other securities for the applications.
Chapter 4, Spring Modules for Android, covers the RestTemplate and Retrofit modules that are connected to the Android projects. An explanation of HTTP clients is provided. Objects to JSON marshaling will also be covered. We will learn how to start and set up the environment. HTTP request methods for both the RestTemplate and Retrofit modules, such as POST, GET, UPDATE, and DELETE, will also be covered, along with the common functionality of other Spring modules and Maven dependency management.
Chapter 5, Securing Applications with Spring Security, covers the requirements for Spring Security. We will learn how to register and configure security and authentication in the web server. We will also learn about the architecture of Spring Security and how to use it for clients. We will see the approach to securing an API for Android application and what the security flow will be. We will learn how to use Spring Security in relation to the REST API. Use of the basic authentication, OAuth2, implicit flow, and the authorization code flow will also be discussed. We will also learn how to connect with Android projects and use basic authentication.
Chapter 6, Accessing the Database, covers the existing Spring data modules. We will also cover JDBC, JPA, H2, MySQL for Spring, and SQLite Room for Android. We will also learn about the use of JPA to create REST API in Spring and fetch the APIs and handle the contents in Android.
Chapter 7, Concurrency, covers coroutines, including topics such as concurrency, parallelism, and thread pools.We will also learn aboutsequential operations and callback hell.
Chapter 8, Reactive Programming, covers reactive programming-related topics, including Spring Reactor and blocking. Readers will also learn about RxJava and RxAndroid in this chapter.
Chapter 9, Creating an Application, starts with the installation of the Android environment. We will then configure Spring on the web server and make a project design. We will then create UI, layout, and RESTful web services and retrieve JSON from the APIs. We will also learn to use Spring Boot and Spring Security for the app. We will then learn how to use Basic Auth to secure the data and give access to users. We will use secured REST API for an Android app and how to handle contents in Android. This application will be based on Kotlin, and we will be taking advantage of the features of Kotlin features, features including null safety, reflection, and annotation, in this application.
Chapter 10, Testing an Application, deals with Spring testing. This includes unit, integration, and UI testing, and their uses. We will get to know the test structure for the project, along with the testing tools such as JUnit and Espresso. Test cases for JUnit and JPA will also be discussed. We will learn how to write UI test cases for the Android application. We will also learn to execute these tests via Android Studio. We will also learn how to test UI using Espresso in Kotlin, and its uses in relation to Kotlin in the Android app. We will also look intoconcurrency and reactive programming in the application.
A basic knowledge of Spring and Kotlin will be helpful, but not essential. MySQL Workbench for the database, Eclipse or IntelliJ IDEA for Spring, Android Studio for Android, and the Postman or Insomnia REST client will be required to run the code samples for this book.
You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packt.com/support and register to have the files emailed directly to you.
You can download the code files by following these steps:
Log in or register at
www.packt.com
.
Select the
SUPPORT
tab.
Click on
Code Downloads & Errata
.
Enter the name of the book in the
Search
box and follow the onscreen instructions.
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
WinRAR/7-Zip for Windows
Zipeg/iZip/UnRarX for Mac
7-Zip/PeaZip for Linux
The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Learn-Spring-for-Android-Application-Development/. In case there's an update to the code, it will be updated on the existing GitHub repository.
We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://www.packtpub.com/sites/default/files/downloads/9781789349252_ColorImages.pdf.
Feedback from our readers is always welcome.
General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at [email protected].
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packt.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.
Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in, and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.
Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!
For more information about Packt, please visit packt.com.
The title of this book makes reference to two of the greatest stage names—Spring, ostensibly the best framework of Java, and Android, which has the greatest number of clients of any operating system. This book will help to you learn and develop a product-ready application on your own which will be lightweight, secure, powerful, and responsive.
Before start learning about the Spring and Android, we will demonstrate examples and code from Kotlin, as this programming language is very new to developers. These days, Kotlin is so popular that Google has declared it the official language of Android. Moreover, the Spring language also supports Kotlin. In this book, we will figure out how to make a robust, secure, and intense server dependent on Spring in the Kotlin language, and use the substance and utilize of this server in an Android application as a client.
In this chapter, you will learn how to set up the environment to create Spring and Android projects, including the required tools and applications. This will include going through steps with accompanying images for visualization purposes. The developers who know Java, at that point, will have some leeway since it is the common platform among Spring and Kotlin. We will demonstrate the code and models with Kotlin that runs on JVM. The Kotlin is designed by JetBrains. On the off-chance that you are new to Kotlin and Spring, being familiar with Java will allow you to write code in Kotlin with ease.
The following topics will be covered in this chapter:
Setting up the environment
Spring
Java
Kotlin
Apache Tomcat
Integrated development environments
Android
To run these frameworks, we need some tools and a specific operating system. Here is the list of these:
Operating system:
Linux
and
m
acOS are recommended for development because we can find all the required packages for these OSes and they are lighter than Windows.
IDE:
My recommended IDE is IntelliJ IDEA (Ultimate version). This is the best IDE for Java, but you have to purchase it to use it. You can also use Eclipse and Netbeans; only one of these is necessary to develop Spring applications. We will show all the projects in IntelliJ, but we will also learn the setup of the environments for Spring in both IntelliJ
IDEA
and Eclipse.
You can find all the examples from this chapter on GitHub: https://github.com/PacktPublishing/Learn-Spring-for-Android-Application-Development/.
An environment setup is one of the prime parts before developing an application. To the developers who are currently working with Spring, feel free to skip this part. This section is for new developers, who need to set up the foundation and the instruments to begin developing.
Here are the steps of how to set up the environment in the accompanying segments.
Spring is the most powerful Java application framework; it is currently the most popular in the enterprise world. It helps to create high-performing applications that have easily-testable and reusable code. This is open source and was written by Rod Johnson, first released under the Apache 2.0 license in June 2003.
To create and run Spring applications, you need some tools and language supports. You also need a server to test and run your project in your operating system. We will show you how to set up the environment for Spring.
The following software and tools are needed with the current version:
Java (version 1.8)
Kotlin (version 1.3)
Apache Tomcat (
version 9.0.11)
IntelliJ Ultimate (version
2018.2.2)
or Eclipse Photon
Spring Framework Libraries (
version 5.0.8.RELEASE)
Java is available in two editions:
Standard Edition (J2SE)
Enterprise Edition (J2EE)
Here, we will opt for Standard Edition. Java is free to download and use for all operating systems.
You can download Java 10.0.2 from http://www.oracle.com/technetwork/java/javase/downloads/index.html. Download for your operating system.
After installation, please check whether Java is installed. To check, open your Terminal and type java --version. If Java is installed successfully, you will see the following Java version:
Alternatively, you will see an error. If this occurs, try to install it again to resolve it.
Developed by JetBrains, Kotlin is an open source and statically-typed programming language. It runs on the Java Virtual Machine (JVM) and can be compiled to JavaScript source code or use the LLVM compiler infrastructure. Kotlin is easy to learn, especially for Java developers.
To use Kotlin, you don't need to download or set it up separately like Java. It comes with the IDEs. Kotlin is a built-in feature of Android Studio, IntelliJ Ultimate, or IntelliJ Community. To use Kotlin in Eclipse, you need to follow these steps:
Go to
help ->
Eclipse Marketplace
from the
Eclipse toolbar.
In the search box, write
Kotlin
, there you will find the
Kotlin
plugin.
Install it and you can write code in
Kotlin
:
We require a steady, free, and open source web server that we can use to create and run Spring-Framework-based ventures. We will utilize Apache Tomcat, which is easy to understand for all developers of Java. You can also use Jetty or Undertow to develop in Spring.
Tomcat is an open source web server. This allows the utilization of Java Servlets and JavaServer Pages (JSP) for the Java server. The core segment of Tomcat is Catalina.
You can download Tomcat 9.0.11 from https://tomcat.apache.org/download-90.cgi.
If you use Tomcat version 9, you have to use Java version 8 or later. According to the Apache Tomcat source, this version builds on Tomcat 8.0.x and 8.5.x, and implements the Servlet 4.0, JSP 2.3, EL 3.0, WebSocket 1.1, and JASPIC 1.1 specifications (the versions required by the Java EE 8 platform).
Let's see how to configure and verify the Tomcat server.
You can configure the Tomcat server in two ways—either using the Terminal or from the IDE. To set up the server, you have to download the Tomcat server's content from https://tomcat.apache.org/download-90.cgi.
Configuring Tomcat by these following steps:
Download a binary distribution of the core module from the link.
Extract the file. This creates a folder named
apache-tomcat-9.0.11
(version number can be changed).
To access it with ease, rename the folder
Tomcat
and move it to
/usr/local
(for Linux) or
/Library
(for macOS):
For Linux, use these steps:
// If you have an older version of Tomcat, then remove it before using
the newer one
sudo rm -rf /usr/local/Tomcat
// To remove exist TomCat
sudo mv ~/Download/Tomcat /usr/local
// To move TomCat from the download directory to your desire direction
For macOS, use these steps:
// If you have an older version of Tomcat, then remove it before using the newer one
sudo rm -rf /Library/Tomcat
// To remove exist TomCat
sudo mv Downloads/Tomcat /Library/
// To move TomCat from the download directory to your desire direction
To check the current directory, type the following:
For Linux:
cd /usr/local/Tomcat/
For macOS:
cd /Library/Tomcat/
Type
ls
to see a list of this directory:
Change the ownership of the
/usr/local/Tomcat
or
/Library/Tomcat
folder hierarchy:
For Linux:
sudo chown -R <your_username> /usr/local/Tomcat/
For macOS:
sudo chown -R <your_username> /Library/Tomcat/
Make all scripts executable:
For Linux:
sudo chmod +x /usr/local/Tomcat/bin/*.sh
For macOS:
sudo chmod +x /Library/Tomcat/bin/*.sh
To check the contents of Tomcat, use the following command:
For Linux:
ls -al /usr/local/Tomcat/bin/*.sh
For macOS:
ls -al /Library/Tomcat/bin/*.sh
You can see that every file is listed with
-rwxr-xr-x@
, where
-x
means executable. Executable demonstrates to us the authorization status to get to the files:
To start and stop, type the following:
For macOS
:
/Library/Tomcat/bin/startup.sh/Library/Tomcat/bin/shutdown.sh
For Linux
:
/usr/local/Tomcat/bin/startup.sh/usr/local/Tomcat/bin/shutdown.sh
To turn on and off the Tomcat server, use this command:
After starting the server, go to your browser and enter
http://localhost:8080
, which will show you the default page:
This is how we can configure Tomcat from the Terminal.
When it comes to writing Java programs, you can use any text editor. However, we encourage you to use an integrated development environment (IDE) because they provide numerous features. IntelliJ IDEA, Eclipse, and NetBeans are the best of them. IntelliJ is a paid IDE, but you can use Eclipse or NetBeans, which are free.
We can use IDE to do the following:
Manage Tomcat
Develop apps and web apps where there is no need to remember the full name of the methods and signatures
Highlight compile errors
In this book, we will work with Eclipse and IntelliJ IDEA. You can download the Ultimate version, which has a 30-day free trial, from https://www.jetbrains.com/idea/download/.
To download the Eclipse, visit http://www.eclipse.org/downloads/packages/.
For Spring, you should download Eclipse IDE for the Java EE Developers version.
For both, once you start IDE, it will ask for a workspace. You can create a folder of your choice and give the path of that folder.
IntelliJ IDEA is a Java coordinated development environment for developing computer software. It is developed by JetBrains and is accessible as an Apache 2 Licensed people group release and in a restrictive business version. Both can be utilized for business development.
Eclipse is an incorporated development environment utilized in computer programming and is the most generally-utilized Java IDE. It contains a base workspace and an extensible module framework for tweaking the environment. Eclipse is composed generally in Java and its essential utility is for developing Java applications, yet it might likewise be utilized to develop applications in other programming dialects by means of modules, including Ada, ABAP, C, C++, C#, Clojure, COBOL, D, Erlang, Fortran, Groovy, Haskell, JavaScript, Julia, Lasso, Lua, NATURAL, Perl, PHP, Prolog, Python, R, Ruby (including the Ruby on Rails framework), Rust, Scala, and Scheme.
To use Kotlin in Eclipse, you will need to install the Kotlin plugin.
After creating a project, you’ll need to integrate the Tomcat server manually. However, if you use Spring Boot, you don't need to do anything because this comes with the Tomcat server.
Follow these steps to create a web project and implement the Tomcat server into your project:
Visit new >
New Dynamic Web Project
.
Provide a
Project Name
.
To integrate Tomcat, click
New Runtime
:
Download version 9+, select
Apache Tomcat v9.0
, and click
Finish
:
Select the latest
Dynamic web module version
.
Click
Finish
.
You will find these files after creating the project:
Go to the
Server
tab, which is in the bottom-left window:
Select
Tomcat v9.0 Server at localhost
.
Hit the start button.
Once the server is started, verify it by visiting
http://localhost:8080
in a browser.
If everything is OK, you can
start and stop the Tom
cat server from here.
Android is a mobile operating system developed by Google, in light of an altered form of the Linux kernel and other open source software and designed basically for touchscreen mobile gadgets, for example, cell phones and tablets. What's more, Google has additionally developed Android TV for televisions, Android Auto for vehicles, and Wear OS for wristwatches, each with a specific UI. Variations of Android are likewise utilized on IoT, advanced cameras, PCs, and various hardware. It was first developed by Android Inc., which Google purchased in 2005, and Android was disclosed in 2007. The first commercial Android devices were launched in September 2008. The current version has since experienced numerous significant discharges, with the present variant being 9 Pie, released in August 2018. The core Android source code is known as Android Open Source Project (AOSP) and is authorized under the Apache License.
In this book, we will figure out how to create a REST API, security, and a database in a Spring platform on a server. We will also learn how to make an Android application and retrieve data from the server, as well as its utilization as a client.
Android Studio is the main IDE among the different IDEs to make an Android application. This is the official IDE for Android. This is based on the IntelliJ IDEA of JetBrains, which is structured especially for Android application development.
To download Android Studio, visit https://developer.android.com/studio/. Here, you will find the latest version of Android Studio to download. The best part is that this includes JRE, the latest SDK, and other important plugins to develop.
Install the Android Studio application
