Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (1 vote)
19 views

Go for Java Programmers: Learn the Google Go Programming Language 1st Edition Barry Feigenbaum all chapter instant download

Programming

Uploaded by

loleyjetsor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
19 views

Go for Java Programmers: Learn the Google Go Programming Language 1st Edition Barry Feigenbaum all chapter instant download

Programming

Uploaded by

loleyjetsor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 65

Download Full Version ebook - Visit ebookmeta.

com

Go for Java Programmers: Learn the Google Go


Programming Language 1st Edition Barry Feigenbaum

https://ebookmeta.com/product/go-for-java-programmers-learn-
the-google-go-programming-language-1st-edition-barry-
feigenbaum/

OR CLICK HERE

DOWLOAD NOW

Discover More Ebook - Explore Now at ebookmeta.com


Instant digital products (PDF, ePub, MOBI) ready for you
Download now and discover formats that fit your needs...

Start reading on any device today!

Network Programming with Go Language: Essential Skills for


Programming, Using and Securing Networks with Open Source
Google Golang 2nd Edition Jan Newmarch
https://ebookmeta.com/product/network-programming-with-go-language-
essential-skills-for-programming-using-and-securing-networks-with-
open-source-google-golang-2nd-edition-jan-newmarch-2/
ebookmeta.com

Network Programming with Go Language : Essential Skills


for Programming, Using and Securing Networks with Open
Source Google Golang 2nd Edition Jan Newmarch
https://ebookmeta.com/product/network-programming-with-go-language-
essential-skills-for-programming-using-and-securing-networks-with-
open-source-google-golang-2nd-edition-jan-newmarch/
ebookmeta.com

Learn Concurrent Programming with Go (MEAP v02) James


Cutajar

https://ebookmeta.com/product/learn-concurrent-programming-with-go-
meap-v02-james-cutajar/

ebookmeta.com

Wild Women Do Female Killers tricksters and crooks in


Singapore 1st Edition Yeo Suan Futt

https://ebookmeta.com/product/wild-women-do-female-killers-tricksters-
and-crooks-in-singapore-1st-edition-yeo-suan-futt/

ebookmeta.com
Engineering Disease Resistance in Plants using CRISPR-Cas
1st Edition Zulqurnain Khan

https://ebookmeta.com/product/engineering-disease-resistance-in-
plants-using-crispr-cas-1st-edition-zulqurnain-khan/

ebookmeta.com

Sports Cardiology Care of the Athletic Heart from the


Clinic to the Sidelines David J. Engel

https://ebookmeta.com/product/sports-cardiology-care-of-the-athletic-
heart-from-the-clinic-to-the-sidelines-david-j-engel/

ebookmeta.com

Fiberglass Science and Technology Chemistry


Characterization Processing Modeling Application and
Sustainability Hong Li (Editor)
https://ebookmeta.com/product/fiberglass-science-and-technology-
chemistry-characterization-processing-modeling-application-and-
sustainability-hong-li-editor/
ebookmeta.com

Mathematics in the 21st Century 2022 Edition Scientific


American Editors

https://ebookmeta.com/product/mathematics-in-the-21st-
century-2022-edition-scientific-american-editors/

ebookmeta.com

Fighting for the News The Adventures of the First War


Correspondents from Bonaparte to the Boers 3rd Edition
Brian Best
https://ebookmeta.com/product/fighting-for-the-news-the-adventures-of-
the-first-war-correspondents-from-bonaparte-to-the-boers-3rd-edition-
brian-best/
ebookmeta.com
Wireless Interface Technologies for 3D IC and Module
Integration 1st Edition Tadahiro Kuroda

https://ebookmeta.com/product/wireless-interface-technologies-
for-3d-ic-and-module-integration-1st-edition-tadahiro-kuroda/

ebookmeta.com
Go for Java
Programmers
Learn the Google Go Programming
Language

Barry Feigenbaum, Ph.D.
Go for Java Programmers
Learn the Google
Go Programming Language

Barry Feigenbaum, Ph.D.


Go for Java Programmers: Learn the Google Go Programming Language

Barry Feigenbaum, Ph.D.


Austin, TX, USA

ISBN-13 (pbk): 978-1-4842-7198-8 ISBN-13 (electronic): 978-1-4842-7199-5 


