Professional Documents
Culture Documents
August Lilleaas
Visit to download the full and correct content document:
https://ebookmass.com/product/pro-kotlin-web-apps-from-scratch-august-lilleaas/
August Lilleaas
This work is subject to copyright. All rights are solely and exclusively
licensed by the Publisher, whether the whole or part of the material is
concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in
any other physical way, and transmission or information storage and
retrieval, electronic adaptation, computer software, or by similar or
dissimilar methodology now known or hereafter developed.
The publisher, the authors, and the editors are safe to assume that the
advice and information in this book are believed to be true and accurate
at the date of publication. Neither the publisher nor the authors or the
editors give a warranty, expressed or implied, with respect to the
material contained herein or for any errors or omissions that may have
been made. The publisher remains neutral with regard to jurisdictional
claims in published maps and institutional affiliations.
1. Setting Up a Development
Environment
August Lilleaas1
Figure 1-1 Download IntelliJ IDEA Community Edition for your platform
For more details on how to install and run IntelliJ IDEA, refer to the
JetBrains website. For example, the download page has a link with
installation instructions in the left sidebar, as seen in Figure 1-1.
Create a New Kotlin Project with IntelliJ IDEA
There are many ways to create a new Kotlin project. For this book,
you’ll be using IntelliJ IDEA to do it. It’s nice to have a GUI to hold your
hand through the process if you’re not familiar with Kotlin and/or the
JVM.
When you launch IntelliJ IDEA, you should see the splash screen
shown in Figure 1-2.
Click “New Project” to create a new Kotlin project using the built-in
wizard in IntelliJ IDEA, shown in Figure 1-3.
Figure 1-3 The New Project screen in IntelliJ IDEA
Use your good taste and judgment to name the project, and adjust
the options as follows:
Make sure you select “New Project” in the left sidebar.
Set Language to Kotlin.
Set Build system to Gradle.
Set Gradle DSL to Kotlin.
Uncheck Add sample code.
You need a JDK, and the easiest way to get one is to have IntelliJ
IDEA download one for you. Click the red “<No SDK>” dropdown in the
New Project dialog shown in Figure 1-3 and choose an appropriate JDK
from the popup that appears, shown in Figure 1-4. JDK 17 or JDK 11 is a
good choice, as those are stable Long-Term Support (LTS) releases.
Figure 1-4 Use IntelliJ IDEA to download a JDK
There are multiple vendors available. They are all full-fledged JDKs
that adhere to the JDK specifications. For the most part, it doesn’t
matter which one you choose. The differences lie in a handful of edge
cases and different defaults. For most web apps, you’ll be able to switch
between vendors and not notice any differences. I personally prefer
Amazon Corretto, mostly out of habit. But I’ve used other vendors in
real-world web apps, such as Azul Zulu. I tend to choose whichever
vendor is most convenient on the platform I use, such as Azul Zulu on
Azure, Amazon Corretto on AWS, and so on.
Make sure you choose a JDK of version 11 or newer. Versions 11 and
17 are both Long-Time Support (LTS) releases, which means they’ll
receive security updates longer than other versions. And later in this
book, you’ll use libraries that require at least version 11 to work.
You can also choose an existing JDK if you have one installed.
Alternatively, you can manage JDK installations yourself, by using
something like sdkman (https://sdkman.io/) on macOS and
Linux and Jabba (https://github.com/shyiko/jabba) on
Windows.
Tip You can have bad luck and choose a JDK version that’s
incompatible with the Gradle version used by IntelliJ IDEA. For
example, the 2021 version of IntelliJ uses Gradle 7.1, which only
works with JDK versions lower than 16. If this happens, delete your
project and start over, using a different JDK or Gradle version.
After IntelliJ IDEA finishes downloading the JDK, click the “Create”
button at the bottom of the New Project dialog shown in Figure 1-3, and
your brand-new project appears, as shown in Figure 1-5.
Figure 1-5 IntelliJ IDEA after it has finished with project initialization
With this setup, IntelliJ IDEA won’t create sample code or pre-
generated files, other than a Gradle build system skeleton. All you have
now is a way to compile and run Kotlin code. And that’s all you need in
this book. There’s no framework with tens of thousands of lines of code
that needs to run first to get anything done.
Tip Gradle is a build system for the Java platform. This is where
you add third-party code as dependencies, configure production
builds, set up automated testing, and more. Maven is also an
excellent choice for building production-grade Kotlin web apps. Most
examples you’ll see in books and online documentation use Gradle,
though, and I’ve only used Gradle in real-world Kotlin apps, so that’s
why I use it in this book.
Kotlin Hello, World!
It’s common when learning a new language to make one’s first program
to be one that outputs “Hello, World!” This ensures that everything is
up and running, that you can compile Kotlin code, and that you can run
it and see that it outputs something.
INDIA: A. D. 1897.
Rejection of American proposals for a
reopening of mints to silver.
INDIA: A. D. 1897-1898.
Frontier wars.
From the early summer of 1897 until beyond the close of the
year, the British were once more seriously in conflict with
the warlike tribes of the Afghan frontier. The risings of the
latter were begun in the Tochi Valley, on the 10th of June,
when a sudden, treacherous attack was made by Waziri tribesmen
on the escort of Mr. Gee, the political agent, at the village
of Maizar. A number of officers and men were killed and
wounded, and the whole party would have been destroyed if
timely reinforcements had not reached them. Over 7,000 troops
were subsequently employed in the suppression and punishment
of this revolt. The next outbreak, in the Swat Valley, was
more extensive. It was ascribed to the preaching of a
fanatical Mohammedan priest, known as "the mud mullah," who
labored to excite a religious war, and was opened, July 26, by
a night attack on the British positions at Malakand and
Chakdarra. The latter outpost, guarding the bridge over the
Swat river, on the road to Chitral, was held by a small
garrison of less than 300 men, who were beleaguered for a
considerable time before relief came. According to an official
return of "wars and military operations on or beyond the
borders of British India in which the Government of India has
been engaged," made to Parliament on the 30th of January,
1900, there were 11,826 troops employed in the operations
immediately consequent on this rising, with the result that
"the insurgents were defeated and the fanatical gatherings
were dispersed; large fines were taken in money and arms." But
other neighboring tribes either gave help to the Swats or were
moved to follow their example, and required to be subdued,
their countries traversed by punitive expeditions and "fines
of money and arms" collected. Before the year closed, these
tasks employed 6,800 men in the Mohmand country, 3,200 in the
Utman Khel country, 7,300 in the Buner country, 14,231 in the
Kurram Valley; and then came the most serious business of all.
The Afridis, who had been subsidized by the government of
India for some years, as guardians of the important Khyber
Pass, were suddenly in arms against their paymasters, in
August, destroying the Khyber posts. This serious hostility
called nearly 44,000 British-Indian troops into the field,
under General Sir William Lockhart, whose successful campaign
was not finished until the following spring. The most serious
engagement of the war with the Afridis was fought at the
village of Dargai, October 18. The final results of the
campaign are thus summarized in the return mentioned above:
"British troops traversed the country of the tribes,
inflicting severe loss on the tribesmen, who were ultimately
reduced to submission: they paid large fines in money and
arms, and friendly relations have since been restored."
Great Britain,
House of Commons Reports and Papers, 1900, 13.
INDIA: A. D. 1898.
Discovery of the birthplace and the tomb of Gautama Buddha.
INDIA: A. D. 1899-1900.
Famine again.
{262}
INDIA: A. D. 1901.
Census of the Empire.
Decrease of population in several of the Native States.
Bombay, 176,000;
Bombay Native States, 17,000;
Baroda, 15,000;
Haidarabad, 2,000;
Madras, 3,000;
Central India States, 1,000.
Total, 214,000.
United States,
Message and Documents
(Abridgment, 1896-1897).
{264}
"But the work does not stop with the rising generation of the
race; it embraces also the adult Indian. … Soon after the
beginning of appropriations for Indian schools, Congress, in
what is called the Severalty Act, provided for every Indian
capable of appreciating its value, and who chose to take it, a
homestead of one hundred and sixty acres to heads of families,
and a smaller number to other members, inalienable and
untaxable for twenty-five years, to be selected by him on the
reservation of his tribe. If he prefer to abandon his tribe
and go elsewhere, he may take his allotment anywhere on the
public domain, free of charge. No English baron has a safer
title to his manor than has each Indian to his homestead. He
cannot part with it for twenty-five years without the consent
of Congress, nor can the United States, without his consent,
be released from a covenant to defend his possession for the
same period. This allotment carries with it also all the
rights, privileges, and immunities of an American citizen;
opens to these Indians, as to all other citizens, the doors of
all the courts; and extends to them the protection of all the
laws, national and state, which affect any other citizen. Any
Indian, if he prefers not to be a farmer, incumbered with one
of these homesteads, may become a citizen of the United
States, and reside and prosecute any calling in any part of
the United States, as securely under this law as anyone else,
by taking up his residence separate and apart from his tribe,
and adopting the habits of civilized life. Thus every door of
opportunity is thrown wide open to every adult Indian, as well
as to those of the next generation.
{266}
{267}