Preface
"Some people think they are polite just because they still use words at all and not fists."
-Friedrich Hebbel (1813-1863)
In the beginning was the Word. Much later, on May 23, 1995, at SunWorld in San Francisco, the head of Sun Microsystems's then Science Office, John Gage, and Netscape co-founder Marc Andreessen introduced the new Java programming language with its integration into the Netscape web browser. This event was the beginning of the triumphal procession of a language that offers elegant ways to program on any platform and to express your thoughts in an object-oriented (OO) way. The possibilities of the language and its libraries are nothing new in themselves but have been packaged so well that Java is pleasant and fluid for programming. Java is now one of the most popular programming languages on the planet. In its 23 chapters, this book deals with the Java technology with an intense focus on the Java programming language. Important topics include object-oriented programming (OOP), designing classes, and the structure of Java's standard libraries.
Target Group
The chapters of this book are designed for beginners to the Java programming language as well as for advanced users. Basic knowledge of a structured programming language such as C, Python, JavaScript, or Visual Basic and knowledge of OOP are helpful because the book doesn't explicitly address computer architectures or what programming actually is. So, if you've already programmed in any language, this book is for you!
What This Book Is Not
This book shouldn't be taken as a programming book for beginners. If you have never programmed before and associate the word "translation" primarily with "interpreting," you should start with a basic tutorial or follow one along in parallel. Many areas in the life of an industrial programmer are covered in this book to a general depth, but this book cannot replace the Java Language Specification (JLS), available at https://docs.oracle.com/javase/specs.
Java technologies have exploded in recent years, so that their initial manageability has given way to strong specialization. Today, covering everything in one book isn't possible, and we certainly won't aim for that goal with this one. A book that deals specifically with the graphical user interface (GUI) JavaFX or Swing-both parts of standard Java-could be as extensive as the book you're holding in your hands. Other special topics include OO analysis/design, Unified Modeling Language (UML), parallel or distributed programming, Enterprise JavaBeans (EJBs), database connectivity, object-relational mapping, web services, dynamic web pages, and many other topics. For all those topics, special-purpose books may be required to satisfy your curiosity.
This Java book trains you on the syntax of the programming language, the handling of important standard libraries, development tools and development environments, OO analysis and design, design patterns, and program conventions. But this book can't help you impress the cool IT geeks at a party. Sorry.
My Life and Java, Or "Why a Java Book?"
My involvement with Java started over 20 years ago and is related to a compulsory university course. In 1997, our project group dealt with an OO dialog specification. A state machine had to be programmed, and the question of which programming language to use came up. Since I wanted to introduce Java to the seminar's participants, I prepared a set of slides for our presentation. Parallel to the slides, the professor expected an elaboration in the form of a seminar paper. Working with Java was fun and something completely different from what I had been used to until then. Before Java, I had coded in Assembler for about 10 years; then later, I used the high-level languages Pascal and C, and mainly built compilers. I tried and tested code, wrote down my experiences, and learned about Java and its libraries. The work grew with my experience. During time in this group project, a fellow student approached me to give a Java training as a speaker. I felt like doing it but didn't have any documents. So, I kept writing training materials for the course. When the professor asked for the seminar paper at the end of the group project, the preliminary manuscript of the current book was already so extensive that this introduction more or less became the seminar paper.
That was in 1997, and of course, I could have stopped writing immediately after I turned in the paper. But to this day, I still enjoy Java and look forward to each new version. And I am not alone in my optimism: The forecasts for Java remain promising because the use of Java is now as established as that of COBOL in banking and insurance. That's why people keep talking about Java being "the new COBOL."
After about two decades, I now consider this book to be a multifaceted Java resource for ambitious developers who want to look behind the scenes. Its level of detail is not reached by any other book about the basics of Java in English-at least that I know of! I have enjoyed extending the book, even if many topics are hardly addressed in a normal Java course.
Software and Versions
The basis for this book is Java Platform Standard Edition (Java SE) version 17 using the free OpenJDK implementation, which is a kind of Java Development Kit (JDK). The JDK essentially consists of a compiler and a runtime environment-the Java virtual machine (JVM) -and is available for the Windows, macOS, Linux, and Solaris platforms.
A graphical development interface, called an integrated development environment (IDE), is not part of the JDK. While I don't advocate relying on one vendor (because vendors appeal to different groups of developers), this book introduces IntelliJ development environments in slightly greater detail. Our sample programs can basically be entered into any other development environment or text editor-such as Microsoft Visual Studio Code (VS Code) or vi-and compiled on the command line. However, pure text editors are outdated in development, and a graphical command-line approach simplifies program creation.
Which Java Version to Use
Since Oracle (then still led by Sun) introduced the Java programming language in 1995 with version 1.0, the version spiral has inexorably turned. A new version is released every 6 months, and every 2 years, a Long-Term-Support-Release (LTS), with updates for a longer period of time, is released. The latest LTS is Java 17. Especially for authors writing books about Java, the question arises as to which Java version the text should be based on and which libraries should be described. In this book, we always describe the capabilities of the latest version, which was Java 18 at the time of this writing. For the didactics of OOP, the version question is fortunately irrelevant.
The examples in this book are consistently based on Java 17.
Using This Book to Learn
This book is ideal for self-study. The first chapter is for warming up. If you don't have a development environment installed on your computer, you should first install the JDK from Oracle. Because the JDK only installs command-line tools, every developer should install a graphical IDE because an IDE makes the development of Java programs much more comfortable. An IDE provides several advantages over the raw command line, such as the following:
-
Editing, compiling, and running a Java program are quick and easy with a keystroke or mouse click.
-
An editor should highlight the syntax of Java in color ( syntax highlighting ).
-
A context-sensitive help shows the parameters for methods and at the same time provides access to the application programming interface (API) documentation.
-
Other benefits such as a GUI builder, project management, and debugging are added but don't play any role in this book.
In software development, the documentation of API interfaces is essential. Documentation can usually be viewed from the development environment with the touch of...