https://doi.org/10.1007/978-1-4842-7199-5
Copyright © 2022 by Barry Feigenbaum
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: Matthew Moodie
Coordinating Editor: Mark Powers
Cover designed by eStudioCalamar
Cover image by Ricardo Gomez on Unsplash (www.unsplash.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 via the book’s product page, located at www.apress.com/9781484271988. For more
detailed information, please visit http://www.apress.com/source-­code.
Printed on acid-free paper
To my wife Martha who sustains me.

Thank you for putting up with all the time


I spent working on this book.

This book was developed during the Covid-19 pandemic.


Many thanks and kudos to all the health-care workers that served so
many that became ill and to the essential workers that keep the country
going during this time of crisis. My heart goes out to the many who lost
friends and loved ones due to Covid-19. May time reduce your pain.
Personally, the stay-at-home nature of this crisis offered me the time
needed to author this book, so in some way is it a, hopefully, positive
by-product of the pandemic.
Table of Contents
About the Author��������������������������������������������������������������������������������������������������� xiii

About the Technical Reviewer���������������������������������������������������������������������������������xv


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

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

Assessments�������������������������������������������������������������������������������������������������������xxxv

Part I: First Look at Go������������������������������������������������������������������������������������ 1


Chapter 1: A Brief Look at Go vs. Java��������������������������������������������������������������������� 5
Go Is a Compiled (vs. Interpreted, As Java Is) Language�������������������������������������������������������������� 6
Go and Java Share Similar Program Structure����������������������������������������������������������������������������� 7
Go and Java Have Some Code Style Differences That Influence How Code Is Structured������������ 7
Both Go and Java Are Procedural Languages������������������������������������������������������������������������������� 8
Java Is an Object-Oriented (OO) Language, While Go Is Not Fully OO������������������������������������������� 9
Java Is a Highly Functional Language, Go Is Less So������������������������������������������������������������������ 10
Java Is a Highly Declarative Language, Go Is Less So���������������������������������������������������������������� 10
Many Java Features Are Annotation Driven�������������������������������������������������������������������������������� 10
Go Does Not Support Exceptions������������������������������������������������������������������������������������������� 11
Both Java and Go Use Managed Memory (Garbage Collectors)�������������������������������������������������� 11
Go and Java Both Support Concurrency but in Different Ways��������������������������������������������������� 12
Go’s Runtime Is Simpler Than the JRE���������������������������������������������������������������������������������������� 12
The Go Program Build Process Is Different��������������������������������������������������������������������������������� 13
Go and Java Have Similar Release Cycles���������������������������������������������������������������������������������� 13

v
Table of Contents

Chapter 2: What Java Has That Go Does Not���������������������������������������������������������� 15


Multiple Assignments������������������������������������������������������������������������������������������������������������������ 15
Statements and Operators���������������������������������������������������������������������������������������������������������� 15
Assert Statement������������������������������������������������������������������������������������������������������������������������ 16
While and Do Statements������������������������������������������������������������������������������������������������������������ 16
Throw Statement/Throws Clause������������������������������������������������������������������������������������������������ 17
Strictfp, transient, volatile, synchronized, abstract, static���������������������������������������������������������� 17
Objects and Classes (OOP) and Inner Classes, Lambdas, this, super, Explicit Constructors������� 17
Generic Types and Methods�������������������������������������������������������������������������������������������������������� 20
Extensive Functional Programming Capabilities������������������������������������������������������������������������� 20
Boxing of Primitive Values���������������������������������������������������������������������������������������������������������� 21
Source Annotations��������������������������������������������������������������������������������������������������������������������� 21
Multiple Visibilities���������������������������������������������������������������������������������������������������������������������� 22
Overloaded/Overridden Functions����������������������������������������������������������������������������������������������� 22
Formal Enums����������������������������������������������������������������������������������������������������������������������������� 22
Built-in Binary Data Self-Serialization���������������������������������������������������������������������������������������� 23
Concurrent Collections���������������������������������������������������������������������������������������������������������������� 23

Chapter 3: A Deeper Comparison of Go and Java��������������������������������������������������� 25

Part II: The Go Language������������������������������������������������������������������������������� 31


Chapter 4: Key Go Aspects������������������������������������������������������������������������������������� 33
Simple Go Program Example������������������������������������������������������������������������������������������������������ 35
Go Packages������������������������������������������������������������������������������������������������������������������������������� 41
Go Comments������������������������������������������������������������������������������������������������������������������������������ 44
Go Build/Run Process������������������������������������������������������������������������������������������������������������������ 45
Go Playground����������������������������������������������������������������������������������������������������������������������� 46
Go Integrated Development Environments���������������������������������������������������������������������������� 50
Running Go Programs������������������������������������������������������������������������������������������������������������ 55
Building Go Programs������������������������������������������������������������������������������������������������������������ 56
Bytecode vs. Real Code��������������������������������������������������������������������������������������������������������� 59

vi
Table of Contents

Go Command-Line Tools������������������������������������������������������������������������������������������������������������� 61
Tools Bundled in the Go Command���������������������������������������������������������������������������������������� 62
Other Tools����������������������������������������������������������������������������������������������������������������������������� 64
Go Runs Programs Instead of Classes���������������������������������������������������������������������������������������� 64
Go Memory Management������������������������������������������������������������������������������������������������������������ 66
Go Identifiers������������������������������������������������������������������������������������������������������������������������������� 71
Go Scopes����������������������������������������������������������������������������������������������������������������������������������� 73
Go Scopes vs. Go Source Files���������������������������������������������������������������������������������������������� 76
Initializing Go Variables��������������������������������������������������������������������������������������������������������������� 78
Lifetimes of Go Identifiers����������������������������������������������������������������������������������������������������������� 80
Go Module Summary������������������������������������������������������������������������������������������������������������������� 81
Go Assignments and Expressions����������������������������������������������������������������������������������������������� 87
Text Formatting in Go������������������������������������������������������������������������������������������������������������������ 89
Goroutines����������������������������������������������������������������������������������������������������������������������������������� 94
Issues with Concurrency������������������������������������������������������������������������������������������������������� 94
Go Concurrency��������������������������������������������������������������������������������������������������������������������� 97
Goroutines by Example�������������������������������������������������������������������������������������������������������� 100

Chapter 5: Go Basic Features������������������������������������������������������������������������������� 111


Language Keywords������������������������������������������������������������������������������������������������������������������ 111
Operators and Punctuation������������������������������������������������������������������������������������������������������� 114
Go Operator Precedence����������������������������������������������������������������������������������������������������������� 119
Go Built-in Functions����������������������������������������������������������������������������������������������������������������� 120

Chapter 6: Go Types���������������������������������������������������������������������������������������������� 123


Primitive/Built-in Types������������������������������������������������������������������������������������������������������������� 123
Numbers������������������������������������������������������������������������������������������������������������������������������ 123
Characters and Strings�������������������������������������������������������������������������������������������������������� 125
Reference vs. Pointer Types������������������������������������������������������������������������������������������������ 126
Drill Down on Basic Data Types������������������������������������������������������������������������������������������� 129
Methods As Functions��������������������������������������������������������������������������������������������������������� 152
Any Declared Type Can Have Custom Functions����������������������������������������������������������������� 153

vii
Table of Contents

Functions As Values������������������������������������������������������������������������������������������������������������� 155


Structure Fields������������������������������������������������������������������������������������������������������������������� 162
Structure Literals����������������������������������������������������������������������������������������������������������������� 164
Nested Structures���������������������������������������������������������������������������������������������������������������� 165
Structure Field Alignment���������������������������������������������������������������������������������������������������� 167
Application of Interfaces������������������������������������������������������������������������������������������������������ 171
Composite Interfaces����������������������������������������������������������������������������������������������������������� 174
Variable Declarations���������������������������������������������������������������������������������������������������������������� 179
Constant Declarations��������������������������������������������������������������������������������������������������������������� 182
Type Casting������������������������������������������������������������������������������������������������������������������������������ 184
Type Testing������������������������������������������������������������������������������������������������������������������������������ 185
Derived Type Declarations��������������������������������������������������������������������������������������������������������� 188

Chapter 7: Errors and Panics�������������������������������������������������������������������������������� 193


Go Errors����������������������������������������������������������������������������������������������������������������������������������� 193
Go Panics���������������������������������������������������������������������������������������������������������������������������������� 195
Errors and Panics Illustrated����������������������������������������������������������������������������������������������������� 199

Chapter 8: Go Statements������������������������������������������������������������������������������������� 207


Package and Import Statements����������������������������������������������������������������������������������������������� 208
Assignment Statements������������������������������������������������������������������������������������������������������������ 209
Declaring Variables������������������������������������������������������������������������������������������������������������������� 211
Declaring Named Constants����������������������������������������������������������������������������������������������������� 213
If/Else Statements��������������������������������������������������������������������������������������������������������������������� 214
Switch Statement��������������������������������������������������������������������������������������������������������������������� 217
While Statement������������������������������������������������������������������������������������������������������������������������ 220
Do-While Statement������������������������������������������������������������������������������������������������������������������ 221
For with Index Statement���������������������������������������������������������������������������������������������������������� 221
For over a Collection Statement������������������������������������������������������������������������������������������������ 222
Forever Statement�������������������������������������������������������������������������������������������������������������������� 224
Break and Continue Statements����������������������������������������������������������������������������������������������� 225
Goto Statement������������������������������������������������������������������������������������������������������������������������� 226

viii
Table of Contents

Return Statement���������������������������������������������������������������������������������������������������������������������� 227


Defer Statement������������������������������������������������������������������������������������������������������������������������ 228
Go Statement���������������������������������������������������������������������������������������������������������������������������� 229
Select Statement���������������������������������������������������������������������������������������������������������������������� 230

Chapter 9: Applications for Interfaces������������������������������������������������������������������ 233


An Interface Is the Key�������������������������������������������������������������������������������������������������������������� 233
On Dependency Injection���������������������������������������������������������������������������������������������������������� 236
On Aspect-Oriented Programming�������������������������������������������������������������������������������������������� 244

Chapter 10: Go Unit Tests and Benchmarks��������������������������������������������������������� 249


Test Cases and Benchmarks in Go�������������������������������������������������������������������������������������������� 250
Test Cases in Java��������������������������������������������������������������������������������������������������������������������� 262

Chapter 11: Going into the Future������������������������������������������������������������������������� 267


Improved Error Handling����������������������������������������������������������������������������������������������������������� 267
Go Generics������������������������������������������������������������������������������������������������������������������������������� 269
Capstone Game of Life Example����������������������������������������������������������������������������������������������� 275
Game of Life Go Source������������������������������������������������������������������������������������������������������������ 280
Capstone Project in Java����������������������������������������������������������������������������������������������������� 281
Capstone Project in Go�������������������������������������������������������������������������������������������������������� 326
API Outputs������������������������������������������������������������������������������������������������������������������������������� 355
Game Outputs��������������������������������������������������������������������������������������������������������������������������� 359

Part III: Go Library Survey�������������������������������������������������������������������������� 363


Chapter 12: Key Package Comparison������������������������������������������������������������������ 375
Java Lang Packages����������������������������������������������������������������������������������������������������������������� 375
Java IO Package������������������������������������������������������������������������������������������������������������������������ 380
Java Text Package��������������������������������������������������������������������������������������������������������������������� 383
Java Time Packages����������������������������������������������������������������������������������������������������������������� 385
Java Util Packages�������������������������������������������������������������������������������������������������������������������� 386

ix
Table of Contents

Chapter 13: Key Method/Function Comparison���������������������������������������������������� 393

Chapter 14: Go Package Survey��������������������������������������������������������������������������� 399


File Access with Go������������������������������������������������������������������������������������������������������������������� 399
Compression Services�������������������������������������������������������������������������������������������������������������� 402
Archive Packages���������������������������������������������������������������������������������������������������������������� 402
Compression Packages������������������������������������������������������������������������������������������������������� 405
Image���������������������������������������������������������������������������������������������������������������������������������������� 406
Input/Output (I/O)���������������������������������������������������������������������������������������������������������������������� 409
Bytes Package�������������������������������������������������������������������������������������������������������������������������� 415
Format Package������������������������������������������������������������������������������������������������������������������������ 419
Data Collections������������������������������������������������������������������������������������������������������������������������ 421
Sorting�������������������������������������������������������������������������������������������������������������������������������������� 424
Context Package����������������������������������������������������������������������������������������������������������������������� 426
Cryptography and Hashing and Data Encoding������������������������������������������������������������������������� 430
Encoding Packages������������������������������������������������������������������������������������������������������������������� 431
Unicode Encoding Packages����������������������������������������������������������������������������������������������� 433

Chapter 15: SQL Database Access������������������������������������������������������������������������ 437

Chapter 16: Client and Server Support����������������������������������������������������������������� 449


MIME Packages������������������������������������������������������������������������������������������������������������������������� 449
Network Packages�������������������������������������������������������������������������������������������������������������������� 449
The Net Package����������������������������������������������������������������������������������������������������������������������� 450
The HTTP Template Package����������������������������������������������������������������������������������������������������� 462
The Net.HTTP Package�������������������������������������������������������������������������������������������������������������� 467
URL Package����������������������������������������������������������������������������������������������������������������������������� 477

Chapter 17: Go Runtime���������������������������������������������������������������������������������������� 479


Errors Package�������������������������������������������������������������������������������������������������������������������������� 479
Flag Package���������������������������������������������������������������������������������������������������������������������������� 480
Log Package����������������������������������������������������������������������������������������������������������������������������� 485
Math Package��������������������������������������������������������������������������������������������������������������������������� 492

x
Table of Contents

Operating System Support Packages��������������������������������������������������������������������������������������� 507


Reflection Package������������������������������������������������������������������������������������������������������������������� 515
Regular Expression Package����������������������������������������������������������������������������������������������������� 517
Go Runtime Packages��������������������������������������������������������������������������������������������������������������� 519
String Processing Packages����������������������������������������������������������������������������������������������������� 520
Concurrency and Goroutines����������������������������������������������������������������������������������������������������� 525
Testing Package������������������������������������������������������������������������������������������������������������������������ 528
Time and Date Package������������������������������������������������������������������������������������������������������������ 533

Appendix A: Installing Go������������������������������������������������������������������������������������� 541

Appendix B: Some Go FAQs����������������������������������������������������������������������������������� 553

Appendix C: Go Gotchas to Look Out For�������������������������������������������������������������� 561

Appendix D: Mark-Sweep Pseudocode����������������������������������������������������������������� 567

Appendix E: ASCII vs. UTF-8��������������������������������������������������������������������������������� 571

Index��������������������������������������������������������������������������������������������������������������������� 575

xi
About the Author
Barry Feigenbaum, Ph.D., has decades of software engineering experience. During his
career, he has worked for major industry-leading companies, such as IBM and Amazon,
and is currently at Dell where he is a Senior Principal Software Engineer. He has worked
on mainframe and midrange servers and many applications for personal computers.
He has developed software products, such as assemblers for multiple hardware
architectures, in many key industry languages such as C/C++/C#, Python, JavaScript,
Java, and now Go. He has extensive experience in the full software development life
cycle. Most recently, he has committed himself to leading teams developing mission-­
critical microservices, most often written in Go, that operate in large clustered
environments.
He led the early development of the LAN support inside Microsoft Windows
(he defined the SMB protocol that is the basis for both the CIFS and the SAMBA
technologies). He has served as a software tester, developer, and designer as well as a
development team lead, architect, and manager on multiple occasions. He was a key
contributor as a developer, architect, and manager to several releases of PC-DOS and
OS/2. In these roles, he worked extensively with Microsoft on joint requirements, design,
and implementation.
Dr. Feigenbaum has a Ph.D. in Computer Engineering with a concentration in
object-oriented (OO) software design and other degrees in Electrical Engineering. He
has published multiple articles in technical magazines and juried journals. He has
coauthored several books on IBM PC-DOS. He has spoken at numerous technical
conferences, such as JavaOne. He has served on industry standard bodies. He has taught
multiple college-level courses on data structures, software engineering, and distributed
software as an adjunct professor at several universities. He has over 20 issued US patents.
He is married, has one son, and lives in Austin, TX.

xiii
About the Technical Reviewer
Ronald Petty, M.B.A., M.S., is founder of Minimum
Distance LLC, a management consulting firm based in
San Francisco. He spends his time helping technology-
based startups do the right thing. He is also an instructor
at UC Berkeley Extension.

xv
Acknowledgments
To my son Barry, Jr., for his careful review of the drafts of this book. He provided a
perfect example of the book’s target audience: a professional Java programmer wanting
to learn Go.
A hearty thanks to all the other reviewers that made helpful comments, suggested
additional content, and/or made errata corrections: Charles Stein, Divya Khatnar, Rosish
Shakya, and Sharath Hegde.
I especially want to thank Ronald Petty for his thorough technical review of this text.
Also, for his numerous suggested content improvements and code samples, several of
which were included.
I wish to thank Jason Isaacs at Dell who supported me during the creation of this text
and allowed me to go forward with this effort.
To the developers of Go and to the Go community in general, many thanks for
building such a powerful tool. I learned much from the extensive Go documentation and
the many articles, blogs, wikis, tutorials, and books provided by the community.

xvii
Introduction
Since its debut in the mid-1990s, Java has enjoyed huge success. Arguably more so
than other languages, Java is a major player in the web application space and key data
processing areas such as Big Data tools, among others. Among other aspects, Java’s high
level of portability across operating systems and hardware architectures, its rich and
improving over time language and library of functions, as well as its good performance
contributed to this success.
But Java comes with some drawbacks. Java was created at a time when Object-­
Oriented Programming1 was the norm and network delivery of code was advantageous.
The resulting Java runtime footprint is quite large, and it is resource intensive. The Java
developers are trying to address this to some degree with the use of Java Modules along
with standard library subsetting and the Graal2 Virtual Machine, but typical Java code,
for the same functionality, often uses more resources than typical Go code does.
As time is passing, the Java language and runtime is no longer an optimal fit for many
modern, especially cloud-based, applications. Also, the Java language is continuously
growing and can be a challenge to fully master. Go is deliberately a simple, thus easy to
master, language.
The Go language and runtime is relatively new and designed to meet the needs
of modern cloud computing systems and other system3 programming tasks. It is
considered by many to be a “better C than C” and thus a potential replacement for the C4
programming language, the language it most closely resembles. Go is also likely to take
over a large fraction of the Java server and application space. Thus, it is the raison d'etre
for this book.
Many new applications and reengineering of existing applications are now being
developed in Go. For applications previously written in Java, Kotlin5 or Scala6 JVM

1
https://en.wikipedia.org/wiki/Object-oriented_programming
2
www.graalvm.org/java/
3
Oriented to operating the computer system rather than achieving business tasks.
4
https://en.wikipedia.org/wiki/C_(programming_language)
5
https://kotlinlang.org/
6
www.scala-lang.org/

xix
Introduction

(both available as Java Virtual Machine–based languages) might be the more expected
language to use, but often Go is winning out over them. As an example of a redo into
Go, Khan Academy7 is using Go to reengineer8 its previous Python site implementation.
This often happens because Go exhibits many of the ease-of-use features common to
scripting languages with the efficiency of compiled languages.
The original Go lead designers, Robert Griesemer, Rob Pike, and Ken Thompson, all
at Google, wanted to define a language and associated runtime with these key features
(some also provided by Java):
• High developer productivity – Go offers a consumable and
reasonably complete runtime. It also offers a one-stop shopping
toolchain. It has widespread high community support.

• High readability and developer usability – The language itself is


small, so it is easy to learn, and its code is both easy to read and
understand vs. easiest/fastest to write. It has a targeted ease of use
comparable to nonstatically typed languages like Python. Often, the
language is opinionated (sort of take it or leave it).

• Go uses memory garbage collection (GC) which reduces programmer


effort and makes for more reliable programs.

• Go is statically linked (vs. dynamically linked, as Java is); this makes it


easier to manage deployment and execution of Go programs.

• Static typing – Generally supports safer, more performant, and more


predictable programs; helps with high reliability and long duration
execution critical for servers.

• Runtime efficiency – The code efficiently uses the processors it runs


on, comparable to what is achievable in C/C++9 applications.

7
www.khanacademy.org/
8
https://blog.khanacademy.org/half-a-million-lines-of-go/
9
https://en.wikipedia.org/wiki/C%2B%2B

xx
Introduction

• High network performance – Distributed/cloud use cases are now


common, and the code needs to be performant for them. For the
same level of function, Go is often less resource intensive than
Java typically is; this helps with reducing resource footprint and
improving scale in modern cloud distributions.
• High utilization of multi-processor systems – The code needs to allow
easy and safe exploitation of multi-processor (core) systems that have
become the norm. Go excels at this.
Robert Pike summarized10 this as follows:
… we wanted a language with the safety and performance of statically
compiled languages such as C++ and Java, but the lightness and fun of
dynamically typed interpreted languages such as Python. It was also impor-
tant that the result be suitable for large systems software development on
modern, networked, multicore hardware.
The Go Brand Book11 (GBB) states:
Go is an open source programming language that enables the production
of simple, efficient and reliable software at scale.
The GBB further states that Go has these benefits for new programmers:
Developer productivity of a dynamic language with the speed,
safety, and reliability of a static language
• Easy to learn & readable
• Has a vibrant, welcoming community, spanning open-source
developers, startups, large companies, and universities
• The language for the Cloud
And these benefits for experienced programmers:
• Solves big engineering problems
• Backed by Google, who understands and supports needs specific to
open source communities and Go
• High demand for Go programmers

10
www.red-gate.com/simple-talk/opinion/geek-of-the-week/rob-pike-geek-of-the-week/
11
https://storage.googleapis.com/golang-assets/Go-brand-book-v1.9.5.pdf
xxi
Introduction

In many ways, Go is a lot like Node.js,12 a popular JavaScript13-based application


development platform. Node.js makes it easy to develop lightweight servers very
quickly and thus is popular as a microservices platform. Node.js and Go have
similar capabilities, history, and community support. Go, because of its type safety
and goroutines (vs. Node.js’s event loop), is likely to be able to provide more
scaled and reliable solutions than Node.js can. In the author’s opinion, Go will also
consume a significant number of the Node.js use cases.

As a result, many applications previously done in Java can instead be implemented


in Go with some advantages, especially in cloud environments.
So, in summary, here are some Go advantages relative to Java:

• Go is a smaller language that is clean, maintainable, and easy to


learn.

• Go is better suited to support multi-core processors and high levels of


concurrency.

• Go has a smaller but strong set of standard libraries, especially for


building servers, that comes bundled with the standard installation.

• Go is well suited to cloud execution, especially in a containerized


environment.

• Go is well suited to any constrained environments where large code


and runtime footprint can be issues.
Go is open source, has an active developer community, and is sponsored by Google;
it will not go away. Future Go evolution will retain backward compatibility;14 this is a Go
community promise. This makes Go a great language for commercial development.
Hackernoon15 says: “Go is on a trajectory to become the next enterprise programming
language.”

12
https://en.wikipedia.org/wiki/Node.js, https://nodejs.org/en/
13
https://en.wikipedia.org/wiki/JavaScript
14
https://golang.org/doc/go1compat
15
https://hackernoon.com/go-is-on-a-trajectory-to-become-the-next-enterprise-
programming-language-3b75d70544e

xxii
Introduction

They further say:

Go — a programming language designed for large-scale software develop-


ment — provides a robust development experience and avoids many issues
that existing programming languages have. These factors make it one of the
most likely candidates to succeed Java as the dominating enterprise soft-
ware platform in the future. … Taken as a whole, they (Go’s design choices)
position Go as an excellent choice for large development projects looking
for a modern programming language beyond Java.
InfoWorld16 says:

Google’s Go programming language has certainly made a name for itself.


Lightweight and quick to compile, Go has stirred significant interest due to
its generous libraries and abstractions that ease the development of concur-
rent and distributed (read: cloud) applications. … But the true measure of
success of any programming language is the projects that developers create
with it. Go has proven itself as a first choice for fast development of network
services, software infrastructure projects, and compact and powerful tools
of all kinds.
Open source projects they mention that use Go include Docker, Kubernetes, Fedora
CoreOS, InfluxDB, Istio, Traefik, Hugo, Terraform, CockroachDB, and Gravitational
Teleport.
Note that Docker and Kubernetes are the foundation technologies for the
containerization of many modern applications. Many organizations depend on them to
be rock solid and performant. This is a testament to the maturity of the Go language and
its runtime.
Brainhub17 list some major companies using Go and the advantages they see:
• Simple code

• Created for large projects

• Easy to learn

• One problem – one solution

• Ease of maintenance

16
www.infoworld.com/article/3442978/10-open-source-projects-proving-the-power-of-
google-go.html
17
https://brainhub.eu/library/companies-using-golang/

xxiii
Introduction

• Similar to C

• Designed for multi-core processors

• Designed for the Internet

• Quick compilation

• Small application size

• Open source model


They mention companies using Go including Google (of course), Uber, Twitch,
Dailymotion, SendGrid, Dropbox, and SoundCloud.
Awesome Open Source18 lists over 15,000 (and growing) projects that use Go.
Sandra Parker19 projects20 Go has a winning future where she emphasizes: “Because
it is made by Google.”
She indicates why it’s currently popular: “Go is different from other languages. It is
young but so powerful that it was able to bring up geek’s engagement from the very start.”
In summary:

• It is convenient, fast, and secure to write code with Golang, and it


provides cross-platform support…

• Google cares about the user.

• Golang has cloud infrastructure.

• Google has money.

And why it is going to get more popular as time passes:


Applications written on Go are highly performant. Golang is very efficient
like C/C++, handling parallelisms like Java, and has easy code readability
like Python, Perl, and Erlang. … This is why many companies migrate to
Golang from other languages. Golang is the future.

18
https://awesomeopensource.com/projects/go
19
www.quora.com/profile/Sandra-Parker-34
20
https://medium.com/@Sandra_Parker/why-golang-is-the-future-part-1-ed7dd4f419d and
https://medium.com/@Sandra_Parker/why-golang-is-the-future-part-2-1f984ae8f1a4

xxiv
Introduction

In 2020, Ziff Davis21 showed that Go is the most desired new language to learn, as
shown in Figure 1.

Programming languages that working professionals would like to learn:

40% Working professionals

32%

30%

25%
24%
21%
20%
20%
18%
16%
15%
15% 14%

10%

5%

0%

Go Python Kotlin Javascript Bash/Shell Typescript Scala R (Rscript)


(Node.js) /PowerShell

Figure 1. Programming languages professionals want to learn

Other sources extol the virtues of Go and indicate it has a growing future. For
example, Towards Data Science22 states these as key features for Go’s success:
1. Go has language-level support for Concurrency. It offers a CSP23
based message-passing concurrency via Goroutine (lightweight
Green thread) and Channel.

21
https://en.wikipedia.org/wiki/Ziff_Davis, www.zdnet.com/article/developers-
say-googles-­go-is-most-sought-after-programming-language-of-2020/, and www.
hackerearth.com/recruit/developer-survey/
22
https://towardsdatascience.com/top-10-in-demand-programming-languages-to-learn-
in-2020-4462eb7d8d3e
23
Communicating sequential processes – https://en.wikipedia.org/wiki/
Communicating_sequential_processes

xxv
Introduction

2. The biggest USP24 of Go is its language design and simplicity. It has


successfully combined the simplicity and productivity of Python
and the power of C.

3. Go has embedded Garbage Collector (albeit not as mature as JVM


garbage collector). Go developers can write system programming
with the safety of Java, Python.

Go is ranked as one of the top five most loved languages by GeeksforGeeks,25 which
describes Go as follows:
Go is a statically typed, open-source programming language designed at
Google that makes programmers more productive and helps to build simple,
reliable, and efficient software very easily. This language … is syntactically
similar to C, but with memory safety, garbage collection, structural typing,
and CSP-style concurrency. Go is well known for its high-performance in
networking and multiprocessing.
They cite these key virtues:

1. Concurrency: provides greater concurrency with the help of


goroutine which makes it extremely easy to implement in a
concurrent system. …

2. Simplicity and Consistency: This language was designed with a


very minimalistic approach and it is well known for its simplicity.
… The standard library and the packages are consistent.

3. Object-oriented: Go is an Object-oriented programming language


and supports the useful features of OOPs. …

4. Tools: Go provides many useful tools for building, testing, and


analyzing code…

5. Compiler: Its compiler is super-fast and easily compiles a large go


program within a few seconds. …

24
Unique selling proposition – https://en.wikipedia.org/wiki/Unique_selling_proposition
25
www.geeksforgeeks.org/top-5-most-loved-programming-languages-in-2020/

xxvi
Introduction

Note that this author disagrees with point 3. In his opinion, Go is object-based,26 not
object-oriented.
The popular TIOBE27 index shows that Go use is growing at a fast rate. A late 2020
survey shows this:

• Current Year Rank: 13

• Previous Year Rank: 20

• Growth Rate: High

Few languages have seen such high year-over-year growth. TIOBE twice named
Go as the “language of the year.” The future need for Go programmers is expected to
continue to grow rapidly.
A look at Go Users28 shows hundreds of organizations, including some of the world’s
largest companies, using Go around the world. This list is likely to omit many actual
users.
Go is used, and in many ways proven effective, in many complex programs. The
Docker29 container system and the Kubernetes30 container orchestrator are prime
examples of industry-leading programs written in Go. Also, the Go compiler, builder,
and most of the standard libraries are written in Go.31 They are an important test case in
themselves.
In 2020, StackOverflow has ranked (https://insights.stackoverflow.com/
survey/2020) the most loved languages. Go is among the top of the top 25 listed well-known
languages, and it ranks higher in that list on the desired (“loved”) scale than Java. Note how
well it compares to Python; this is remarkable for a compiled language.

26
https://en.wikipedia.org/wiki/Object-based_language
27
The Importance of Being Earnest – https://en.wikipedia.org/wiki/TIOBE_index
28
https://github.com/golang/go/wiki/GoUsers
29
www.docker.com/
30
https://kubernetes.io/
31
Originally bootstrapped from a C version of these tools.

xxvii
Introduction

Table 1. Most Loved Languages Survey


Language Loved Percentage (Using and Want
to Continue Using)

Rust 86.1%
TypeScript 67.1%
Python 66.7%
Kotlin 62.9%
Go 62.3%
Julia 62.2%
Dart 62.1%
C# 59.7%
Swift 59.5%
JavaScript 58.3%
SQL 56.6%
Bash/Shell/PowerShell 53.7%
HTML/CSS 53.5%
Scala 53.2%
Haskell 51.7%
R 44.5%
Java 44.1%
C++ 43.4%
Ruby 42.9%
PHP 37.3%
C 33.1%
Assembly 29.4%
Perl 28.6%
Objective-C 23.4%
VBA 19.6%

xxviii
Introduction

All this should make learning to program in Go highly interesting to experienced Java
developers looking to broaden their skills and marketability. In the author’s opinion, Go
will emerge as the go-to language for multi-core computing over networks, especially for
servers.
Of course, for a complete analysis, we need to contrast the mascots of Go and Java.
In the author’s opinion, Go’s mascot is both simpler and cuddlier, as, arguably, is the
language itself.
Figure 2 shows the Go logo and Gopher mascot. 32

Figure 2. Go mascot and logo32

Figure 3 shows the Java mascot (Duke).33

Figure 3. Java mascot33

32
The Go gopher was designed by Renee French. (http://reneefrench.blogspot.com/) and is
licensed under the Creative Commons 3.0 Attributions license.
33
https://wiki.openjdk.java.net/display/duke/Main

xxix
Introduction

Gophers, welcome aboard! In this book, we will briefly explore the concepts behind
Go and why it was created. This overview will be followed by an introduction to Go’s
various features and a look at if/how they differ from Java. Then comes a presentation
of most of the Go language statements and data types. This is followed by a brief look
at some potential future Go enhancements. A capstone example Go program is then
presented to unify the Go experience. Next comes a review of the Go standard libraries
as they compare to similar Java libraries. Finally comes a survey of a subset of the various
Go standard libraries as an introduction to their usage. Deeper and more comprehensive
descriptions are available at the Go site.
More precisely, this book’s content is broken down into three parts with several
chapters within each part.
Some background on Go:

• A brief look at Go vs. Java comparing key features of both languages

• Summary of features Java has that Go does not have

A description of the Go language and its key features with a look at using Go in
practice:

• A brief side-by-side comparison of Go features with Java

• A survey of Go key features

• A more detailed view of important Go characteristics (like Go


keywords, etc.)

• A detailed view of Go data types


• A discussion of Go’s error reporting mechanism

• A broader discussion on Go’s interface data type and how it is applied

• A description of each Go statement

• A more detailed discussion on applying Go data types

• A look at testing Go vs. Java programs

• A brief look at possible future Go enhancements

• A capstone program illustrating many Go and Go library features

xxx
Introduction

An introduction to the Go standard libraries in comparison with Java libraries


combined with a survey of key Go standard libraries:

• A discussion of key Java library packages with similar Go packages.

• A brief side-by-side comparison of commonly used Java methods


with similar Go functions.

• A brief discussion of formatting data values in Go.

• A brief discussion of file input/output in Go.

• This part includes chapters covering compression/decompression,


image processing, input/output, cryptography, relational database
access, network access, and Go runtime access.

• It is intended to bring awareness of the various Go libraries and not a


complete understanding of all the available functions.

• This is the largest part of the book.

In addition, there are five appendixes with supplementary information such as how
to install Go, as well as some summary and reference information.

Note In some of the code examples in this book, long source lines are wrapped
into multiple lines. This wrapping may not be allowed in actual Go source.

The source for the capstone programs, as well as for some of the other listing
samples in this book, is available at the book website: www.github.com/apress/
go-­for-java-­programmers.
Before we dive into Go, let us consider why Go exists. Rob Pike summarized34 the
language and why it was created this way:
The Go programming language was conceived in late 2007 as an answer
to some of the problems we were seeing developing software infrastruc-
ture at Google. The computing landscape today is almost unrelated to
the environment in which the languages being used, mostly C++, Java,
and Python, had been created. The problems introduced by multicore

34
https://talks.golang.org/2012/splash.article

xxxi
Introduction

processors, networked systems, massive computation clusters, and


the web programming model were being worked around rather than
addressed head-on. Moreover, the scale has changed: today's server
programs comprise tens of millions of lines of code, are worked on
by hundreds or even thousands of programmers, and are updated
literally every day. To make matters worse, build times, even on large
compilation clusters, have stretched to many minutes, even hours.

Go was designed and developed to make working in this environment


more productive. Besides its better-known aspects such as built-in concur-
rency and garbage collection, Go's design considerations include rigorous
dependency management, the adaptability of software architecture as sys-
tems grow, and robustness across the boundaries between components.
Go is a compiled, concurrent, garbage-collected, statically typed
language developed at Google. It is an open source project: Google imports
the public repository rather than the other way around.
Go is efficient, scalable, and productive. Some programmers find it fun
to work in; others find it unimaginative, even boring. In this article we will
explain why those are not contradictory positions. Go was designed to
address the problems faced in software development at Google, which led
to a language that is not a breakthrough research language but is nonethe-
less an excellent tool for engineering large software projects.
Wikipedia35 defines Go as follows: “Go is a statically typed, compiled programming
language…. Go is syntactically similar to C, but with memory safety, garbage collection,
structural typing, and CSP-style concurrency.”
Wikipedia36 describes Java as follows:
Java is a class-based, object-oriented programming language …. It is a gen-
eral-purpose programming language intended to let application developers
write once, run anywhere (WORA), meaning that compiled Java code can
run on all platforms that support Java without the need for recompilation.
The syntax of Java is similar to C and C++, but has fewer low-level facilities
than either of them. The Java runtime provides dynamic capabilities (such
as reflection and runtime code modification) that are typically not available
in traditional compiled languages.

35
https://en.wikipedia.org/wiki/Go_(programming_language)
36
https://en.wikipedia.org/wiki/Java_(programming_language)

xxxii
Introduction

These descriptions cover some of the key similarities and differences. In the
author’s opinion, the relative brevity of the Go description reflects the relative
simplicity of Go vs. Java.
Go addresses the needs of modern system and application software development in
cloud environments on modern multi-core machines. In the author’s opinion, it meets
these goals very well. As you explore Go more within these pages, you will see its features
and functions and how they match and support the goals stated earlier. By the time you
finish this book, perhaps you will also agree.
Go was not designed to replace (cover all use cases of ) Java. It is more targeted
toward the use cases of the C (and to some extent C++) language. It is primarily a system
programming language well suited toward implementing servers and tools such as
compilers. Java also supports these types of programs.
One of the reasons Go is popular is it is lightweight relative to many other languages.
Go is arguably more lightweight than Java in many areas. This is one of its most attractive
attributes.
Go’s threading model, provided by goroutines and channels, certainly is lighter
weight. Because it lacks Object-Oriented Programming (OOP) features, its data model
and error processing are also more lightweight. Even more lightweight is the set of
standard libraries. Perhaps most critically, Go’s single executable (vs. a JRE and many
JARs) deployments and resulting fast program launching are most attractive.
Go is also arguably easier to master than Java. The language is simpler and has fewer
constructs to learn. The runtime libraries are, while functional, generally more basic and
approachable.
This is not to say that Go is necessarily better than Java (or the reverse), but that
it is often more approachable and easier to master and use. Both languages and their
runtimes will extend over time; Go is more likely to continue its more approachable style.

xxxiii
Assessments
Divya Khatnar: If one knows Java, they will surely enjoy learning Go using this book. The
author makes sure that each topic uses Java as a baseline to explain Go. Not only does this
book teach you Go, but it also sharpens your understanding about Java.
Charles Stein: As Go becomes a staple language, Java users need a clear guide to help
them make the transition. This book thoroughly covers the basics and exciting applications
of Go from a Java-analogous perspective.
Sharath Hedge: This book covers all the comparisons of Java and Go exhaustively.
Also, it covers important packages provided by Go. As a developer if I want to start a
project in Go, this book will offer ready reckoner for the many questions I have. This book
offers examples for the majority of the cases, which helps a lot.

xxxv
Discovering Diverse Content Through
Random Scribd Documents
other two captains. And now, because I did not take their advice, I have lost
the Dupleix, my ship. Mon Dieu, what an ass I was! Now they will report it
to my owners, and I will never get a ship again."

"What were the names of your friends' ships?"

"The Antonin——"

"The Antonin under Captain Lecoq?"

"Yes. And the La Rochefoucauld?"

"Orderly," I called in German, which the captain did not understand,


"bring up captains numbers five and nine."

While we waited, I invited my mournful guest to have some more


champagne, but he refused and continued holding his head and moaning.

A knock at the door.

"Come in."

And in walked the captains of the Antonin and the La Rochefoucauld.


They had been on board ten and three days respectively.

The captain of the Dupleix gaped.

"Eh, tout la France!" he cried.

Full of ironical enthusiasm, he raised his glass of champagne and


saluted them. Then with joy that he made no effort to conceal, he clasped
the hands of the two captains whose advice he had scorned and who had
encountered the same fate as he. They returned his welcome with a grim
humour.

The presence of these three captains aboard the Seeadler represented a


loss of ten thousand tons of saltpetre destined for French powder mills, and
a saving of hundreds, perhaps thousands of German lives.
* * *

One Sunday morning, we sighted a large British barque and started after
her. She thought we were playfully challenging her to a race, and tried to
run away. I don't know whether we could have caught her in a straight
sailing ship against sailing ship contest; at any rate, our motor gave us the
edge.

A strange feeling came over me as we gained on her and as her lines


became more distinct. It was a sense of sadness and of vague, dimly
dawning recollection. Had I seen that ship before? Was it possible...

"Signal and ask her for her name," I called.

Our signal flag went aloft. The reply came back:

"Pinmore"

Ah, my old Pinmore, on which I had made the longest and most
harrowing voyage of my life. Memories swept over me of those endless
storms and of the disease on board, beri-beri, scurvy. My whole being
seemed to leap back to the days of my youth. Homesickness seized me. I
could not say a word to Leudemann, who stood beside me.

"No use, the ship must be sunk," a harsh inner voice told me.

It was hard for me to sink any sailing vessel, but doubly cruel to have to
sink my old ship. I felt as though she were a kind of mother. No sailor with
any kind of sailor's soul in him will raise a hand against his own ship.

We took her as we had taken the others. When her crew came aboard, I
looked for familiar faces. There were none. The skipper, Captain Mullen,
came up to me with a humorous, seamanly air.

"Well, Captain, our hard luck is your good luck."

"Lucky?" I felt like saying. "Do you call this lucky?"


He was a typical old seaman, afraid neither of enemy in war nor storms
at sea. The seven seas had been his home. Like the sailing ship, the old-time
windjammer captain is vanishing. Captain Mullen was indeed like the king
of a vanishing race. He swaggered down below, and saluted our other
skippers with a jovial air. He soon became the leading figure of the
"Captains' Club."

When everyone had left the Pinmore, I had a boat take me over to her. I
clambered aboard and sent the boat and its crew back, telling them I would
give them a hail when I wanted them again.

"Why does the Count want to remain alone aboard her?" I heard one of
them say.

I went to the fo'c'sle. There was my bunk, the same old bunk where I
had slept night after night for months and had tumbled out countless times
at the command "all hands on deck" while those endless storms bore down
upon us. I paced the planks on deck where I had stood watch so often. It
seemed as though I had never seen that deck save in a storm. Those gales
had left so deep an imprint on my memory that it gave me a sense of
strangeness to see the sun shining on the Pinmore's planks and a slowly
heaving sea around.

I remembered a cunning little cat I had once owned on board her. The
captain's wife wanted it. The steward got it for her. I told the steward that if
he did not bring it back to me I would go to the captain. The steward
laughed at me. I determined to complain to the captain about the steward
and his wife and demand my cat back. I could see myself as I had
wrathfully strode along the deck to the cabin. The sight of the door made
me stop. I mustered up my courage and advanced again. I ventured just far
enough to peep in at the door, which was ajar. The skipper was sitting there
reading a paper. One glimpse of the master, and all of Phelax Luedige's
bravery oozed away. He turned and tiptoed away. I never did get my cat
back, and forever after held a grudge against the steward.

I could still feel the old enmity. If I could have found that steward, I
would have let him know how the end of a rope felt. I went to the cabin and
half opened the door. It was much as when I had seen it last. The bright
rainbow glow of the coloured skylight gave me an old familiar feeling.
Something restrained me from entering. I did not dare go in then. I would
not now.

At the stern I looked for my name which I had once carved on the rail. I
found it, half effaced by time and weather. I read it slowly, spelling it out as
a child spells its first lessons: P-H-E-L-A-X L-U-E-D-I-G-E. I looked at the
compass, beside which I had watched for hours. The compass is a sacred
place to a sailor.

"This ship," I thought, "carried me safely. The storms were wild all the
way from 'Frisco around the Horn to Liverpool. They wanted to take us,
every man aboard, but the good old Pinmore fought against wind and wave
over leagues and leagues of dreary waste and brought us safely to port. Yes,
she was our mother, our kindly protecting mother."

The deserted ship with an unguided helm rolled back and forth. The
rigging creaked and groaned. It seemed to be a voice, a voice that hurt me.
Every spar seemed to say:

"So here you are, Phelax, back again. Where have you been all these
years? Where is all the crew? What do you want here, alone? What are you
going to do with me?"

Little had I dreamed when I was a sailor on this fine barque that one day
I would walk her decks again, not as a seaman, but as the commander of a
raider.

Returning to the Seeadler, I shut myself up in my cabin. In the distance


I heard the roar of a bomb, and I knew that my old Pinmore had started on
her last cruise.
XVIII

THE LIFE OF A MODERN BUCCANEER

Ever taken a trip at sea where the company aboard was dull and dead,
the passengers uncongenial to one another, and everybody sitting around
day after day and bored to death? You have? Well, then, you know what it's
like, eh?

Give me a lively, companionable crowd of shipmates, and I don't care


how long or how stormy the cruise. On land, if you don't like the company,
you can seek better mates elsewhere. On shipboard, do your darnedest and
you can't get away from 'em. You have to take your company just exactly as
you find it. You are married to it. A genial lot of shipmates and a long
cruise, say from New York to Melbourne, and what more can any man ask
for at sea?

Although our old jolly-boat was a raiding auxiliary cruiser, she also
degenerated into a breed of passenger ship, too. Our passengers were our
prisoners. That made the situation somewhat unusual and added a bit of
spice. I've served as an officer aboard a dozen or more liners, and have seen
all kinds and strata of society aboard, including dull, delightful, ill-natured,
jovial—both the quick and the dead. Yes, I have had some splendid
passenger lists on voyages where every hour was gay and bubbling with
fun. But no group of passengers on a liner ever enjoyed such happy
comradeship as did we aboard our buccaneering craft. The fact that we were
captors and captives only seemed to make it all the jollier. We took the
greatest pleasure in making the time agreeable for our prisoners, with
games, concerts, cards, and story-telling. We tried to feed them well, and I
think we did, which helps a lot, as you'll agree. We didn't throw it at them
either. In fact, we served special meals for all the nations whose ships we
captured. One day our own German chef cooked, and that boy was some
cook, as you say. The next day an English cookie, then the French chef,
then the Italian to make us some polenta. The English food was the worst. It
usually is. On the other hand, the Americans fed their sailors best of all. It's
long been a tradition on Yankee clippers. In the old days, the American
sailing ships were famous for frightful work and much brutality, but the
food was good. To-day the work is not bad and there is no brutality, but the
food is still good.

The prisoners seemed to appreciate our intentions thoroughly. They


wanted to do everything they could for us in return. Feelings of patriotism
should have made them hope for our early destruction. But more elemental
sentiments of gratitude and friendship obliterated the more artificial
passions of war hatred. I am sure that very few of our passengers wished us
any ill or gloated in the hope of our being sunk by the cruisers of their
nations. I think it really hurt many of them to realize that the day probably
would come when we would be caught and go down under a rain of Allied
shellfire. That magnificent Frenchman, the captain of the Charles Gounod,
kept aloof from the general fraternizing, and scrupulously kept up his
manner of cold politeness and stately hostility toward us, but even he
thawed out a few degrees, although he tried hard to keep from showing it.

There was only one of our prisoners who behaved himself in any way
that could be considered improper. That was Captain Lecoq of the La
Rochefoucauld, that same Captain Lecoq who had cherished hopes that we
would run afoul of the British cruiser. You see, the skippers aboard were
quite free to go where they liked on the ship, except that I asked each one,
as he came aboard, not to go into the fore part of the ship, and I explained
why.

"My magazines," I said, "are in the forward half of the boat. I do not
want you to know exactly where they are placed. After you are released,
you might reveal the secret. Then, one of these merry days, if some cruiser
takes a shot at me, and if the location of my magazines is known, they'll aim
right at that spot. A shell there and up in the air we go. I must ask you to
give me your word of honour that you will not go into the foreship, else I
will have to keep you confined."

Each skipper gave me his word, including Lecoq.

Captain Lecoq broke his promise. He not only went secretly into the
foreship, but he made sketches of the layout there. Captain Mullen of the
Pinmore saw the sketches, knocked Lecoq down, and reported him to me. I
berated Lecoq soundly.

"And as a result of your dishonourable action," I said, "when I release


my prisoners and send them off to some port, there will be one Frenchman
who will remain behind, and that Frenchman will be you. You will continue
your cruise with us. You know where my magazines are, and I cannot trust
any promise that you now give me."

He turned a bit green around the gills at that, but there was nothing he
could say in reply.

Our only woman aboard, the skipper's little bride, grew melancholy. We
did everything we could to make the time pleasant for her, but she pined for
the society of other women. It was rather a trial for her to be so long the
only woman among several hundred men.

"Count, I do so wish there were a woman aboard that I could talk to,"
she said to me a bit coaxingly one day. "Why don't you catch me one?"

I always like to oblige a lady, particularly one so charming and


agreeable as she, but catching another woman was a game of chance with
us. You don't often find fair company aboard freighters, especially in
tropical waters. However, I said:

"Madam, we will do our best."

At times I used to amuse myself by joining the crowd on the lookout in


the rigging. It was a misty day, and nobody had much of a chance of seeing
anything. Then it cleared a little in the west, and Boarding Officer Preiss,
who was beside me, thought he saw a ship. I instructed the helmsman to
steer in than direction, and after fifteen minutes a large British barque
appeared through the mist. As we drew near her, I saw a white figure on the
deck. Sure enough, a woman.

"Madam," I shouted, to the Canadian skipper's bride, "get ready to


welcome your companion. She'll be paying you a call in a few minutes."
Everybody, prisoners and all, swarmed on deck to witness the
exceptional capture. The Seeadler bore down on the unlucky barque.

The captain looked curiously at the crowded figures standing at our rail,
of every colour and race. They waved gaily. Our gramophone blared out,
"It's a Long Way to Tipperary."

"Hello," he shouted through his megaphone, "collecting volunteers?"

He thought we were picking up war volunteers from the Atlantic


islands.

"Volunteers?" I called in return. "Oh, yes."

Our prisoners laughed a bit.

"Any news of the war?" he asked.

Officers and sailors and the woman on his deck craned their necks for a
reply.

"Much news of the war," I responded. "I will signal it."

They stared, awaiting the signal.

"C-I-D," our signal flags went up; "heave to or I will fire."

I could see the captain rapidly thumbing the pages of his book. His head
jerked up suddenly. His binoculars focussed themselves on our masthead
where the German flag now waved. Our gun mask dropped, and the cannon
peered forth. By Joe, but it raised a commotion on the deck. When she saw
it, the woman darted into her cabin. The sailors ran to the boats. Even the
helmsman deserted the wheel. The captain was the only one who kept his
head. He seized the helm with a firm hand, and the ship hove to.

Our guests were always interested in the prospect of having new


additions to their company. They had an ever-ready, cordial welcome for
fresh arrivals. This time, the coming of a second feminine passenger made
the occasion a gala one. Everybody put on his best manners. The members
of our "Captains' Club" marshalled their forces on deck, ready to greet the
officers and the lady from the captured craft with suitable dignity and
formality.

Our little woman put on her best clothes and asked me for a nosegay
from a supply of artificial flowers we had captured. The newly arriving
woman, who scarcely knew what to expect aboard our dreadful pirate craft,
was surprised when she was greeted not only by our Captains' Club with all
of its stately courtesies, but also by a brightly smiling young woman who
presented her with a bouquet of flowers that made up in brightness of
colour what it lacked in sweetness of perfume, since they were imitation
ones.

The two women immediately became the best of friends, and the
convivial spirit aboard made our happiness complete.

The captured barque, the British Yeoman, carried a rare store of


provisions, including some live pigs and chickens. She also had two pets, a
curious pair—a rabbit and a pigeon. We promptly adopted them and called
the pigeon "the dove of peace" in honour of the spirit aboard our raiding
ark. That rabbit and pigeon were inseparable. If the rabbit strayed, the
pigeon would coo and coo for it to come back, and the rabbit would
obediently respond.

Then we also had two dachshunds aboard, Piperle and Schnaeuzchen.


Piperle was a friendly little rascal and most intelligent. He seemed to
understand what our work was, and grew most enthusiastic. He went out
with the boarding parties, barked furiously if anything seemed to go wrong,
and wagged his tail with a tremendous enthusiasm when things turned out
all right. He seemed to take it as his especial task to give a friendly
welcome to prisoners brought aboard. He would bark and leap upon them,
as though saying:

"Hello, you'll have a good time here."

Schnaeuzchen was an ill-natured specimen of dachs bitch. She looked


on satirically at Piperle's demonstrations, and people had to make many
amicable overtures before she became friendly. She and Piperle were of
discordant temperaments. They got along together in a resigned sort of way,
with many a quarrel in dog language, something like husband and wife. I
think she nagged him a lot.

We gave the rabbit and pigeon quarters in Piperle's kennel, which


delighted the good-natured dog. He welcomed his guests with cordial
demonstrations. He licked the rabbit's fur continually, which at first made
the pigeon jealous. The bird sulked and made angry sounds. The
unfortunate rabbit seemed in a quandary, torn between his liking for the
new friend and the old. He must have been a diplomat, though, for presently
he found a way to reconcile the pigeon to his fondness for Piperle, and the
three became excellent friends. When the three were asleep in the kennel,
they made an edifying picture of harmony, Piperle on his side, the rabbit
huddled against his belly, the pigeon perched on his side.

Schnaeuzchen, malign and crafty, watched this beautiful friendship with


a jaundiced eye. She was the villain of the piece. She often made attempts
to devour the rabbit or the pigeon or both, or at least to take a bite out of
them. She was quick and cunning with her snapping jaws and sharp teeth. I
spent a great deal of time trying to convince her that she had better leave the
three pals alone, and Piperle had to be on the alert all the time to protect his
two friends. One night Schnaeuzchen, with bold and bloody resolve, raided
Piperle's kennel. I suppose she reasoned that she had better end the
obnoxious situation with one fell blow. She got in before Piperle knew what
had happened, and the rabbit barely escaped her jaws. Piperle turned on her
and chastised her properly. After that she resigned herself to the inevitable.
She kept the peace with the other pets, and while she never became really
friendly with them, the pigeon and rabbit were at least safe.

Talking about animals brings to mind one remarkable piece of good


fortune that blessed our entire adventure. Before it was over, we were
destined to suffer pretty nearly all the hardships that the sea can bestow
upon the sailor—arctic ice and tropical sun, storm and calm, frightful labour
and deadening idleness, shipwreck, life as castaways on a desert island, the
terrors of weeks in an open boat, hunger, thirst, and scurvy. But we never
had any bedbugs. I had had enough experience with those vermin in my
early days before the mast. I was determined to have none of them now.
Bedbugs are a constant pest aboard sailing ships, and doubtless some of the
vessels we captured had plenty of them. But aboard the Seeadler we had a
magnificent fumigating plant, and every article that was brought aboard was
given a thorough treatment. That fumigator was one of our most treasured
possessions. Without it, we would surely have been in a fix. We could not
have put comfortably into a port and called for the vermin exterminator, and
if we had taken aboard any bedbug guests, our long voyage would have
given them plenty of time to multiply and overrun our ark. We would have
been eaten alive.

I remember a time during my jack-tar days when we had a magnificent


collection of bedbugs in the forecastle. A comrade and I went to the captain,
a mean old German skipper, and told him we were being eaten alive and
begged him to go to the slight expense of getting a vermin exterminator.

"Bedbugs," he grunted, "Gott im Himmel, catch them."

We did catch them. We caught a match box full of them, and put them in
his bunk.

The next day the vermin exterminator came aboard.

XIX

HOW WE MADE OUR PRISONERS WALK THE


PLANK

Our floating hotel was about full. If we wanted to take any more guests
aboard, we would have to get rid of our present company. The old pirates
would have had a plank-walking ceremony. That was a sure way to prevent
inconvenient information from getting around. Undoubtedly, it would have
enabled us to keep our existence still secret. We were buccaneers in a sense,
but not quite that bad. We would have to take other measures. When our
prisoners got to port and our freebooting career became known, cruisers, of
course, would set out after us. They would make the narrow Atlantic much
too hot for us. We would have to seek other waters. The broad Pacific
remained. We did not want to hold our prisoners for the always rough
passage of Cape Horn, where, in addition, there were likely to be cruisers
on watch, keeping a guard for suspicious ships that might be trying to take
the shortest route from European waters to the Pacific. We might be shelled
and sunk, but it would have been scarcely humane to take a chance of going
down with all our prisoners on board. So we arranged it in a way that would
enable us to get a good start on our trip around Cape Horn before the
cruisers could get word of us.

The French barque, the Cambronne, came along. You should have seen
her heave to and her yards come banging down when our German flag went
up and we signalled the inevitable: "Stop or I shall fire."

Her captain exhibited all of the usual Gallic despair at the prospect of
losing his ship. We looked the craft over. She was large and roomy and had
aboard a large stock of provisions.

"No," I said to her skipper, "we are not going to sink your ship. She will
go right on to port."

"Eh?" He was immensely surprised.

"She will take our prisoners."

"I will be delighted, monsieur, to have them as my guests."

"They won't be your guests, Captain. You will be the guest of the new
captain of the Cambronne."

"I will not command my ship?"

"Not at all. I have a Captains' Club aboard. You, as a prisoner, are now a
charter member. Your ship is my prize. I will select a member of the
Captains' Club as her skipper."
He was very angry. It hurt him nearly as much to be removed from the
command of his ship as to have her sunk.

It was a touchy matter to select a skipper from among a dozen captains,


each of whom was full of sensitive dignity and thought he was the best
navigator of the lot. The French captains thought a Frenchman should be
selected, since the most numerous nationality among the prisoners was the
French. The traditional principle of seniority, however, pointed to the
selection of the oldest skipper. My belief in that principle was confirmed by
the fact that the oldest skipper was Captain Mullen of the Pinmore. He had
shown himself to be the finest of gentlemen, and then there was the
memory of my old ship, which I had been compelled to sink. I appointed
Captain Mullen master of the Cambronne. Since he was a Britisher, it was
reasonable that his ship should sail under British colours. That necessitated
the ceremony of hauling down the French flag and hoisting the Union Jack.
The French captains did not like it at all.

I was rather glad that it was not I who would command the Cambronne.
With all those captains aboard, especially the disgruntled French captains,
the skipper of the Cambronne was certain to have an uncomfortable time.
One skipper always knows more than any other skipper. Nor is any skipper
ever reticent about the mistakes of another. The skipper of the Cambronne
had better navigate with a perfect correctness, or there would be plenty of
talk aboard.

We lopped off the Cambronne's upper masts, so that she could set only
her lower sails. She could not make any speed now, and it would take her
from ten to fourteen days to get to Rio de Janeiro, which was the nearest
port. Then I exacted a pledge from Captain Mullen:

"Captain," said I, "we are releasing our prisoners, and they are under
your command. I understand perfectly well that when you get to port our
existence will be known. We will be a sailing ship in a world of armoured
cruisers. We will be chased like a wild deer. We need a start. We have taken
care that you do not get to port too soon. One thing remains, though. You
may meet a ship within a week or within a day—it may be a steamer with a
wireless plant. I ask for your word that you will not communicate with any
ship until you reach port. We have, I hope, treated our prisoners fairly, and I
ask this of you in return. I must have your solemn word on it."

"Count," he replied, "I give you my word that the Cambronne will not
communicate with any ship until she is in port at Rio."

We shook hands on it, and my mind was at rest. It was no risk to take
the word of the Pinmore's old skipper.

He played his part nobly. He passed several steamers on his way to Rio,
but steered clear of them. One comical thing happened. A big steamer came
toward the Cambronne one morning, and then her captain noticed the crowd
of prisoners on the ship's deck. He was a cautious soul. It looked suspicious.
The steamer turned and fled at full speed.

There remained the case of Captain Lecoq of the La Rochefoucauld,


who had broken his word to me and whom I had promised not to release
with the other prisoners. He tried to dissuade me. He was aghast at the
thought of being kept aboard the Seeadler throughout her long cruise, the
end of which no one could foretell. He vowed by all the saints that he
would keep the position of the ship's magazines locked sternly within his
bosom. I would not listen to him. I told him that the others would go but he
would remain. I intended to hold him until we had caught and released our
next batch of prisoners. He enlisted the other captains to intercede in his
behalf. They came and asked me to relent.

"Gentlemen," I replied, "I have just now rested the safety of my ship on
Captain Mullen's word. You are all ship masters. You know a captain's duty
to the vessel he commands. Very well, I know that Captain Mullen's word is
good. I have taken the others of you at your word, and you have not failed
me. But Captain Lecoq broke his word. Can I trust him not to break it
again?"

They argued so hard for their unfortunate fellow skipper that I finally
gave in. After all, even if he did break his word again and tell of the
position of my magazines, it did not necessarily mean disaster. I made him
sign a promise and made the other captains sign as witnesses to his promise.
Then I gave orders that he should go with the rest.
We paid our prisoners off, just as if they had been working for us. Each
received wages for the time he had spent aboard, and each was paid the
wage he ordinarily received from his shipowner. By Joe, that made them
happy. We had a final banquet. The sailors feasted in their quarters. I
entertained the officers and ladies in my cabin. Toasts of champagne were
drunk, and at the end there were cordial handshakes. We transferred the
crowd to the Cambronne in boatloads, and each boat, as it pushed off, gave
three cheers for the Seeadler.

Evening was coming on. The Seeadler lay watching while the
Cambronne raised sail. Now the stately barque was sliding through the
water. Hands waved and farewells were shouted. The two ships saluted each
other. With her snow-white canvas bellied out by the brisk wind, the
Cambronne sailed toward the horizon. Aboard the buccaneer, we watched
till the last tip of her mast disappeared below the skyline.

We had been away from port for eight weeks and had sunk eleven
vessels, representing a total of more than forty thousand tons of Allied
shipping. The Atlantic had given us its share. Now to the Pacific. And God
save us from the cruisers.

XX

THE BATTLE OF THE FALKLAND ISLANDS

Through an oily sea we sailed south and west toward the Falkland
Islands. Many a time had I passed this way in the old days when bound for
Cape Horn. These islands of the South Atlantic have long been the base for
whaling schooners. But to every German the Falklands will be forever
memorable as the scene of a one-sided naval engagement in which one of
our best beloved admirals was overwhelmed by a British fleet.
Had you seen our deck as we sailed south during these days, you might
have wondered what we were about. Along with other plunder, we had
looted captured ships of several great sheets of iron. We had ripped them
from iron walls and roofs of forecastles and stowed them on our deck. Now
the mechanics of the Seeadler's motor crew got busy with acetylene
torches, and from those sheets of metal they welded a great iron cross, ten
feet high.

We drew near a spot on that lonely ocean just a bit to the east of the
Falkland Islands. My navigation officer and I figured out the point carefully
on our chart, and when our instruments told us we were there, I called all
hands on deck. Somewhere far below on the floor of the ocean were the
bodies of hundreds of our comrades and the battered hulks of a once proud
German fleet. It was in these very waters that our gallant Pacific Squadron
under Count von Spee sank in three thousand fathoms. For here it was that
our light cruisers, the Scharnhorst, Gneisenau, Nuremburg, and Leipsic,
with odds against them, fought it out with a more powerful British
squadron.

With flag at half mast, we stood at solemn attention. The sky was gray
and melancholy. The sea rolled with a gentle swell. In our mind's eye we
could picture that disastrous day when, outranged by the guns of the great
British warships, our cruisers, two large and three small, had fought a losing
and hopeless fight. One, a scout cruiser, escaped. The others went down.
Pounded from the distance, they trembled under the blows of the shells that
rained down upon them. Exploding projectiles raked the decks and pierced
the hulls of the ill-fated vessels. As if in a last struggle, trying to keep afloat
for one more shot at the enemy, they staggered, lurched, and then, one after
the other, plunged into the depths, entering port on their final voyage far
below on the ocean floor, eighteen thousand feet beneath the surface. Every
man aboard three of the ships was lost. A high sea happened to be running
at the time, so the victors had little chance to rescue the men from the
doomed ships. Two hundred and fifty members of the crew of the
Gneisenau were picked up and got to the Falklands alive.

As if in a dream, I thought of the last time I saw my friend Count von


Spee. It was in the days before the world went mad. The Navy Yard at Kiel
was in gala mood. Every warship in the harbour had sent three hundred
men. They stood at rigid attention while Von Spee and his staff strode by.
Then he addressed them.

"By order of the Emperor, I am to take command of our cruisers in


Chinese waters. My officers and men sail with me to-morrow."

The sailors all give three cheers. They think the Admiral and his men
are merely going for a pleasant vacation to the Orient. It is in 1913. No war
is in sight. Yet a darker note intrudes: Even then military and naval men
were unable to escape the thought of war:

"We are leaving home and country for two years. We who part from you
to-morrow will do our duty, knowing that every man at home will do his. If
war should come, we will be across the world and you will be here. We will
be too far away to lend a hand to you, and there is little that you will be able
to do for us.

"Ours is a young navy, but we have had a great teacher. When England
built her mighty fleet, she taught us how to build ours. The English have
great naval traditions, and both their fleet and traditions have been our
model. If war should come before we meet again, we along the far-off
China coast may be but a few ships against many enemies, but from you of
the High Sea Fleet we expect great deeds."

We of the German Navy knew and constantly gave expression to the


thought that Britain was our guide on the sea. Her great seafaring tradition
was our conscious and admitted pattern. We German naval men liked the
English and were in sympathy with them. Our navies were alike in spirit.
The French Navy was somewhat different. Its morale was perhaps not so
good. French naval officers all come up from the ranks. The British and
German come from cadet schools and are recruited mostly from the first
families. That is best. It provides a finer corps of officers. I, myself, came
up from the forecastle, but I believe that, unless you have officers and men
from different worlds, your men will have little respect for their
commanders. It must either be that, or your officers must inspire respect
with their fists as in the old sailing-ship days. The French Navy no longer
has a rich tradition. It is true that the French had far greater sea fighters than
we in past centuries, and they had their fine old naval traditions. But during
the Revolution the old Royal Navy of France was swept away and remained
abolished for twenty years. At the end of that time, a new navy was formed,
but by then the fine old French traditions seem to have been forgotten and
new traditions had to be formed. We Germans, with a new fleet, took over
the old, solid tradition of the British and made it our own. We did
everything we could to implant it in our men, and make it a real, living
thing ingrained in our people. Our sea leaders understood the importance of
a tradition. That was why we were determined to keep a fleet after the war.
When our great ships went down at Scapa Flow, our Socialists favoured the
total abandonment of the naval arm, but fortunately enough of our people
came out of their post-war trance long enough to prevent such a fatal error.
Perhaps it might be only a few small ships that we could retain, but it would
serve to keep traditions alive until we could again build up a fleet as great
or even greater than the one we lost.

Von Spee was a sailor's admiral. He was a seaman by temperament,


open, honest, and jovial, uncomfortable on land and only himself when on
the bridge of his flagship. Too many of our professional fighting men, I
regret to say, were more ornamental than useful. They were good at wearing
gold lace and that is about all. But not Von Spee. He was at his best on a
quarter-deck in a storm. I still can see him pacing back and forth, with his
bushy brows and piercing blue eyes.

The day after he said auf wiedersehen to us at Kiel, he and his officers
and men left by transport for the Orient, there to relieve the officers and
men aboard the cruisers of our small Pacific Squadron at Tsing Tao. What
was to have been their two-year term overseas began as commonplace,
quiet routine. It ended under the salvos of British guns off the Falkland
Islands.

Von Spee's plan, when the war caught him 15,000 miles from German
waters, was to harass the Allies in the Pacific and then try to slip back
through the North Sea to Kiel. Lady Luck smiled on him for a little while
and then deserted him. After crossing the Pacific, he caught Craddock, the
British admiral, off the coast of Chile. Von Spee's star was in its ascendancy
at this time and Craddock's on the wane. A German secret agent in Chile
flashed a wireless to Von Spee giving him the information that Craddock
was waiting for the arrival of the big but old battleship Canopus that was
rounding the Horn. Without the Canopus, Craddock's forces were weaker
than Von Spee's, and Von Spee instantly dashed to the attack so as to engage
Craddock before the Canopus came up. Craddock and his men met their
fate like true British sailors. Outgunned, the British cruisers continued to
fire until they sank. Only one, a small boat, got away. But their conqueror's
days were numbered.

Von Spee now began his long race toward Kiel. Only two routes were
possible, one by Cape Horn and the other by the Cape of Good Hope. Of
course, he knew the British would be laying for him at both places. He
knew also that they would be after him with swifter and more powerful
ships than his own. His one chance was to beat them to Cape Horn, lose
himself in the broad Atlantic, make a run for it, and probably fight his way
through the blockade.

By now he was short of both munitions and coal. A wireless from


Germany brought the good news that a supply ship had slipped through the
blockade and was now on its way out to meet him. What a tremendous
voyage he might now have made! What a hair-raising dash at the Allied
blockade line he might have made! But he never got the chance.

As he rounded the Horn, Dame Fortune tempted him, and he made what
proved to be a fatal error. He stopped a British collier and took all her coal.
This delayed him for three days. Meanwhile, a fleet of Britain's mightiest
battle cruisers had arrived at the Falklands. He still might have run by them
unnoticed had he not determined to shell and destroy the wireless station on
the Falklands. Thus he stumbled into that nest of battle cruisers. He tried to
run, but they caught and sank him. That day the British had their sea giants,
the Indefatigable, the Invincible, the Indomitable, and along with them a
number of other battle cruisers, that later were to fight gallantly at Jutland,
and then find their way to rest on the floor of the North Sea.

Only one of Von Spee's ships, the light but fleet cruiser Dresden,
showed her heels to the British leviathans and slipped back around Cape
Horn, But the Fates were merely playing with the poor Dresden, and a few
days later she was sunk by the more powerful British cruiser Kent off San
Juan Fernandez, Robinson Crusoe's island, in the Pacific. She was lying in
neutral waters and should have been sheltered by the laws of war. Her
captain signalled to the commander of the Kent:

"We are in Chilean territory."

"My orders are to sink you on sight," replied the Kent, "and no matter
where you are."

The captain of the Dresden blew up his ship, and with his officers and
crew swam ashore. The island was not quite so deserted after this shipwreck
as it was in Robinson Crusoe's day!

That in brief was the story of the plucky Von Spee and his gallant men.
Hence this dreary waste of waters off the Falklands was sacred to us. We
hove to, and from my quarter-deck I presided over a brief memorial service
above the watery graves of our comrades and their ships. First I told my
boys the story of my friend Count von Spee and his men, and every one of
us knew that we, too, might soon be on our way to join them. But with the
difference that we might not even have a chance to fight it out.

On German ships, the captain is also the chaplain. Every Sunday aboard
the Seeadler we had our hour of prayer and song. When we had "guests"
aboard from enemy ships, we invited them to join with us in the worship of
the Great Ruler of the Waves. Our service followed the ritual of no
particular creed. It was as simple as we simple seamen could make it. The
table which bore the ship's Bible was draped not only with our German flag
but also with the flags of all the Allied nations whose ships we had captured
and under whose colours our prisoners had sailed. I wanted to make our
prisoners feel that the service was as much theirs as it was ours, and that we
did not feel ourselves any more a chosen people before the Altar of God
than any other people.

My life has not been altogether a pious one. On the contrary, it had been
decidedly blasphemous. My character was then, and still is, far from saintly.
However, I may not have been wholly unfit for the office of ship's chaplain.
I am religious at heart, easily swayed by sentimental appeal. Had I not been
a member of the Salvation Army in Australia? Those testimonial meetings
in Fremantle were still vivid memories to me. So I was not exactly a
greenhorn at conducting a prayer meeting.

Before concluding our little memorial service, I addressed our comrades


three thousand fathoms below us. No mounds were raised over their graves,
no green grass or kindly flowers had been placed to cheer them on their
journey to the land from which no traveller has yet returned. Only the
waves of the sea. I spoke to them as though my voice could somehow find
its way to their resting place among the mountain ranges at the bottom of
the South Atlantic:

"Glorious fallen comrades, we bring you a message from home. Your


comrades have kept their promise to your commander. On sea and on land
they are fighting for the Fatherland. We of the Seeadler salute you and
solemnly swear that we, too, will endeavour to live and die as gloriously as
you. We, too, are hunted on the sea, even as you were. So perhaps it will not
be long ere we join you down there in Davy Jones's Locker. If we do, our
one hope is that we will be able to fight our last fight as gallantly as did
you."

I then led the sailors in a prayer that we repeated aloud, and while the
chorused invocation travelled southward on the winds that blew toward the
Antarctic, four men came forward bearing the great iron cross.

"A decoration for the graves of heroes!"

At this signal from me the massive emblem slid into the water with
scarcely a splash and flashed swiftly down, down, three thousand fathoms,
to carry our message to Admiral Count von Spee and his men.

XXI

RACING THE ENEMY AROUND CAPE HORN


"Ahoy, shipmate," I said to Leudemann, "you are the fellow who likes
yacht racing. By Joe, it's to be a race now—a race to see who gets to Cape
Horn first."

We knew that, as soon as our former prisoners made port, the news of
our presence in the South Atlantic would be flashed abroad. Then the
British would send their cruisers on the double-quick down the coast of
South America to keep us from doubling the Cape. To be sure, we had taken
care to give ourselves a mighty good start. But in a race of windjammer
against swift cruisers, what is a start of a thousand miles or so? With decent
weather, we had hopes of making it. So far we had had fair winds and had
made good time. But the most difficult stretch of sea in all the world now
lay before us. The storms for which the Horn is famous often delay sailing
ships for weeks.

"And then," responded Leudemann, "even if we do get to the Cape


before any cruisers that may be sent down from the North, they may have a
cruiser or two nosing around at the Pacific end of the Straits. Unless we
round the Horn before those chaps reach Rio, the jig may be up."

Just south of the Falklands, we caught a wireless from a British cruiser,


a warning message to Allied merchantmen.

Steer clear of Fernando Noronha. German cruiser Moewe reported there.

"Moewe" means "sea gull" in German. "Hail to you, far-distant Sea


Gull, may you fare as well on your warlike flight as we hope to fare in our
Sea Eagle!"

A feeling of homesickness for the old Moewe came over me, as it does
over any sailor at the mention of a ship on which he has sailed. My service
aboard the Moewe had been neither long nor eventful, but already she had
made for herself a heroic reputation. I have always regretted that I was not
with her on her raids. She made several, slipping out through the blockade,
sinking quantities of Allied shipping, and stealing back into German waters.

She was built just before the war, and originally designed to carry the
exotic banana from Southwest Africa and "German East" to Hamburg.
Plans had just been made to flood Germany with them. Her sister ship in the
banana trade was the Wolf, and she, too, became a famous raider.

All manner of ingenious devices were invented in fitting out the Moewe
for her career as a raider. She was altered so that she could disguise herself
and change disguises while steaming at full speed just like a quick-change
actor. One day she would be a three or two funnelled steamer, the next she
would look like a slow tramp with one funnel. The line of her deck could be
changed in a few minutes also. She also had fake superstructures that could
be raised or lowered at will. She could even be made longer or shorter in a
few moments by means of a fake section that slipped out from her stern.
One day she would be a tramp, the next, with fake bulls'-eyes, a liner. These
startling metamorphoses were a great success and enabled her to dodge
many an Allied cruiser.

Of course, the British soon got on to the Moewe's quick-change habits,


and were not to be fooled by them. On one of her adventures, the Moewe
was trapped off the eastern coast of South America. The British cruisers
Glasgow and Amethyst were warned by wireless that the Moewe was
steering south from Fernando Noronha to take coal. So they rushed out
from Rio de Janeiro to trap her. Presently, the Glasgow spotted the Moewe
on the horizon. The German ship had on one of her innumerable disguises,
and the captain of the Glasgow could not recognize her. He was wary,
however, and on to the Moewe's tricks, so he wirelessed her to stand by to
be searched. The Moewe turned and ran south. The Glasgow could make
twenty-five knots and easily outrace her. The Moewe was well armed with
guns and torpedoes and would fight, but she would be no match for an
armoured ship. The men aboard the Moewe seemed as good as at the bottom
of the sea. The Glasgow knew that the fleeing ship must be the long-sought-
for raider, and prepared to sink her.

The two ships steamed with straining boilers, and the Glasgow was fast
creeping up on the Moewe. When almost within range, the hunted raider ran
into one of those sudden rain squalls that sweep over the ocean. Like the
Biblical cloud, it hid her from the pursuing cruiser. Of course, the Glasgow
followed her into the squall. But as the Moewe ran through the swirling
storm, she passed another steamer, this one steaming north. The cruiser saw
emerging from the squall this new ship. She had three masts. The Moewe
had had but two. The captain of the Glasgow thought only of the Moewe's
ability to disguise herself. He presumed that the Moewe had taken
advantage of the squall to run up a third mast and then double back on her
trail in the hope that the Englishman would not recognize her and that she
might pass safely and even have an opportunity to torpedo the Glasgow.
The cruiser instantly opened fire, and blew the poor, inoffensive cargo
steamer out of the water. It was only when they examined the wreckage that
they discovered that they had made a mistake and sunk a British freighter!
Meanwhile, the Moewe had escaped once more.

Nor was that the only ship the British sank by mistake. They shelled two
harmless sailing vessels to pieces, mistaking them for our Seeadler. It all
came about because of one of those familiar war rumours, a rumour to the
effect that we were already somewhere off the Australian coast. An
Australian cruiser encountered a Scandinavian three-master, and they
seemed to think she was behaving queerly. Word had been passed around
that the Seeadler carried torpedoes. So the cruiser thought she had better not
run any chance of being blown up. She opened fire at long range. Only ten
men aboard the Scandinavian ship were saved. Later on, the armoured
cruiser Kent[1] sank another sailing vessel under similar circumstances in
the Pacific.

[1] See Note B, Appendix.

Sailors since Magellan, by Joe, have talked about the storms around
Cape Horn. Sea stories usually have something about the tough times
rounding the Cape. I had seen those storms myself when I had sailed in the
forecastle, and as a naval officer I had many a time told tales to my brother
officers of gales and tempests I had witnessed in an old windjammer
rounding Horn. But our trip this voyage was to be the most unusual of all. If
the storms held us back, the cruisers would be almost certain to catch us.
We had sailed south in fine time, and if we made a quick passage round that
boisterous tip of South America, we might slip into the wide Pacific and
continue our raids.

Well, we ran into the dirtiest weather off the Horn, gales and hurricanes.
Why, there were days when even with our motor running we could make no
headway at all. It took us three weeks to beat our way through the gales and
around the point. By that time, the cruisers lay there in wait for us, not just
one or two, but a whole half dozen of them.

Ordinarily, a sailing ship tries to hug Cape Horn as closely as it can,


keeping quite near land. If you veer too far to the south, you run into
icebergs. Navigating among icebergs with the wind whistling through your
rigging is enough to give any skipper the chills. So the storms had held us
up, and now our best chance probably would be to steer as wide a course to
the south as possible, whether safe or not. The mountains of ice were there,
and a hurricane was blowing. But we considered the ice the lesser of two
evils. The British watch to the far south was bound to be less vigilant than
up nearer the Cape. We must try to sail around them. So, ho for the
Antarctic!

On our way through the blockade, we had steered into the Arctic. Now
here we were heading into the Antarctic.

To make it pleasant, by Joe, the weather, which had been quite decent to
us on the way south, changed in order to give us a regular Cape Horn
welcome. It turned into a veritable hurricane. Nevertheless, we were
determined to carry as much sail as possible. Risky, but we had to take
chances in the hope of getting through. As the tempest increased, not even
the Seeadler dared carry more than a rag or two of lower sail. With this we
tried to hold our way. Through the mist we saw a great wall. It came
moving toward us. A vast wall of white, an iceberg. The wind was driving
this white spectre through the water, and we had to veer off in order to
avoid collision.
To the north were the cruisers, and here, but a few hundred yards away,
an equally relentless enemy bearing down upon us, as though determined to
turn us into the arms of our pursuers. A shout to the helmsman. Determined
as we were to go no farther north, we knew we could do no more than hug
the Antarctic ice field.

The mountain of ice nearest us seemed coming closer and closer—nine


times as much ice below the water as above. As every schoolboy knows, if
a berg looms up two hundred feet above the waves, its base extends
eighteen hundred feet below the surface! How far its sharp hard edges and
spurs may extend on either side you never can tell unless one of them rips
open your hull. The best way to avoid running into a spur is to turn and run
the other way. An iceberg carries neither lights, lighthouses, buoys, nor
sirens. She is a cold, calculating, merciless Circe, and the wise mariner
gives her a wide berth. Some of us thought the berg was six thousand feet
long while others thought it much more than that. We were so near it that
we could hear the clattering and squawking of the thousands of sea gulls
that swarmed around the ice mountain. In the wild, heaving sea, the berg
rolled like some mammoth ship. There were cracking sounds as the heaving
ice strained and split. Once, under the stress of the movement, one whole
vast corner broke off with a tremendous rending and tearing. The block, as
big as a skyscraper, crashed into the sea, and before it could start off on a
cruise of its own the waves dashed it into the berg with a noise like thunder,
and this continued time and again as the parent berg drove its husky
offspring before it.

Suddenly, there came an even more ominous scraping sound. The


Seeadler quivered, and our blood fairly froze. We had grazed a submerged
snout of ice. In such a sea, there would have been no chance to launch
lifeboats. Although we had not staved in our hull, nevertheless, the ship had
sprung a leak. No matter who was captain. Everybody to the pumps. I took
my place with the sailors in the hold, and we all fought to keep the water in
check. The brush with the ice was a warning. We veered a bit more to the
north, and with pumps working madly, passed the berg. The wind wrenched
us, the waves struck us hard, but we kept on, beating our way to the Pacific
and pumping.
"Cruiser ahoy!"

I saw through the storm a 23,000-ton auxiliary cruiser. I believe it was


the Otranto, a converted passenger liner, fast and well armed, capable of
blowing us out of the water before our little gun could throw a shell
halfway to her.

"Hard aport," I shouted.

The ship shook as the helm was forced over, and the wind nearly turned
us bottom side up. Storm or no storm, we were all dead men if that cruiser
ever caught us.

"Set all sails."

We must risk it and run with all our canvas before the hurricane, and
perhaps, somehow, we knew not how, in the shelter of the storm, we might
be lucky enough to evade the cruiser.

Only men who have been to sea in windjammers can imagine what it is
to set sail in a hurricane. The canvas whipped as though a devil had taken
hold of it. The masts bent under the force of the wind as it blasted against
the sails. The ship and its rigging creaked and groaned as though crying out
against the sudden strain.

"The cruiser is coming," Leudemann shouted in my ear. "She is making


straight for us."

"More sail on, by Joe," I sang out to the men aloft.

Never mind the hurricane. To the south we go. We'll bury ourselves in
the Antarctic ice before we let them catch us, if the wind doesn't snap off
our masts.

So, with the combined force of the gale and our 1,000-horsepower
motor, we scudded southward. Suddenly, a flooding rain broke over us, a
providential squall if there ever was one. It was like a gift of heaven. It
blotted us out from the cruiser, just like the squall that rescued the raider
Moewe.

"It is the hand of God," I shouted. "Our hour hasn't struck yet."

Under cover of the squall, we got away from there as fast as we could
go, and after a few hours we felt certain we had given our pursuer the slip.
In reality, we had not been pursued at all. The cruiser hadn't even seen us,
and our lookout had been sharper than hers. We learned this from later
reports. The ironical thing now would have been for us to have impaled the
Seeadler on an iceberg in that mad sprint southward. But luck was with us
again. The storm blew itself out.

Still, we were not out of the danger zone. Days went by before we were
safely out of that boisterous region and spreading our wings on the broad
expanse of the Pacific. Cruisers were still watching for us, and we had to
keep a constant lookout. Our problem now was how to put them off the
scent.

The Seeadler carried twenty lifeboats and a corresponding equipment of


life preservers. These were much more than enough for our crew. We had
taken ten of them off captured ships to accommodate our prisoners in case
of necessity. Now we threw all these extra lifeboats overboard, taking care
that on each boat and each life preserver was painted Seeadler. Our hope
was that some of them would be picked up, and that the report would then
be sent out that we had gone down off the Horn. That was exactly what
happened. Two days later we picked up a wireless. It carried the news that a
coastguard cutter had found one of our little boats. Later, two more were
picked up. Then three. All along the coast of South America we were now
given up for lost. The cruisers abandoned the chase and steamed north.

This left the way clear for us, and now we sailed out to continue our
adventure on the greatest of all the seven seas.

Fourteen days after rounding the Horn, we picked an interesting and


rather puzzling wireless out of the air:
Seeadler gone down with flags flying. Commander and part of crew
taken prisoners and on their way to Montevideo.

"What's that?" I thought. "By Joe, Johnny Bull is telling a whopper."

Now, when old John Bull tells a fib, you can bet, by Joe, that he has
good reason for it. We tried to figure it out, and came to the conclusion that
it had something to do with the scare we had created. The news that our
prisoners had given out at Rio had sent Lloyd's rates skyward and caused
many ships to lie in harbour until the danger from the German raider had
blown over. The British, in order to bring Lloyd's rates down and to liberate
all the shipping that had been tied up, took pains to spread a highly coloured
report of our disaster dressed up with suitable imaginative trimmings to
make it more convincing.

"Well, Johnny Bull," I thought, "we'll fix you."

Our wireless operator, a very capable fellow, worked out a scheme with
me. "Sparks" sent out the following message purporting to come from a
British ship:

SOS—SOS—German sub....

He cut the message short, as if interrupted, to make it seem as if at that


moment the ship had been torpedoed.

After a suitable interval he sent out another call, this one merely
reporting German submarines off the coast of Chile.

Did Lloyd's rates go up again? And did those ships that were getting
ready to put to sea put back to their berths? Well, you can bet your boots
they did. And we sent out other submarine warnings every so often just to
keep our little joke alive.
These were all small injuries, but we had been sent out to harass the
enemy, and this was one way of doing it. What more could you expect of a
lone windjammer? And then, it's these injuries all added together that more
often than not win the day. It was good sport for us, anyhow.

XXII

RAIDING THE PACIFIC

The wireless continued to be interesting. We picked up many messages


from the cruiser Kent,[1] which was right in our waters; in fact, much too
close for comfort. Our course was northward, with the Chilean coast and
the Andes almost in sight. We steered almost to the Galapagos Islands, and
at Robinson Crusoe's island, San Juan Fernandez, we trimmed our sails and
turned our bow west. We sailed for weeks on the broad expanse of the
Pacific without sighting a ship. Except for the occasional crackle of the
wireless, we were alone in the world.

[1] See Note C, Appendix.

Our wireless antennæ kept us in touch with the latest phase of the
international situation. Nor was it particularly pleasant on those long idle
days at sea to sit and meditate on the fact that the United States was going
into the war against us. We sailors knew better than some of our people at
home the tremendous power of the great republic of the West. There were
closeted statesmen and generals who might talk as they pleased about the
American lack of military preparedness and the impossibility of American
troops being mustered and sufficiently trained in time to be of any service
in the critical hour of the war. We sailors had travelled. Many of us had

You might also like