Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views

Beginning Cloud Native Development with MicroProfile, Jakarta EE, and Kubernetes: Java DevOps for Building and Deploying Microservices-based Applications 1st Edition Tarun Telang instant download

The document is about the book 'Beginning Cloud Native Development with MicroProfile, Jakarta EE, and Kubernetes' by Tarun Telang, which focuses on Java DevOps for building and deploying microservices-based applications. It includes various chapters covering cloud computing, cloud-native application development, setting up development environments, building RESTful web services, and microservices architecture. The book is intended for developers looking to enhance their skills in cloud-native technologies and practices.

Uploaded by

bozsikredan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Beginning Cloud Native Development with MicroProfile, Jakarta EE, and Kubernetes: Java DevOps for Building and Deploying Microservices-based Applications 1st Edition Tarun Telang instant download

The document is about the book 'Beginning Cloud Native Development with MicroProfile, Jakarta EE, and Kubernetes' by Tarun Telang, which focuses on Java DevOps for building and deploying microservices-based applications. It includes various chapters covering cloud computing, cloud-native application development, setting up development environments, building RESTful web services, and microservices architecture. The book is intended for developers looking to enhance their skills in cloud-native technologies and practices.

Uploaded by

bozsikredan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 45

Beginning Cloud Native Development with

MicroProfile, Jakarta EE, and Kubernetes: Java


DevOps for Building and Deploying Microservices-
based Applications 1st Edition Tarun Telang pdf
download
https://ebookmeta.com/product/beginning-cloud-native-development-
with-microprofile-jakarta-ee-and-kubernetes-java-devops-for-
building-and-deploying-microservices-based-applications-1st-
edition-tarun-telang/

Download more ebook from https://ebookmeta.com


We believe these products will be a great fit for you. Click
the link to download now, or visit ebookmeta.com
to discover even more!

Beginning Cloud Native Development with MicroProfile,


Jakarta EE, and Kubernetes 1st Edition Tarun Telang

https://ebookmeta.com/product/beginning-cloud-native-development-
with-microprofile-jakarta-ee-and-kubernetes-1st-edition-tarun-
telang/

Cloud Native Devops with Kubernetes: Building,


Deploying, and Scaling Modern Applications in the
Cloud, 2nd Edition Justin Domingus & John Arundel

https://ebookmeta.com/product/cloud-native-devops-with-
kubernetes-building-deploying-and-scaling-modern-applications-in-
the-cloud-2nd-edition-justin-domingus-john-arundel/

Beginning Helidon: Building Cloud-Native Microservices


and Applications 1st Edition Dmitry Kornilov

https://ebookmeta.com/product/beginning-helidon-building-cloud-
native-microservices-and-applications-1st-edition-dmitry-
kornilov-2/

Social media marketing for dummies 4th Edition Shiv


Singh

https://ebookmeta.com/product/social-media-marketing-for-
dummies-4th-edition-shiv-singh/
READY FOR C1 ADVANCED Student's book with key 4th
Edition Amanda French

https://ebookmeta.com/product/ready-for-c1-advanced-students-
book-with-key-4th-edition-amanda-french/

The Wills Eye Manual Office and Emergency Room


Diagnosis and Treatment of Eye Disease Kalla Gervasio

https://ebookmeta.com/product/the-wills-eye-manual-office-and-
emergency-room-diagnosis-and-treatment-of-eye-disease-kalla-
gervasio/

Exploring the Syntax and Semantics of South Asian


Languages 1st Edition Reena Ashem

https://ebookmeta.com/product/exploring-the-syntax-and-semantics-
of-south-asian-languages-1st-edition-reena-ashem/

Pragmatics Pedagogy in English as an International


Language 1st Edition Zia Tajeddin

https://ebookmeta.com/product/pragmatics-pedagogy-in-english-as-
an-international-language-1st-edition-zia-tajeddin/

Easton s Crime A Second Chance 1st Edition Audrey North

https://ebookmeta.com/product/easton-s-crime-a-second-chance-1st-
edition-audrey-north/
Ergodesign Methodology for Product Design: A Human-
Centered Approach 1st Edition Marcelo M. Soares

https://ebookmeta.com/product/ergodesign-methodology-for-product-
design-a-human-centered-approach-1st-edition-marcelo-m-soares/
Beginning Cloud Native
Development with
MicroProfile, Jakarta EE,
and Kubernetes
Java DevOps for Building and Deploying
Microservices-based Applications

Tarun Telang
Beginning Cloud Native
Development with
MicroProfile, Jakarta EE,
and Kubernetes
Java DevOps for Building and
Deploying Microservices-based
Applications

Tarun Telang
Beginning Cloud Native Development with MicroProfile, Jakarta EE, and
Kubernetes: Java DevOps for Building and Deploying Microservices-based
Applications
Tarun Telang
Hyderabad, India

ISBN-13 (pbk): 978-1-4842-8831-3 ISBN-13 (electronic): 978-1-4842-8832-0


https://doi.org/10.1007/978-1-4842-8832-0
Copyright © 2023 by Tarun Telang
This work is subject to copyright. All rights are reserved 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.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not
identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Steve Anglin
Development Editor: Laura Berendson
Coordinating Editor: Gryffin Winkler
Copy Editor: Kezia Endsley
Cover designed by eStudioCalamar
Cover image by Pixabay (www.pixabay.com)
Distributed to the book trade worldwide by Apress Media, LLC, 1 New York Plaza, New York, NY 10004,
U.S.A. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit
www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer
Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail booktranslations@springernature.com; for reprint,
paperback, or audio rights, please e-mail bookpermissions@springernature.com.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub (https://github.com/Apress). For more detailed information, please visit http://www.
apress.com/source-code.
Printed on acid-free paper
This book is dedicated to my grandparents, parents, wife Nikita, and
son Vihan. They have always been a source of inspiration and
encouragement to me. It’s also for all of the software and technology
creators who work hard to make our planet a better place to live.
—Tarun Telang
Table of Contents
About the Author��������������������������������������������������������������������������������������������������� xiii

About the Technical Reviewers�������������������������������������������������������������������������������xv


Acknowledgments�������������������������������������������������������������������������������������������������xvii

Introduction������������������������������������������������������������������������������������������������������������xix

Chapter 1: Introduction to Cloud Computing������������������������������������������������������������ 1


Introduction to Cloud Computing�������������������������������������������������������������������������������������������������� 1
Examples of Cloud Computing������������������������������������������������������������������������������������������������� 2
Benefits of Cloud Computing��������������������������������������������������������������������������������������������������� 4
Essential Characteristics of Cloud Computing������������������������������������������������������������������������� 5
Types of Cloud Computing Based on Deployment Models������������������������������������������������������������ 7
Public Cloud����������������������������������������������������������������������������������������������������������������������������� 8
Community Cloud�������������������������������������������������������������������������������������������������������������������� 9
Private Cloud������������������������������������������������������������������������������������������������������������������������� 11
Hybrid Cloud�������������������������������������������������������������������������������������������������������������������������� 12
Service Models of Cloud Computing������������������������������������������������������������������������������������������� 13
Software as a Service (SaaS)������������������������������������������������������������������������������������������������ 14
Platform as a Service (PaaS)������������������������������������������������������������������������������������������������� 16
Infrastructure as a Service (IaaS)������������������������������������������������������������������������������������������ 18
The Role of Java in Cloud Computing����������������������������������������������������������������������������������������� 19
The Evolution of Cloud Computing���������������������������������������������������������������������������������������������� 21
Summary������������������������������������������������������������������������������������������������������������������������������������ 26

Chapter 2: Cloud-Native Application Development������������������������������������������������� 29


What Is Cloud-Native?���������������������������������������������������������������������������������������������������������������� 29
Characteristics of Cloud-Native Applications������������������������������������������������������������������������ 30
Examples of Cloud-Native Applications��������������������������������������������������������������������������������� 32
v
Table of Contents

Benefits of Cloud-Native Applications����������������������������������������������������������������������������������������� 33


Drawbacks of Using Cloud-Native Applications�������������������������������������������������������������������� 34
Cloud-Native Applications vs. Traditional Applications��������������������������������������������������������������� 35
Cloud-Native Application Development��������������������������������������������������������������������������������������� 37
Managed Services for Java-Based Applications������������������������������������������������������������������������� 38
Examples of Cloud-Native Application Development������������������������������������������������������������� 38
Cloud-Native Application Development Is the Future������������������������������������������������������������ 39
Phases of Cloud-Native Application Development����������������������������������������������������������������� 40
Summary������������������������������������������������������������������������������������������������������������������������������������ 52

Chapter 3: Setting Up Your Development Environment������������������������������������������ 55


Prerequisites������������������������������������������������������������������������������������������������������������������������������� 55
Hardware Requirements�������������������������������������������������������������������������������������������������������� 55
Installing Java Development Kit (JDK)����������������������������������������������������������������������������������� 57
Using Maven������������������������������������������������������������������������������������������������������������������������������� 58
Installing Maven�������������������������������������������������������������������������������������������������������������������� 59
Git������������������������������������������������������������������������������������������������������������������������������������������������ 60
Installing Git��������������������������������������������������������������������������������������������������������������������������� 60
Creating a GitHub Account����������������������������������������������������������������������������������������������������� 61
Creating a GitHub Repository������������������������������������������������������������������������������������������������ 62
Pushing Code to a GitHub Repository������������������������������������������������������������������������������������ 63
Using Docker������������������������������������������������������������������������������������������������������������������������������� 65
Benefits of Using Docker������������������������������������������������������������������������������������������������������� 65
Installing Docker�������������������������������������������������������������������������������������������������������������������� 66
Docker Hub���������������������������������������������������������������������������������������������������������������������������� 67
Using Kubernetes������������������������������������������������������������������������������������������������������������������������ 68
Installing Kubernetes������������������������������������������������������������������������������������������������������������� 69
Configuring Docker for Kubernetes��������������������������������������������������������������������������������������� 71
Creating a Kubernetes Cluster����������������������������������������������������������������������������������������������� 73
Using Zipkin�������������������������������������������������������������������������������������������������������������������������������� 74
Installing Zipkin��������������������������������������������������������������������������������������������������������������������� 74

vi
Table of Contents

Integrated Development Environments (IDE)������������������������������������������������������������������������������ 75


Summary������������������������������������������������������������������������������������������������������������������������������������ 76

Chapter 4: Building RESTful Web Services������������������������������������������������������������� 77


REST: An Architectural Style for Building Web Services�������������������������������������������������������������� 78
Introduction to Open Liberty Runtime����������������������������������������������������������������������������������������� 78
Key Features of the Open Liberty Application Server������������������������������������������������������������ 79
Downloading and Installing Open Liberty������������������������������������������������������������������������������ 80
Starting the Open Liberty Server������������������������������������������������������������������������������������������� 80
Printing a List of Features on the Open Liberty Server���������������������������������������������������������� 82
Creating a Server Instance���������������������������������������������������������������������������������������������������� 85
Stopping the Open Liberty Server����������������������������������������������������������������������������������������� 86
Configuring the Server���������������������������������������������������������������������������������������������������������� 87
Creating a RESTful Web Service in Open Liberty������������������������������������������������������������������� 87
Creating a RESTful API����������������������������������������������������������������������������������������������������������� 98
Summary���������������������������������������������������������������������������������������������������������������������������������� 109

Chapter 5: Microservices Architecture����������������������������������������������������������������� 111


Vertical Scaling������������������������������������������������������������������������������������������������������������������������� 111
Horizontal Scaling��������������������������������������������������������������������������������������������������������������������� 112
Vertical vs. Horizontal Scaling��������������������������������������������������������������������������������������������� 113
History of Service-Based Architecture�������������������������������������������������������������������������������������� 113
Types of Service-Based Architectures�������������������������������������������������������������������������������������� 115
Service-Oriented Architecture (SOA)����������������������������������������������������������������������������������� 115
What Is a Web Service?������������������������������������������������������������������������������������������������������� 116
What Is SOAP?�������������������������������������������������������������������������������������������������������������������������� 117
What Is REST?��������������������������������������������������������������������������������������������������������������������� 118
REST vs. SOAP��������������������������������������������������������������������������������������������������������������������� 118
The Monolithic Architecture������������������������������������������������������������������������������������������������������ 119
Evolution of the Microservices Architecture������������������������������������������������������������������������ 120
Benefits of Microservices Architectures������������������������������������������������������������������������������ 121

vii
Table of Contents

Drawbacks of Microservices Architectures������������������������������������������������������������������������������ 122


Design Considerations��������������������������������������������������������������������������������������������������������� 122
Using Microservices in Cloud-Native Applications�������������������������������������������������������������� 123
Cloud-Native Twelve-Factor Applications���������������������������������������������������������������������������� 124
What Is a Virtual Machine?������������������������������������������������������������������������������������������������������� 126
What Are Containers?��������������������������������������������������������������������������������������������������������������� 127
What Are Container-Based Applications?���������������������������������������������������������������������������� 128
What Are Serverless Applications?�������������������������������������������������������������������������������������� 130
Where Is Serverless Computing Used?������������������������������������������������������������������������������� 130
Benefits of Serverless Computing��������������������������������������������������������������������������������������� 131
Drawbacks of Serverless Computing���������������������������������������������������������������������������������� 131
Popular Serverless Platforms���������������������������������������������������������������������������������������������� 132
Main Components of a Serverless Computing Platform����������������������������������������������������������� 132
Serverless Applications vs. Containers������������������������������������������������������������������������������� 134
Microservice Deployment Patterns������������������������������������������������������������������������������������������� 138
Key Considerations�������������������������������������������������������������������������������������������������������������� 138
Microservices Deployment Strategies and Patterns����������������������������������������������������������� 139
Microservices Management������������������������������������������������������������������������������������������������ 142
Summary���������������������������������������������������������������������������������������������������������������������������������� 142

Chapter 6: The Eclipse MicroProfile Framework�������������������������������������������������� 143


What Is the Eclipse MicroProfile Framework?�������������������������������������������������������������������������� 143
Layers of Functionality in MicroProfile�������������������������������������������������������������������������������� 144
Popular Implementations of the Eclipse MicroProfile Framework�������������������������������������� 147
MicroProfile Config�������������������������������������������������������������������������������������������������������������� 148
The MicroProfile Health Check Specification���������������������������������������������������������������������������� 156
The MicroProfile Fault Tolerance Component��������������������������������������������������������������������������� 159
Key Features of the Fault Tolerance Component����������������������������������������������������������������� 159
Fault Tolerance API�������������������������������������������������������������������������������������������������������������� 160
Summary���������������������������������������������������������������������������������������������������������������������������������� 162

viii
Table of Contents

Chapter 7: MicroProfile Framework – Part 2�������������������������������������������������������� 163


The MicroProfile Metrics Specification������������������������������������������������������������������������������������� 163
Types of Metrics������������������������������������������������������������������������������������������������������������������ 164
Metrics Components����������������������������������������������������������������������������������������������������������� 164
Metrics Annotations������������������������������������������������������������������������������������������������������������� 164
Maven Dependency������������������������������������������������������������������������������������������������������������� 165
Tracking Response Time Using @Timed������������������������������������������������������������������������������ 165
Tracking the Number of Invocations������������������������������������������������������������������������������������ 166
Tracking Memory Usage������������������������������������������������������������������������������������������������������ 167
MetricRegistry��������������������������������������������������������������������������������������������������������������������� 167
Creating Custom Metrics����������������������������������������������������������������������������������������������������� 168
Using Open Tracing������������������������������������������������������������������������������������������������������������������� 171
Distributed Tracing�������������������������������������������������������������������������������������������������������������� 171
How Does It Work?�������������������������������������������������������������������������������������������������������������� 171
Using the Jakarta RESTful Web Service������������������������������������������������������������������������������������ 174
Using the MicroProfile OpenAPI Specification�������������������������������������������������������������������������� 177
OpenAPI������������������������������������������������������������������������������������������������������������������������������� 177
Capabilities of the MicroProfile OpenAPI Specification������������������������������������������������������� 177
Generating OpenAPI Documents������������������������������������������������������������������������������������������ 177
Using the MicroProfile OpenAPI in Your Project������������������������������������������������������������������� 178
MicroProfile OpenAPI Annotations��������������������������������������������������������������������������������������� 181
Summary���������������������������������������������������������������������������������������������������������������������������������� 181

Chapter 8: MicroProfile JSON Web Tokens and Jakarta Security������������������������� 183


Security Best Practices for Microservices�������������������������������������������������������������������������������� 183
What Is a JSON Web Token (JWT)?������������������������������������������������������������������������������������������� 184
Use Cases for JSON Web Tokens����������������������������������������������������������������������������������������� 184
Authentication��������������������������������������������������������������������������������������������������������������������� 184
Authorization����������������������������������������������������������������������������������������������������������������������� 184
Session Information������������������������������������������������������������������������������������������������������������� 185
Claims-Based Identity��������������������������������������������������������������������������������������������������������� 185

ix
Table of Contents

Information Exchange���������������������������������������������������������������������������������������������������������� 185


Federation��������������������������������������������������������������������������������������������������������������������������� 185
Creating and Signing a JWT������������������������������������������������������������������������������������������������������ 186
Testing the Application�������������������������������������������������������������������������������������������������������� 189
Verifying and Validating a JWT�������������������������������������������������������������������������������������������������� 190
Using JWT in a Microservice Environment�������������������������������������������������������������������������������� 191
Securing a RESTful Application������������������������������������������������������������������������������������������� 192
Securing a REST Resource�������������������������������������������������������������������������������������������������� 193
The @RolesAllowed Annotation������������������������������������������������������������������������������������������� 195
The @Claim Annotation������������������������������������������������������������������������������������������������������� 196
The @HeaderParam Annotation������������������������������������������������������������������������������������������ 196
Configuring a JWK Set or PEM-Encoded Public Key����������������������������������������������������������������� 197
Public Key Cryptography Standards #8 in PEM Format������������������������������������������������������� 197
JSON Web Key (JWK)����������������������������������������������������������������������������������������������������������� 198
JSON Web Key Set (JWKS)�������������������������������������������������������������������������������������������������� 198
The Jakarta EE Security Specification�������������������������������������������������������������������������������������� 199
Securing a Servlet Using Jakarta Security�������������������������������������������������������������������������� 199
The MicroProfile REST Client���������������������������������������������������������������������������������������������������� 203
The @RegisterClient Annotation������������������������������������������������������������������������������������������ 204
Configuring Your REST Client����������������������������������������������������������������������������������������������� 204
REST Client Interface����������������������������������������������������������������������������������������������������������� 205
Documenting RESTful APIs Using MicroProfile OpenAPI����������������������������������������������������� 209
What Is the OpenAPI Specification?������������������������������������������������������������������������������������ 209
What Is MicroProfile OpenAPI?�������������������������������������������������������������������������������������������� 209
Summary���������������������������������������������������������������������������������������������������������������������������������� 212

Chapter 9: Containerizing Microservices Using Kubernetes�������������������������������� 213


What Are Containers?��������������������������������������������������������������������������������������������������������������� 213
Why Use Containers?���������������������������������������������������������������������������������������������������������������� 213
What Is Container Orchestration?��������������������������������������������������������������������������������������������� 214
The Benefits of Using Container Orchestration�������������������������������������������������������������������� 214
Understanding Kubernetes Terminology����������������������������������������������������������������������������������� 215

x
Table of Contents

The Key Features of Kubernetes����������������������������������������������������������������������������������������������� 217


Using Kubernetes���������������������������������������������������������������������������������������������������������������������� 218
Using Docker Containers����������������������������������������������������������������������������������������������������������� 219
Running a MicroProfile Application in Docker��������������������������������������������������������������������� 220
Pushing the Docker Image to Docker Hub��������������������������������������������������������������������������� 223
Scaling Your Deployment����������������������������������������������������������������������������������������������������� 227
Summary���������������������������������������������������������������������������������������������������������������������������������� 228

Appendix A: Introduction to Maven���������������������������������������������������������������������� 231

Appendix B: Creating an Open Liberty Project Using Maven�������������������������������� 241

Appendix C: Installing Open Liberty Tools������������������������������������������������������������ 247

Index��������������������������������������������������������������������������������������������������������������������� 253

xi
About the Author
Tarun Telang is a hands-on technologist with extensive
experience in the design and implementation of multitiered,
highly scalable software applications. He has been part of
several well-known companies, including Microsoft, Oracle,
Polycom, and SAP. He has over 17 years of experience in
architecting and developing business applications.
He began his career as an enterprise Java developer at
SAP, where he developed distributed application software for
big firms. He got his start with enterprise session beans and
message-driven beans, as well as instrumenting enterprise
applications’ configuration and management using the Java Management Extensions
(JMX) technology.
He quickly mastered various enterprise technologies, including the Enterprise
Beans, Java Management Extensions, Servlets, and Server Pages technologies, and
in his first year as a developer, he became a Sun Certified Programmer for the Java
Platform, Standard Edition 6, and an SAP Certified Development Consultant for the SAP
NetWeaver Java Web Application Server (which was a Java EE 5-compliant application
server).
He also gained expertise in XML technologies like XSLT and XSD. He developed
several solutions using session beans and message-driven beans to handle message-­
oriented communications across numerous systems. In 2007, Tarun was named an
SAP Mentor and Community Influencer for his articles and blog posts on emerging
technologies and for promoting innovative solutions in the SAP Developer Community.
He frequently writes articles on Java and related technologies. Tarun has also authored
multiple online courses, including a best-selling course on the YAML data serialization
language.
He has presented technical lectures at several developer conferences, including
SAP TechEd and the Great Indian Developer Summit. He has been presenting at
conferences for more than 15 years and actively publishes technical papers and blogs to
assist everyone in grasping the fundamentals of software technology. Tarun developed

xiii
About the Author

cloud-based video conferencing applications using a microservices architecture with


the Spring framework and has experience working with Persistence APIs and the
Hazelcast framework for building REST-based services.
He also developed many end-to-end cloud-based solutions using various
architectural patterns, including microservices and service-oriented architectures. Tarun
has gained expertise in web, mobile, and cloud technologies. He is also knowledgeable
in applied agile methodologies, including user-centric and mobile-first design for
managing projects with cross-functional teams located in multiple geographies. Tarun
is the co-author of Java EE to Jakarta EE 10 Recipes: A Problem-Solution Approach for
Enterprise Java (Apress, 2022).
Having previously worked in Canada and Germany, Tarun currently resides in
Hyderabad, India with his wife and son. You can follow him on LinkedIn (www.linkedin.
com/in/taruntelang/), Facebook (www.facebook.com/tarun.telang), and Twitter
(@taruntelang). His blog at https://blogs.taruntelang.me is an excellent resource for
all things related to software technology!

xiv
About the Technical Reviewers
Massimo Nardone has more than 25 years of experience
in security, web/mobile development, cloud, and IT
architecture. His true IT passions are security and Android.
He has been programming and teaching others how to
program with Android, Perl, PHP, Java, VB, Python, C/C++,
and MySQL for more than 20 years. He holds a Master of
Science degree in computing science from the University of
Salerno, Italy.
He has worked as a CISO, CSO, security executive, IoT
executive, project manager, software engineer, research
engineer, chief security architect, PCI/SCADA auditor,
and senior lead IT security/cloud/SCADA architect for many years. His technical skills
include security, Android, cloud, Java, MySQL, Drupal, Cobol, Perl, web and mobile
development, MongoDB, D3, Joomla, Couchbase, C/C++, WebGL, Python, Pro Rails,
Django CMS, Jekyll, Scratch, and more.
He was a visiting lecturer and supervisor for exercises at the Networking Laboratory of
the Helsinki University of Technology (Aalto University). He also holds four international
patents (in the PKI, SIP, SAML, and Proxy areas). He is currently working for Cognizant
as head of cybersecurity and CISO to help clients in areas of information and
cybersecurity, including strategy, planning, processes, policies, procedures, governance,
awareness, and so forth. In June, 2017, he became a permanent member of the ISACA
Finland Board.
Massimo has reviewed more than 45 IT books for different publishing companies and
is the co-author of Pro Spring Security: Securing Spring Framework 5 and Boot 2-based
Java Applications (Apress, 2019), Beginning EJB in Java EE 8 (Apress, 2018), Pro JPA 2 in
Java EE 8 (Apress, 2018), and Pro Android Games (Apress, 2015)

xv
About the Technical Reviewers

Pramit Das has more than 12 years of experience in software


design and development across multiple platforms using
various technology stacks. He is extremely passionate
about programming and exploring new and upcoming
technologies. He has extensive hands-on experience with
programming languages like C/C++, Java, Scala, JavaScript,
and Python, along with their respective tools, libraries,
and frameworks, including Spring, Django, NodeJs, and
Spark. He also has excellent knowledge of backend storage
solutions from Oracle, MySQL, MongoDB, and Cassandra, as
well as other cloud-based managed services.
Academically, Pramit received his Bachelor’s of Technology from NIT, Rourkela in
Computer Science & Engineering, graduating in 2009. He has experience in product- and
service-based industries and is currently working for the cloud giant Salesforce as a
full-time engineer.

xvi
Another Random Scribd Document
with Unrelated Content
Before going on to investigate this playful rivalry it may be useful to
inquire into its social significance. G. Tarde, in his interesting
sociological study, Les lois de l’imitation,404 attempts to prove that
imitation is the mainspring of social evolution. But along with the
peaceful operations of imitation, the fighting instinct, too, makes
itself felt in manifold ways, as a principle of progress (as I remarked
above in discussing combativeness), in conjunction it is true with
imitation and usually under the form of rivalry. It is evident that
social progress would be slow indeed if men only imitated and never
opposed what is done in their presence. Rivalry in ownership, power,
and authority is the force which urges each to do his utmost in the
struggle for life, and which has produced the most advanced
civilizations. A people without ambition is lost; not merely stationary,
but actually decadent. As in art bald imitation of even the best
models results in weakness, so in society. Men must will to do better
in order to do as well.
In spite of their variety we can very quickly review the physical
imitative games, since under movement-plays we have already
noticed a considerable number belonging to this class, and since it is
their psychological side alone that chiefly appeals to us. The
following examples, then, are merely chosen to show by means of
their variety the great importance of imitation in human play.405
Children learn most of their bodily movements by such play in a way
which clearly illustrates the mingled effects of imitation and
emulation. When one child jumps off the second step, another child
who sees him immediately tries to cover three; and when boys are
practising their leaps each makes a mark in the sand beyond the
others as his goal. To lift a heavier weight, to throw farther, to run
faster, to jump higher, to make a top spin longer, to stay longer
under water, to shoot higher, farther, and with better aim than his
comrades can, is the burning wish of every childish heart. In order
to see the same enthusiastic rivalry in physical prowess exhibited by
adults, we must turn to the half-civilized peoples to whom such
acquirements are of surpassing value in the struggle for life. Among
the ancient Germans, for example, such contests were carried to the
highest degree of perfection, and, in spite of their avowedly playful
character, conducted with such seriousness that they often became
matters of life and death. Skill, prowess, and endurance in leaping,
running, lifting and throwing huge stones, the use of bow and arrow,
diving and swimming, riding and rowing, were all the subjects of
contest, and each victor sought to surpass the achievements of the
former one. All warlike peoples of whom ethnology is cognizant
show much the same picture, and highly civilized nations, too,
accord an important position to athletic contests, as the Greek and
Roman games bear witness, as well as the championships and
records of our own day. Rivalry enters, too, into such games as
tenpins, billiards, croquet, golf, etc., all of which are favourite
amusements. The pleasure they afford is complicated, including
display of one’s own strength and skill, the pleasure of watching
others, the stimulus of rivalry and the satisfaction of overcoming an
opponent. Sometimes, and especially in croquet and billiards, the
contest closely approaches fighting play, since the participants not
only try to attain the object of the game, but are apt to engage in
direct hostilities.
We now turn to some examples that are better calculated to exhibit
the many-sidedness of rivalry, which is, of course, an element in all
the games of skill which we have mentioned. We are not so well
prepared to find it in games requiring patient effort, yet even the
Eskimos, in their Fadenfiguren, indulge in fierce emulation,406 and a
play as peaceful as kite-flying is not exempt. “The Hervey Islanders
believe that once the god Tane challenged the god Rongo to a kite-
flying contest, in which the latter won because his cord was
longer.”407 In drinking there is rivalry in the effort to withstand the
power of alcohol, and students have a time-honoured tradition that
the man is a fine fellow and worthy of all respect who can drink the
rest of the company under the table. It is more charitable to
attribute this practice to rivalry rather than to love of
drunkenness.408 The instance of the two boys holding burning
matches illustrates how readily the ability to suppress any
manifestation of pain lends itself to rivalry. The old Germans tested
their endurance by sitting at feasts after their battles, and when they
were covered with wounds. In a grotesquely exaggerated saga it is
related of the wounded sons of Thorbrand: “Thorodd got such a
blow in the neck that his head hung sideways; his hose were all
bloody and would not meet. Snorri could see and feel that a sword
was sticking in his thigh, but Thorodd said nothing. Among the
gayest of the gay is Snorri, son of Thorbrand, who sits with the
others at table, but eats little and looks white. When asked what ails
him he says, ‘When the vulture has won the fight he is not in haste
to eat.’ Then Gode looks at his neck and finds an arrow head at the
root of his tongue.”409 The jeering of Walthar and Hagen, who vie
with one another in mocking at their wounds, is another case in
point. Finally, the passion for making collections, which is so strong
in both children and adults, may be considered as a form of
competitive rivalry which reaches its climax in the miser.

4. Mental Rivalry
The space devoted to the more general kinds of emulation has
purposely been curtailed in order to devote more to the special case
of gaming, as much of the ground has been covered already.
Children are fond of displaying their mental acquirements even
before they are old enough to go to school, but it is there, of course,
that the best opportunity is afforded them. Colozza tells us how the
Italian children use their recess time for contests over the
multiplication table.410 During school hours recitation is easily
transformed to emulation which can be turned to account by the
judicious teacher with better results than are attained by one who
tries to draw the line too rigidly between work and play.
The intellectual rivalries of adults are exceedingly varied. Music
offers unlimited opportunities when people are far enough advanced
to have any sort of society, and even primitive tribes indulge in this
sort of entertainment. Among the Eskimos the contestants compete
in public for the prize for singing, and then fall into actual combat,
thus combining the two forms of rivalry. Grosse quotes from Rink the
following musical dialogue between two East Greenlanders. “Savdlat:
‘The south, the south, oh, the south over there! As I stood on the
headland I saw Pulangitsissok, who had grown fat upon halibut. The
people of this land know not how to speak. Therefore they are
ashamed of their language. They are dumb over there; their speech
is not like ours. In the north we speak in one way, different from
those in the south. Therefore we can not understand their talk.’” To
this challenge Pulangitsissok responds: “‘There was a time, as
Savdlat knows, when I was a good sledger, when I could take a
heavy load on my kajak. Four years ago he found this out. That was
the time when Savdlat bound his kajak to mine for fear he might
capsize. Then he could carry a good load on his kajak, too. As I was
tugging along you cried out pitifully, and were afraid and almost
overturned. I had to hold on to my ropes to keep us up.’”411 Such
sarcastic dialogue often leads to direct contests, in which the singers
try to rout one another by means of their witty improvisations. A
later form is the contest in oratory and song on an assigned theme,
opening with a direct challenge between the contestants. The poem
of Wartburg-Krieg is especially famed, while Plata’s symposium may
be instanced as a fine example of competitive oratory on a given
theme.
Other kinds of rivalry frequently arise in social gatherings, such as
recounting experiences in love, hunting, and battle, as was pre-
eminently the custom among the ancient Germans. “One after
another,” says Weinhold,412 “boasted of his prowess and sought to
prove it by tales of his wonderful deeds. To heighten the effect, each
chose an opponent worthy of his mettle. Thus it happened that
Eystein and Sigurd, the crusader, both Norwegian kings, once had a
controversy in court. Eystein advanced the proposition that it was
impossible to live aright in society, and called on his brother to
sustain the contrary. Then the travelled warrior Sigurd, who had
filled all lands with the fame of his deeds, and the peace-loving,
home-staying Eystein, each related what he had done and could do:
the one his battles, his fame in the East; the other that he had built
huts for poor fishers, made roads over rugged mountains, opened
harbours, widened Christendom, and strengthened the Church—in
short, extended his kingdom by every peaceable method. The talk
became warm, and the silence which followed was ominous, but as
they were both noble-hearted no harm came of it.” Very
characteristic, too, is the Harbardhslied in the Edda, where the gods
Wotan (under the name Harbardh) and Donar emulously recount
their achievements:
Donar: “Do you ask what I did to Rungner,
The giant with sturdy heart and head of stone?
I felled him then, he lies at my feet.
And what did you, Harbardh, the while?”

Harbardh: “For more than five full winters


Was I on an island that is called Allgrün;
There I found men to fight and enemies to fell,
Many things to prove, and many maids to free,” etc.
Singing the praise of one’s future deeds is another form of such
boasting. A company of carousing men have need of a wild boar or
some other sin offering to go through their midst as they perjure
themselves with oaths concerning the hazardous and difficult deeds
which they mean to perform.
Before taking up games of chance again I mention once more the
fact that many reasoning games are also rivalries—dominoes, for
example, and backgammon413—since the chief effort is to reach a
certain goal first and direct efforts are made to embarrass and retard
the adversary, so that genuine fighting play results.
In chance games proper, however, the contestants do not attack one
another directly, but seek to conquer by the better solution of some
problem, the point of departure from other rivalries being that the
reward of solution, at least in games of pure chance, is entirely
accidental, and not dependent on the player’s strength or skill. We
will now attempt to review the more important phenomena
connected with such games, and later study the question in its
psychological bearings.
The wager is akin to play with chance and arises from the holding of
opposite opinions, which can only be settled by future events. Even
if the bet concerns something which is past or present, still the
decision must be in the future, and the fighting element comes in in
the striving of each to prove his superiority, the interest being much
enhanced by pooling the stakes. The bettor’s conviction as to the
correctness of his opinion may be strong or weak414—absolute
certainty destroys the validity of the bet, while absolute uncertainty
makes it a mere game of chance, whereas it should depend, like the
best card games, on a union of reasoning and hazard. For this
reason future events are the proper subjects of the wager, and we
will confine ourselves for brevity’s sake to such bets. Schaller says
rightly: “The future is pre-eminently the object of conjecture, of the
reckoning of probabilities. Even when present circumstances seem to
tend inevitably to a certain result, there are still infinite possibilities
that other results may transpire. Therefore the wager should
concern something yet to come.”415
One of the earliest forms of betting was on physical or mental
superiority, and the stakes formerly so common in reasoning games
may be regarded in the same light. There was much betting on the
victor in the old German riddle contests and life itself was sometimes
staked, if we may depend on the ancient accounts. More often,
though, physical prowess was the subject of the wager. “Indeed,
Tacitus may be right,” says Schuster, “when he records that the
Germans disdained to be praised for ordinary physical vigour, yet
they gave prizes to the victors in their contests and liked to claim the
glory when it set them above others. Reputation with them must not
be mere empty words; one must work for it to the full extent of his
powers. Many examples illustrate this spirit; for instance, Welent and
Amilias, the smiths, each boasted that he could not be surpassed in
his art. The latter offered to bet on it, and Welent replied, ‘I have
not much property, but I will stake it all.’ Then said Amilias, ‘If you
have nothing else, stake your head, and I will stake mine, and
whichever of us is the better man shall cut the other’s head off.’ Two
of Olaf Trygvason’s retainers boasted of being superior mountain
climbers, one wagering his ring on it, and the other his head.”416
Schuster cites, too, the famous contest in the Nibelungenlied, to
which Brunhild thus challenges King Gunther:
“She said: If he is your lord and you are in his hire,
Tell him that I have sworn that whoever can resist my play,
And prove himself my master there, him will I wed,
While if I win you must go alone from hence.”

Fable makes animals wager in the same way; the old tale of the hare
and the hedgehog is found even in Africa, although there the
hedgehog has become a tortoise.417
The stakes are not always, however, on one’s own ability, but quite
as often on the performances of others, or on the speed and
endurance of animals. This is indeed the most popular form of the
sport, doubtless because the agreeable tension of expectation is
thus prolonged until the very moment of the dénouement, as it is
not likely to be in the more personal contests. In riding, rowing,
sailing, and running contests spectators, as well as participants, bet
on the result.418 “Betting on races,” says E. v. Hartmann, “is the
most dangerous and exciting form of gambling, being dependent
purely on chance, and yet offering a false appearance of being
essentially influenced by intelligence and judgment. The custom is
fostered of raising the stakes at the last moment under the influence
of artificial stimulation to interest during the race itself. Immature
boys, sons of respectable labourers, are thus initiated in the
fascinations of the passion for gaming who would otherwise have
little inclination for it.”419 In various parts of the world wagers are
laid on the result of fights between animals. In ancient Greece
gamecocks were bred with special care, and Tanagra, Rhodes,
Chalcis, and Delos were famous for the achievements of their
respective breeds. The birds were fed with garlic before the fight to
augment their excitement, and were armed with artificial spurs. The
stakes were often enormous.420 Cock-fights in which betting seemed
to be the principal feature were held during the middle ages in most
European cities, and in some localities have survived to the present
day. Malays are especially devoted to this sport. It only remains to
add in conclusion that lifeless things, too, may be the subject of
bets. The Gilbert Islanders set two sailboats, about four feet long,
afloat, and bet as to which will sail fastest.421 This is very near to
being play with pure chance, and the wager of Canning with an
English duke is even more so. They staked a hundred pounds on the
question of who should meet most cats on a certain road.
There is but one opinion as to the origin of games of pure chance—
namely, that they grew out of the serious questioning of Fate in the
form of oracles, and colour is given to the theory by the custom of
jesting with the oracle. The Greek custom of pouring wine into a
metal cup and from the sound it made reading one’s prospects in
love, drawing straws—a practice which Walther von der Vogelweide
has made famous—the various flower oracles, counting the cuckoo
calls, observing the flight of birds—as, for example, how many times
the kite circles—and many other such customs422 were originally
conducted seriously, with a view to gaining some knowledge of the
future, and even when playfully practised smack of superstition.
Tylor says, in his admirable study of this subject: “Soothsaying and
games of chance are so closely allied that the instruments of each
are used interchangeably, as among the clever Polynesian magicians
cocoanuts are skilfully rolled about in a circle. In the Tonga Islands
the chief use made of a holiday is to inquire whether the sick will be
cured. They offered loud prayers to the family deity that he would
place the nuts aright, then spun them, and from their position
judged of the god’s will. Under other circumstances, when the
cocoanuts are rolled simply for amusement, no prayer is offered and
no significance attached to the result. The Rev. G. Turner found the
same custom in the Samoan Islands in another stage of
development. There a company sits in a circle, the nuts are rolled
about among them, and the oracle’s answer depends on whether the
monkey face of the nut is turned toward the questioner when it
stops rolling. The Samoans formerly used this method to detect a
thief, but now it is a forfeit game.”423 In this sort of play with chance
there is nothing special at stake, yet it is no doubt closely connected
with those forms which have this feature.
Another of the earliest of the manifold forms of chance games is the
casting of lots. New Zealand wizards decide the fortunes of war by
throwing staffs. If the stick which represents their own tribe falls on
that of another, then a favourable outcome may be confidently
expected to the battle. The Zulus have a similar ceremony, and the
Hindus cast lots before the temple and supplicate the gods for
victory. In the Iliad the crowd prayed with outstretched hands while
the dice in Agamemnon’s helmet decided who should be the first to
fight Hector. Tacitus tells us that the German priests tossed three
dice on a white cloth before they attempted to reveal the future.424
The origin, then, of the use of dice in games of chance is
indubitable. The ancient form of backgammon common in India and
Mexico was played with lots instead of dice, as was also the case
with the Arabian Tâb. Some Indian tribes use the simple casting of
lots for gambling purposes. The Arabian does not throw, but draws
lots as a substitute for the Meisir forbidden in the Koran.425 The
complicated Chinese game lotto is well known, and Bastian found a
similar one used in Siam.426 E. von Hartmann refers repeatedly in
his Tagesfragen to our European lottery, combating the popular idea
that it is reprehensible, and should not be fostered by the state. He
sees in a well-conducted state lottery the best means of directing
the ineradicable tendency to play games of chance into harmless
channels. Money speculation is, as a rule, little different from a
lottery, since the great majority of speculators have no more
intimation of the outcome than is furnished by the law of
probabilities which governs pure games of chance. Returning now to
simpler manifestations, we find many which are closely related to
the use of lots. North American Indians, who are zealous gamblers,
use marked or coloured stones, seeds, and teeth, and stake their
clothing, furniture, weapons, and, in fact, all that they possess. In
Burmah a favourite game is played with beans, and in many of the
villages a thrashing floor is erected for the express purpose of
supplying the demand.427 In Siam the children play with shells, and
everything depends on whether the opening falls up or down.428 A
similar game was known to the Greeks, and in Rome a coin was
tossed with the cry, “Caput aut navis!” equal to our “Heads or tails!”
We must suppose that such play by children is derived from adult
games of chance.
Astragalus and dice were the implements used in many such games.
The former are peculiarly shaped bones from the ankles of sheep,
goats, or calves, and their use for such purposes is very ancient.
They are capable of resting on any one of four sides which may vary
in value, as the six sides of dice. The Schliemann collection in the
Berlin Museum contains some of them which were found in the
“second city.” In ancient Greece four astragali were used in the
games of adults, and were thrown either from the free hand or from
a cup. Special names were given to the various throws, such as
Aphrodite, Midas, Solon, Euripides, etc., and the worst throw was
called, there as in Rome, the dog. The children of antiquity also
played with these bones a game partly of chance and partly of skill,
and Hellenic children use them to this day. Ulrichs saw them at
Arachola on Parnassus. “The children there,” he says, “play with the
astragalus, which is a small four-sided bone rounded at the end and
so shaped as to be capable of resting on any of its sides. In the
game the uppermost side is read, the commonest throw being that
which brings the round end up and is called the baker or the donkey.
Then follow the thief, the vizier, and, rarest of all, the king, the side
which looks like an ear and is opposite the vizier.”429
The name vizier seems to point to Mohammedan influence, and
indeed the children of Damascus have a special game of chance with
astragalus in which the terms vizier and thief are both used.430
Some think that ordinary dice are derived from the astragalus, but it
would be difficult to prove, though their imitation in other materials
seems to suggest it, as in the case of the oblong dice used by the
Romans with cubical ones, and several hundred prehistoric dice
found in Bohemia are of similar form. The Berlin Museum, too, has
oblong dice from India and China, showing that they were widely
used in the Orient, and Hyde points out in his history of games of
chance that the Greek word κύβος is related to the Arabic Kab,
which meant simply made of lamb’s bones. On the other hand,
cubical dice with spots like ours are found in Theban graves, so that
we can not be positive as to the priority of the astragalus.
Possibly cocoanut rolling was the primitive form of roulette as we
have seen it used in half-religious, half-playful manner by the South
Sea Islanders. The Berlin Museum has Chinese rolling dice through
which a peg passes, projecting on each side or with the peg on one
side only, and the ball tapering to a point on the other. According to
Egede, Greenlanders have a sort of roulette, an oblong ball about
which the players sit with the stake before them.431 Another form of
chance game is the morra, which was probably known to the ancient
Egyptians, and was in all likelihood at first a clever method of
calculating.432 As a play the hands of all the players are thrown
simultaneously into the air, and each must guess at the number of
outstretched fingers without taking time to count. This amusement,
still very popular among Italian peasants, was called by the Achæans
“micare digitis.” In China, where it is zealously cultivated, it bears the
name of “tsoey-moey.”433 The North American Indians have a
modification of it in their cane guessing—namely, the effort to locate
a small object passed quickly about in a company. It is used for
gambling purposes, the Indians staking all that they have, even to
their wives sometimes.434 The “Kyohzvay” play is taken quite as
seriously in Burmah. For this a stick is fixed among the folds of a
tightly wrapped cord, and the game is won or lost435 according as it
is or is not successfully concealed.436 The various games of cards
afford by far the most important instances of play with chance, and
their name is legion. We have not time even to glance at such
games as faro, lansquenet, rouge et noir, trente et quarante, etc.,
except to say that they all depend on a combination of reason with
chance, and so more speedily put an end to suspense as to who is
the victor than do purely chance plays. We are now confronted by
the difficult question of what it is that constitutes the demoniacal
charm of gaming, whose power is demonstrated by the value of the
stakes with which a man will tempt Fate. Every one is familiar with
Tacitus’s description of the ancient Germans who, when they had
lost everything else, staked their freedom and their life on the last
throw. H. M. Schuster gives a long list of examples of Germans
staking freedom, wife, and children, the clothes on their backs, life
itself, yes, even their souls’ salvation when their passion for play was
at its height. That this is a universal Aryan trait is shown by the
Indian poem of Nala and Damayanti. The former, under the power of
a hostile demon, loses at play with Pushkara his ornaments, jewelry,
horses, wagons, and clothes. In vain his wife and followers seek to
restrain his madness; for many months the ruinous play goes on
until Nala has lost all his property and even his kingdom. Then as
Pushkara, with loud laughing at the unlucky fellow, cried out that
now he must put up his wife Damayanti, Nala rose from the table
and walked away with his faithful wife, stripped as he was of all else.
The Chinese, Siamese, and Burmese, too, are all passionate
gamblers, and the Malays are famous for their wagers on animal
fights. This is sufficient to show that the wonderfully strong
attractive power of gaming, “le jeu-passion, dont le rôle tragique est
vieux comme l’humanité,”437 is the result of numerous causes whose
aggregate, according to Fechner’s principle, is far greater than their
numerical sum. Taking account of the essentials only, we still have a
threefold phenomenon; these are, desire to win the stake, the
stimulus of strong effects, and the impulse given by the fighting
instinct.
Winning the stake is so important that without it games of chance
become very flat and most unimpressive, as forms of entertainment.
How is this to be explained? Sometimes it appears as veritable
cupidity, the “fascination d’acquérir d’un bloc, sans peine, en un
instant.”438 The seductive chink of gold pieces is heard and visions
of new names of wealth open before us, promising to deliver us
from all burdens and dangers which in spite of their distance and
vagueness we strive to get possession of by a single turn of
Fortune’s wheel; the gold fever is at home in gambling dens. Yet—
and I think this is important—as a rule, it is not mere greed for gain
as such, but a feeling more refined. It is boundless delight in sudden
good fortune that makes the unearned winnings so enticing. That
inward striving after the absolute, which is so deeply rooted in the
human breast, is concerned in the longing to experience at least one
moment of exhilarating joy with which a single stroke of Fortune’s
wand sets our hearts aflame:
“From the clouds it must fall,
Such is the gift of the gods;
And the strongest power of all
Is that which belongs to the moment.”
It would be misleading to suppose that all wagers in a game of
chance are attributable to a desire to win, even in this refined sense.
In so far as it is the chief motive, there is no real play at all, for it
constitutes a serious aim wholly outside the sphere of play. There
must be some other meaning to the intense delight in winning, and
Lazarus, as usual, puts his finger on it. “Even for an onlooker, not
pecuniarily interested, the charm increases with the value of the
stake.”439 The stake serves not only to enhance the thought of
winning the game, but intensifies the decisive moment.440 A
gambler must have excitement at any price, and he also wants to
risk something; betting satisfies both demands.
The need for intense stimuli which we are so constantly
encountering in the course of this inquiry appears as the second
motive in our classification, and it is met by a storm of effects which
betting excites. Consequently gambling is pre-eminently suited to
supply this demand. I have already pointed out that betting on the
performances of others is an especially popular form of gambling,
since in this way alone can the excitement be enjoyed unimpaired by
personal considerations. So, too, in games of pure chance, which
relegate the player to comparative inactivity and impart a feeling of
externality among its other effects. By far the most important of
these effects is the contrast of the emotions of hope and fear, and
often this simultaneous action of opposing passions is sufficient to
stir the soul to its depths, since, as Lazarus penetratingly remarks,
the result is in either case positive; the question is not, winning or
not winning, it is winning or losing. This is another point which
renders games of chance peculiarly fit for the production of exciting
effects. Also besides fear and hope there is the tension of
expectation and the shock of surprise to render the mental agitation
more intense and varied. This explains why gambling is the last
resort of the dissipated, worn-out man who needs sharp stimuli to
arouse his exhausted powers.441
Gambling is, moreover, a fighting play, and this is doubtless one of
its most important phases. There is no other form of play which
displays in so many-sided a fashion the combativeness of human
nature and with so slight expenditure of time and strength. There is
the charm of danger as such, enjoyment of bold betting which in the
changing course of the game is constantly renewed, and further
indirect as well as direct battle with an opponent, for he who makes
the best throw gets the best card. Besides all this there is the desire
to win his wager, and by means of the steady augmenting of stakes
it differs from all other fighting plays in affording at the last moment,
when all seems lost, an opportunity of retrieving everything by a
sudden overwhelming victory. And finally there is the defiance of the
power of chance, or rather, if a religious rearing makes one scruple
to put it in this form, we may call it a struggle with the powers of
darkness.
The question now arises whether this is properly called a fight when
the player can not influence the outcome, but must submit
absolutely to the incalculable hazards of fortune. What right has he
to congratulate himself on a victory for which he is in no way
responsible? To this it may be answered that in addition to this
subjective, psychological condition there is an active contest; for an
illusion exists in connection with every game of chance that in some
way the outcome is dependent on the capacity of the player, and a
little reflection will show that this is characteristic of human nature.
How else arises our naïve sense of worth or of shame? Are we not
vain of physical beauty, of inherited advantages, and of riches which
we have not earned? Does not the consciousness of deformity,
stupidity, weakness, awkwardness, or even a lowly origin impart a
feeling of shame and a sense of responsibility for our own
shortcomings? We feel as if we had had a voice in the fashioning of
our bodies and souls and a choice of our position in life—in short, as
the vulgar saying has it, as if we had not been careful enough in the
choice of our parents. Just in the same way we are proud of our luck
in play. Luck is genius, and he whom it smiles upon is a hero.442
This failure to discriminate between fortunate circumstance and
personal merit is shown in a striking manner in popular poetry. Its
heroes are often armed with magic weapons or directly assisted by
higher powers who lend them supernatural strength or work ruin to
their enemies. Such advantage is thus given them that the reflecting
person has some difficulty in regarding their exploits as especially
praiseworthy, yet the average hearer is undisturbed by such
considerations. For instance, consider the invulnerability of Achilles
and Siegfried’s Tarnkappe, which gave him in the fight with Brunhild
“the strength of twelve men.”
In the case which we are considering, however, this habit of mind
has a twofold significance: First, there is the personification of
chance as fate, with whom the player struggles. Lazarus says:
“Instead of blind chance, he pictures before him a reasoning
intelligence whose laws he tries to fathom, and in the face of many
failures and mistaken conclusions he persists in attempting to
calculate his chances and to count on them, forgetting that the
reckoning of probabilities is useful only in generalities and is
practically worthless when applied to a single case. By and bye he
endows luck with moral qualities as well. He will risk everything on a
single card, and either can not believe that Fate will be inexorable,
that his faith and perseverance must at last be rewarded, or else
assumes an attitude of defiance to a hostile being.”443 In the second
place, the gambler regards the implements of his trade as does the
magician among primitive peoples the means of performing his
incantations. It is actual fetich worship in which personification
assumes proportions quite different from those it bears in the
general idea of fate. Demons who sometimes obey the player’s will,
and sometimes mockingly defy him, seem to dwell in the dice and
cards, transforming play into a contest in magic arts. This is perhaps
not so strongly felt by cultivated people of the present day as I have
represented it, yet it is present in a more or less rudimentary form in
all devotees of the game. While some scoff at it, even they avoid
those things which are traditionally supposed to bring ill luck. Thus,
when I was a student, in our games with dice which were very
popular, the following rules were rigidly observed: In order to throw
double sixes, the player took the dice cup in his right hand, placed
the left over it and shook it solemnly three times up and down
before making the final throw. If low numbers were desired, the
inverted cup was held slantingly and drawn carefully back on the
table so that the dice glided out rather than rolled. For medium
throws there was a choice between two methods over whose
comparative efficacy there was serious controversy: either to rise
from the table and empty the cup from a height, or to propel the
dice suddenly by a sidelong movement from the cup, held at a slant.
Was all this mere joking? To a certain extent certainly it was, yet the
boys half believed in it and had a poor opinion of beginners who did
not know how to handle the dice. Among the lower classes,
however, and among peoples of less advanced civilization this
fetichism is much stronger. Konrad von Haslan, says Schuster,
testifies to having seen and heard “how on the one hand dice are
honoured, greeted, and kissed, and have offerings of booty made to
them, while on the other they were beaten and abused as if they
possessed life. Often the player who has lost by them takes revenge
by picking out the spots or smashing the dice with a stone or biting
them in two to make them suffer.”444 All these circumstances
combine to make gaming a fighting play not alone with men, but
also with supernatural powers whose inscrutable decisions possess a
peculiar power and whose favour lends to the fortunate player a
special nimbus, while the vanquished does not suffer in his own
esteem as if he had been conquered by a human foe.
Finally, we should note that gaming has various mental connections
with experimentation, since enjoyment of the excitation of hope and
fear and the feeling of suspense as well as the shock of surprise is
experimental in every case. With this is combined great activity of
attention and imagination to whose agency the personification of
which we have spoken must be ascribed; reason’s part in the
process is displayed in the complex calculation of probabilities, and
that of the will most conspicuously in the effort to appear outwardly
calm while the wildest excitement reigns within, and hope and
despair surge in alternate waves across the soul.
It is difficult to say which of these stimuli ought to be placed at the
head of the list, but two appear to me to be rather more important
than the others. First, the combative impulse, whose influence is
particularly strong here; and, second, pleasure in intense effects, as
when the “gold fever” takes the form of longing for a supreme
moment which shall fill the soul to the brim, something which will
transcend all other transporting agents. Both find their satisfaction at
the gaming table, owing to the suddenness and importance of its
revelations. In concluding, it may be remarked that the extraordinary
persistence of gamblers, who sometimes sit all night at the table, as
if hypnotized, may be at least partly explained by the law of
repetition taken in conjunction with the independent attractions of
the game. The performance of the last part of a mechanically
repeated action tends to lead to the production of the first part
again.

5. The Destructive Impulse


Turning our attention now to the third of our principal groups of
fighting plays, the first subject—namely, the destructive impulse—
will not occupy us long, as we have already given some
consideration to it in the section on analytic movement-play. There
we were chiefly concerned with the experimental element as
manifested in the desire to take things to pieces. Here we shall
emphasize the fighting instinct which is so easily aroused even
toward a lifeless object, and frequently becomes a sort of delirium
which is only appeased by the entire destruction of the object, as if
it were a vanquished foe. And here, too, belongs the inquiry under
what circumstances the discharge of this impulse, whether directed
against a living or a lifeless object, may be considered as playful. As
soon as rage ceases to be the chief influence, and the destruction is
continued simply for the sake of its intoxicating effects, it takes on
more or less of a playful character, though it is inexpedient to
attempt to set clearly defined limits to what is earnest and what is
play.445 When children tear paper or overturn structures laboriously
erected by themselves, how often the interest is cumulative,
developing finally into passionate eagerness from action which was
at first indifferent! The paper is seized in the teeth, the building
kicked to bits, objects which are breakable entirely destroyed,
flowers pulled to pieces, etc. Education should interfere at this point
and direct the play, imposing proper checks. Madame Necker de
Saussure relates of a previously gentle and tractable girl of eighteen
months that “one day when she was alone with her mother, who
was confined to her bed from illness, the child, without the least
provocation, broke into open rebellion. Clothes, hats, fans, and every
movable object that she could lay her hands on were piled in the
middle of the floor, and she danced around the pile and sang with
the greatest delight. Her mother’s serious displeasure had no
restraining effect.”446 “A girl three years old,” says Paolo Lombroso,
“was left alone for a few moments, and proved her ability to improve
the time. She at once began most energetically, and with full
consciousness of what she was doing, to pull to pieces a basket of
vegetables. She reduced all these to fragments, and then emptied
an inkstand in her lap, amusing herself by smearing it on the wall
and floor with her fingers. When that palled she took a corkscrew
and punched her apron as full of holes as a sieve.”447 A little later in
life the impulse leads to more violent misdemeanours. The
destruction of garden borders, smashing of furniture in public parks,
and many other acts of vandalism which we prosecute, are practised
by half-grown lads, and sometimes even by students.448 Some may
object to calling such roughness play, but play it surely is if there is
no malicious intention, as is usually the case. Such mischief is often
reprehensible, and deserves to be checked, yet such antics as those
of the subalterns as described by Eugen Thossan can not be taken
seriously. He says: “Suddenly a beer mug flew across the table and
hit Sergeant Putz square in the face. This was the signal for a
general free fight. Steins flew through the air like cannon balls. Four
lamps borrowed from the officers’ rooms were on the table; one was
struck and the chimney fell off. Somebody called out ‘When the
chimney is gone the lamp may as well follow,’ and a blow from a fist
shattered the lamp. A mad rage for destruction was kindled, and
with anything that came to hand all the lamps were beaten to
pieces. In the general hullabaloo no one noticed the wounds that he
received from the splinters and blows. When every vestige was
demolished, a frightful war whoop rose to the hall above.” It is more
than probable that such orgies as this often have a certain
connection with the sexual life. We find among animals—deer,
buffalo, etc.—a similar rage for destruction during their breeding
season.
My last example refers to mature men. It is the vigorous description
in Vischer’s Auch Einer of the argument of two friends in an inn
about the china displayed around them. “At last Auch Einer called
out: ‘That is enough; they are condemned.’ He bought the whole
collection from the innkeeper and then let himself loose. He handed
me the pitcher with the remark that I should have the honour of
opening the ball. I was not slow to obey, and as a massive granite
block stood opposite the window I sent the pitcher crashing against
it. Auch Einer was delighted, and, seizing a vinegar cruet, followed
suit. Then we took turns with plates, dishes, glasses, and whatever
came to hand. A crowd of villagers soon collected outside and
cheered the rare sport; loud laughter and cries of ‘Go it, there!’
greeted each act of justice.”
Injurious treatment of living creatures, too, is often due to the same
instinct. In the desire to investigate, the principle of the golden rule
is forgotten. It would be too optimistic, however, to assume that
such things are never done from cruelty. Fischart says that even
well-disposed children reveal the demon of fighting and destruction
when there is a beetle or a broken-winged bird or a wounded cat to
torment. Most readers will recall some reminiscence of their own
youth when they really enjoyed inflicting injury on some living thing.
It may assume a dangerous form when directed against other
persons. Some years ago a number of children at play intentionally
drowned a comrade; and Fr. Scholz tells us, “An eight-year-old girl
with an angelic face secretly put some pins in her little brother’s
food, and calmly awaited the catastrophe, which fortunately was
averted.” “A girl twelve years old pushed a child of three, with whom
she was playing, into a pile of paving stones for no other reason
than that she might have the opportunity to tickle him cruelly.”449
Among criminals murders may sometimes result from following this
impulse. Some time ago three peasants were tried for the murder,
with incredible cruelty, of a servant. They were father, son, and
mother. After the old man had throttled his victim he said to his
accomplices, “Now he is dead enough.” But the woman, to make
sure, dealt a hard blow on the poor fellow’s head. “Now I think he
has had enough, this fine rabbit that we have caught.”450 Here the
bounds between play and earnest are hard to place, but probably
belong at the point where the prearranged plan is no longer the
leading thought, it having given place to mad delight in inflicting
injury. These matters are, after all, only on the threshold of play, and
we will now turn our attention to subjects more important to our
inquiry.

6. Teasing451
The fighting instinct of mankind is so intense that all the playful
duels, mass conflicts, single combats, and contests which we have
described, do not satisfy it. When there is no occasion for an actual
testing of their powers, children and adults turn their belligerent
tendencies into a means of amusement, and so arise those playful
attacks, provocations, and challenges which we class together under
the general name of teasing. The roughest if not the earliest form of
such play is that of bodily attack, such as is often observed among
animals. A female ape which Brehm brought to Germany loved to
annoy the sullen house dog. “When he had stretched himself as
usual on the greensward, the roguish monkey would appear and,
seeing with satisfaction that he was fast asleep, seize him softly by
the tail and wake him by a sudden jerk of that member. The enraged
dog would fly at his tormentor, barking and growling, while the
monkey took a defensive position, striking repeatedly on the ground
with her large hand and awaiting the enemy’s attack. The dog could
never reach her, though, for, to his unbounded rage, as he made a
rush for her, she sprang at one bound far over his head, and the
next moment had him again by the tail.”452 We all know how
children delight in just such teasing. To throw an unsuspecting
comrade suddenly on his back, to box him or tickle and pinch him, to
knock off his cap, pull his hair, take his biscuit from his hand, and if
he is small hold it so high that the victim leaps after it in vain—all
this gives the aggressor an agreeable feeling of superiority, and he
enjoys the anger or alarm of his victim. When I was in one of the
lower gymnasium classes our singing on one occasion was suddenly
broken into by a shrill scream. One of the pupils had found a pin
which he energetically pushed into an inviting spot in the anatomy of
the boy in front of him. The culprit could only say in palliation of his
offence that he did it “without thinking,” which excuse was received
rather incredulously. Schoolboys often pull out small handfuls of one
another’s hair, and it is a point of honour not to display any feeling
during the process. Becq de Fouquières records an ancient trick of
this kind, consisting of a blow on the ear in conjunction with a
simultaneous fillip of the nose. Cold water is a time-honoured
instrument of torture. To duck the timid bather who is cautiously
stepping into the pond, to empty a pitcher on a heedless passer-by,
to place a vessel full of water so that the inmate of a room will
overturn it on opening the door—these are jokes familiar wherever
merry young people are found. The lover of teasing naturally seeks
such victims as are defenceless against him, especially those who
are physically weak or so situated as to be incapable of revenge. Yet
there are ways of annoying the strong and capable. A good-natured
teacher is apt to be the subject of his pupils’ pranks, though in this
case they seldom take the form of physical assaults. It is not an
unheard-of thing, however, for a paper ball to hit his head or for his
seat to be smeared with ink or perhaps with glue as in
Messerschmidt’s Sapiens Stultitia.453
Youths and grown men are little behind the children in such jests.
There is, for instance, the christening on board ship in honour of
crossing the line which Leopold Wagner thinks is derived from the
ancient religious ceremony celebrated on passing the pillars of
Hercules.454 Tossing in a blanket, which made such a lasting
impression on Sancho Panza, was known to the Romans by the
name of sagatio. Such rough sports were practised in the time of the
Roman emperors by noble youths. Suetonius relates of Otho that the
future emperor as a young man often seized, with his companions,
upon weak or drunken fellows at night, and tossed them on a
soldier’s mantle (distento sago impositum in sublime jactare).455 In
popular festivities fighting with pigs’ bladders is a fruitful source of
amusements to which tickling with a peacock’s feather is a modern
addition, and lassoing with curled strips of paper which cling about
the neck. Students make a specialty of such pranks. A favourite one
was crowding, when the streets had only a narrow pavement for
pedestrians, while in bad weather the rest of the road was a mass of
unfathomable mud; another was to deal a hard blow on the high hat
of some worthy Philistine, plunging him suddenly into hopeless
darkness, or tracing a circle on the bald head of a toper asleep over
his wine, etc. In an inn in Giessen there is still in existence a bench
through whose seat a nail projects when a hidden cord is pulled—a
pleasant surprise for the unsuspecting guest who reclines upon it.
On entering the gymnasium I was initiated in an æsthetic little
practice which is of ancient date and serves as an instance of the
coarse jesting that is so common there. One of the company secretly
fills his mouth with beer and reclines on two chairs. With a
handkerchief spread over his face he plays the part of The
Innkeeper’s Daughter. They all sing the familiar song, and two
accomplices play the rôle of two of the peasants while the novice is
asked to be the third. The veil is thus twice withdrawn from the
daughter’s face, and twice replaced without any suspicious
revelations, but when the innocent third lover arrives he is greeted
with the stream of stale beer full in the face. A suitable companion-
piece to this decidedly disgusting trick is this incident related by
Joest as occurring among the Bush negroes of Guayana: “As I was
tending the wound of a young negress whose breast was badly cut,
she wearied of the operation, and suddenly seizing it in both hands
she sent a stream of warm milk into my face and fled laughing
away.”456
The most harmless teasing is the obvious kind which forms the basis
of much social play, such as games for a company like “Blind-Man’s
Buff,” “Fox Chase,” “Copenhagen,” and similar diversions. A striking
instance occurs in The Sorrows of Werther. During a violent storm
Lotta attempts to cheer the frightened company; she places chairs in
a circle and seats everybody in them—many acceding in the hope of
being rewarded with a sweet forfeit or two, and getting their lips all
ready. “We are going to play counting,” said Lotta. “Now, attention! I
am going round the circle from right to left, and you must count,
each taking the number that comes to him; and we are going like
lightning, and whoever hesitates or blunders gets a box on the ear,
and we are going on to thousands.” She then stretched out her arms
and flew around the circle, faster and faster. If any one missed,
bang! came a box on his ear, and in the laugh that followed, bang!
came another, and always faster and faster. Werther, however,
noticed with inward satisfaction that the two blows which he
received were somewhat harder than Lotta gave the others. When
the company is still less refined than this, joking sometimes becomes
so rough as to lose its playful character. The ancient Thracians were
celebrated for this sort of thing. Gutsmuth says truly that from this
circumstance much could be inferred concerning the state of
civilization among them, if we had no other sources of information.
“A man stands on a round stone holding a sickle in his hand and
having his head through a noose suspended from above. When he is
not expecting it a bystander pushes the stone away and there hangs
the poor wretch who has been chosen by lot for this fate. If he has
not sufficient skill and presence of mind to cut the knot at once with
the sickle he flounders there until he dies, amid the laughter of the
spectators.”457
Turning now to other forms of teasing than direct bodily annoyance,
we find again that children very early understand it. When the
pretence is made of great alarm at his beating with a spoon or
banging a book or at a sudden cry, a child as young as two years old
shows great delight, and will repeat the performance with a roguish
expression. From this time on, to cause sudden fright is a favourite
method of gratifying the taste for teasing. The ghostly
manifestations which terrify each generation in turn can often be
traced to some mischievous urchins.
I remember a joke played on a geographical professor at the
gymnasium who, as he carelessly opened a closet door, was
confronted by a skeleton which had been used in the previous
lecture. Students could hardly subsist without the ancient trick of
stuffing the clothes of a “suicide,” and placing the figure on the floor
of their victim’s room with a pistol lying near, or hanging it by a rope
to the window frame, to give the late home-comer a genuine scare.
In Athenäus we find a beautiful instance of readiness to meet such a
trick. King Lysimachus, who took delight in teasing his guests, one
day at a banquet threw a skilfully made artificial scorpion on to the
dress of one Bithys, who recoiled; but, quickly recovering himself,
said to the rather penurious king: “My lord, it is now my turn to
frighten you; I beseech you give me a talent.”458 Such sport with
fear, though harmless in these instances, becomes a passion with all
narrowminded, tyrannous natures, and leads to cruelty which is
anything but playful. Slatin’s dramatic work, Fire and Sword in the
Soudan, gives an instance of such traits in the character of the
Caliph Abdullah. Indeed, Abdullah had a part in, or rather was the
occasion of, Slatin’s first experience during the life of the Mahdi.
Slatin was taken prisoner by the Mahdi’s army before the gates of
Khartoum. The morning after the city was taken, alarming rumours
reached him; half incredulous, he looked out of his tent. “A mob had
collected before the quarters of the Mahdi and his caliphs; it seemed
to be getting into motion and making toward me, and I soon saw
clearly that they were coming in the direction of my tent. I could
now distinguish single persons. First walked the negro soldiers, one
of whom, whose name was Shetta, carried a bloody burden on his
head. Behind him howled the mob. The slaves entered my tent and
stood glowering before me, and Shetta opened the roll of cloth and
showed me—Gordon’s head! I grew faint and dizzy at the sight, my
breath stopped, and it was only by the greatest effort that I
commanded myself sufficiently to gaze upon that pallid face.” The
Mahdi and his caliphs had ordered this hideous cruelty.459
A common and early developed form of teasing is the deception
which imparts to the perpetrator a feeling of intellectual superiority.
Children display this in their tender years principally by pretending
that they are going to do forbidden or improper things, as revolt
against authority. When the little girl observed by Pollock was
twenty-three months old she often declined to kiss her father good-
night. She turned from him as if annoyed or indifferent, to make a
fausse sortie, and then called him back and gave the kiss.460
Sigismund’s boy often exhibited a “kind of humorous defiance of
authority,” such as grasping at a light standing near him, but not so
that it could burn him, and looking slyly at his father.461
Older children have innumerable tricks of this kind. A sort of game is
to strike on a table with a spoon or on the floor with a card and
repeat the formula “He can do little who can’t do this, this,” and pass
the stick or spoon to the next neighbour with the left hand. The
uninitiated who attempt to do this usually pass it with the right hand

You might also like