{"id":13511804,"url":"https://github.com/BruceEckel/OnJava8-Examples","last_synced_at":"2025-03-30T21:30:58.480Z","repository":{"id":30733827,"uuid":"34290135","full_name":"BruceEckel/OnJava8-Examples","owner":"BruceEckel","description":"Code Examples for the book \"On Java 8\"","archived":false,"fork":false,"pushed_at":"2023-07-19T07:12:34.000Z","size":10935,"stargazers_count":3119,"open_issues_count":18,"forks_count":1155,"subscribers_count":106,"default_branch":"master","last_synced_at":"2025-03-30T13:05:36.722Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://www.OnJava8.com","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BruceEckel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2015-04-20T22:34:50.000Z","updated_at":"2025-03-27T01:22:57.000Z","dependencies_parsed_at":"2024-01-14T19:22:15.688Z","dependency_job_id":null,"html_url":"https://github.com/BruceEckel/OnJava8-Examples","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BruceEckel%2FOnJava8-Examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BruceEckel%2FOnJava8-Examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BruceEckel%2FOnJava8-Examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BruceEckel%2FOnJava8-Examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BruceEckel","download_url":"https://codeload.github.com/BruceEckel/OnJava8-Examples/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246385028,"owners_count":20768661,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T03:01:11.524Z","updated_at":"2025-03-30T21:30:58.474Z","avatar_url":"https://github.com/BruceEckel.png","language":"Java","funding_links":[],"categories":["Java","Programming languages"],"sub_categories":["Java"],"readme":"# Examples for *On Java 8* by Bruce Eckel\n\nIf you want to experiment with the code examples from the book [On Java\n8](https://www.onjava8.com/), you're in the right place.\n\nThese examples are automatically extracted directly from the book. This repository\nincludes tests to verify that the code in the book is correct.\n\n\u003e NOTE: Do not attempt to use JDK 16 or greater with gradle. \n\u003e This produces a `BUG!` message from Gradle, which is broken for those versions.\n\n## Contents\n\n- [Building From the Command Line: Quick Version](#building-from-the-command-line-quick-version)\n- [Building From the Command Line: Detailed Instructions](#building-from-the-command-line-detailed-instructions)\n  * [Install Java](#install-java)\n    + [Windows](#windows)\n    + [Macintosh](#macintosh)\n    + [Linux](#linux)\n  * [Verify Your Installation](#verify-your-installation)\n  * [Installing and Running the Book Examples](#installing-and-running-the-book-examples)\n- [Appendix A: Command-Line Basics](#appendix-a-command-line-basics)\n  * [Editors](#editors)\n  * [The Shell](#the-shell)\n    + [Starting a Shell](#starting-a-shell)\n    + [Directories](#directories)\n    + [Basic Shell Operations](#basic-shell-operations)\n    + [Unpacking a Zip Archive](#unpacking-a-zip-archive)\n- [Appendix B: Testing](#appendix-b-testing)\n- [Appendix C: Troubleshooting](#appendix-c-troubleshooting)\n\n# Building From the Command Line: Quick Version\n\nBefore you can run the examples from this repository, you must install\n[JDK8](http://www.oracle.com/technetwork/java/javase/downloads/index.html), the\n*Java Development Kit* for version 8 of the language.\n\nIf you just want to download and check the code, [Download\nHere](https://github.com/BruceEckel/OnJava8-Examples/archive/refs/heads/master.zip)\nand [unzip it](#unpacking-a-zip-archive) into your destination directory. Open\na [shell/command window](#appendix-a-command-line-basics) and move into the\nroot of that directory. You'll know you are in the right directory if you see\nthe files `gradlew` and `gradlew.bat`.\n\nYou'll need an Internet connection the first time you compile the code,\nbecause Gradle needs to first install itself, then all the support libraries.\nOnce these are installed you can perform additional compiling and running\noffline.\n\nOn Mac/Linux, enter:\n\n```\n./gradlew test\n```\n\n(If you get a *Permission denied* error, run `chmod +x ./gradlew`)\n\nOn Windows, enter\n\n```\ngradlew test\n```\n\nIf all goes well, the tests will run. Everything should complete without errors.\n\nAll the book examples are in the subdirectory `Examples` in subdirectories\ncorresponding to the atom names.\n\n# Building From the Command Line: Detailed Instructions\n\nIf you are not familiar with the command line, first read [Command-Line\nBasics](#appendix-a-command-line-basics).\n\n## Install Java\n\nYou must first install the *Java Development Kit* (JDK).\n\n### Windows\n\n1. Follow the instructions to [install Chocolatey](https://chocolatey.org/).\n\n2. At a [shell prompt](#appendix-a-command-line-basics), type: `choco install\njdk8` (you may also select a more recent version, like `jdk11`). The\ninstallation process takes some time, but when it's finished Java is installed\nand the necessary environment variables are set.\n\n### Macintosh\n\nThe Mac comes with a much older version of Java that won't work for the\nexamples in this book, so you'll need to update it to (at least) Java 8.\n\n  1.  Follow the instructions at this link to [Install HomeBrew](http://brew.sh/)\n\n  2.  At a [shell prompt](#appendix-a-command-line-basics), first type\n      `brew update`. When that completes, enter `brew cask install java`.\n\n**NOTE:** Sometimes the default version of Java that you get with the above\ninstallation will be too recent and not validated by the Mac's security\nsystem. If this happens you'll either need to turn off the security by hand\nor install an earlier version of Java. For either choice, you'll need to Google\nfor answers on how to solve the problem (often the easiest approach is to just\nsearch for the error message produced by the Mac).\n\n### Linux\n\nUse the standard package installer with the following [shell commands](#appendix-a-command-line-basics):\n\n*Ubuntu/Debian*:\n\n  1. `sudo apt-get update`\n\n  2. `sudo apt-get install default-jdk`\n\n*Fedora/Redhat*:\n\n```\nsu -c \"yum install java-1.8.0-openjdk\"\n```\n\n## Verify Your Installation\n\n[Open a new shell](#appendix-a-command-line-basics) and type:\n\n```\njava -version\n```\n\nYou should see something like the following (Version numbers and actual text\nwill vary):\n\n```\nopenjdk version \"11\" 2018-09-25\nOpenJDK Runtime Environment 18.9 (build 11+28)\nOpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)\n```\n\nIf you see a message that the command is not found or not recognized, review\nthe installation instructions. If you still can't get it to work, check\n[StackOverflow](http://stackoverflow.com/search?q=installing+java).\n\n## Installing and Running the Book Examples\n\nOnce you have Java installed, the process to install and run the book examples\nis the same for all platforms:\n\n1. Download the book examples from the\n[GitHub Repository](https://github.com/BruceEckel/OnJava8-Examples/archive/refs/heads/master.zip).\n\n2. [Unzip](#unpacking-a-zip-archive) the downloaded file into the directory of your choice.\n\n3. Use the Windows Explorer, the Mac Finder, or Nautilus or equivalent on Linux\nto browse to the directory where you uzipped `OnJava8-Examples`, and\n[open a shell](#appendix-a-command-line-basics) there.\n\n4. If you're in the right directory, you should see files named `gradlew` and\n`gradlew.bat` in that directory, along with numerous other files and\ndirectories. The directories correspond to the chapters in the book.\n\n5. At the shell prompt, type `gradlew test` (Windows) or `./gradlew test`\n(Mac/Linux).\n\nThe first time you do this, Gradle will install itself and numerous other\npackages, so it will take some time. After everything is installed, subsequent\nbuilds and runs will be much faster.\n\nNote that you must be connected to the Internet the first time you run `gradlew`\nso that Gradle can download the necessary packages.\n\n# Appendix A: Command-Line Basics\n\nBecause it is possible for a \"dedicated beginner\" to learn programming from\nthis book, you may not have previously used your computer's command-line shell.\nIf you have, you can go directly to the\n[installation instructions](#building-from-the-command-line-detailed-instructions).\n\n## Editors\n\nTo create and modify Java program files\u0026mdash;the code listings shown in this\nbook\u0026mdash;you need a program called an *editor*. You'll also need the editor to\nmake changes to your system configuration files, which is sometimes required\nduring installation.\n\nProgramming editors vary from heavyweight *Integrated Development Environments*\n(IDEs, like Eclipse, NetBeans and IntelliJ IDEA) to more basic text\nmanipulation applications. If you already have an IDE and are comfortable with\nit, feel free to use that for this book.\n\nNumerous explanations in this book are specific to IntelliJ IDEA so if you\ndon't already have an IDE you might as well start with IDEA. There are many\nother editors; these are a subculture unto themselves and people sometimes get\ninto heated arguments about their merits. If you find one you like better, it's\nnot too hard to change. The important thing is to choose one and get\ncomfortable with it.\n\n## The Shell\n\nIf you haven't programmed before, you might be unfamiliar with your operating\nsystem *shell* (also called the *command prompt* in Windows). The shell harkens\nback to the early days of computing when everything happened by typing commands\nand the computer responded by displaying responses\u0026mdash;everything was text-based.\n\nAlthough it can seem primitive in the age of graphical user interfaces, a shell\nprovides a surprising number of valuable features.\n\nTo learn more about your shell than we cover here, see\n[Bash Shell](https://en.wikipedia.org/wiki/Bash_(Unix_shell)) for Mac/Linux\nor [Windows Shell](https://en.wikipedia.org/wiki/Windows_shell).\n\n### Starting a Shell\n\n**Mac**: Click on the *Spotlight* (the magnifying-glass icon in the upper-right\ncorner of the screen) and type \"terminal.\" Click on the application that looks\nlike a little TV screen (you might also be able to hit \"Return\"). This starts a\nshell in your home directory.\n\n**Windows**: First, start the Windows Explorer to navigate through your\ndirectories:\n\n- *Windows 7*: click the \"Start\" button in the lower left corner of the screen.\nIn the Start Menu search box area type \"explorer\" and then press the \"Enter\"\nkey.\n\n- *Windows 8*: click Windows+Q, type \"explorer\" and then press the \"Enter\" key.\n\n- *Windows 10*: click Windows+E.\n\nOnce the Windows Explorer is running, move through the folders on your computer\nby double-clicking on them with the mouse. Navigate to the desired folder. Now\nclick the file tab at the top left of the Explorer window and select \"Open\nWindows Powershell.\" This opens a shell in the destination directory.\n\n**Linux**: To open a shell in your home directory:\n\n- *Debian*: Press Alt+F2. In the dialog that pops up, type 'gnome-terminal'\n\n- *Ubuntu*: Either right-click on the desktop and select 'Open Terminal', or\n  press Ctrl+Alt+T\n\n- *Redhat*: Right-click on the desktop and select 'Open Terminal'\n\n- *Fedora*: Press Alt+F2. In the dialog that pops up, type 'gnome-terminal'\n\n\n### Directories\n\n*Directories* are one of the fundamental elements of a shell. Directories hold\nfiles, as well as other directories. Think of a directory as a tree with\nbranches. If `books` is a directory on your system and it has two other\ndirectories as branches, for example `math` and `art`, we say that you have a\ndirectory `books` with two *subdirectories* `math` and `art`. We refer to them\nas `books/math` and `books/art` since `books` is their *parent* directory.\nNote that Windows uses backslashes rather than forward slashes to separate the\nparts of a directory.\n\n### Basic Shell Operations\n\nThe shell operations shown here are approximately identical across operating\nsystems. For the purposes of this book, here are the essential operations in a\nshell:\n\n-   **Change directory**: Use `cd` followed by the name of the\n    directory where you want to move, or `cd ..` if you want to move\n    up a directory. If you want to move to a different directory while\n    remembering where you came from, use `pushd` followed by the different\n    directory name. Then, to return to the previous directory, just say\n    `popd`.\n\n-   **Directory listing**: `ls` (`dir` in Windows) displays all the files and\n    subdirectory names in the current directory. Use the wildcard `*` (asterisk) to\n    narrow your search. For example, if you want to list all the files ending in\n    \".kt,\" you say `ls *.kt` (Windows: `dir *.kt`). If you want to list the\n    files starting with \"F\" and ending in \".kt,\" you say `ls F*.kt` (Windows:\n    `dir F*.kt`).\n\n-   **Create a directory**: use the `mkdir` (\"make directory\") command\n    (Windows: `md`), followed by the name of the directory you want to create.\n    For example, `mkdir books` (Windows: `md books`).\n\n-   **Remove a file**: Use `rm` (\"remove\") followed by the name of the file\n    you wish to remove (Windows: `del`). For example, `rm somefile.kt` (Windows:\n    `del somefile.kt`).\n\n-   **Remove a directory**: use the `rm -r` command to remove the files in\n    the directory and the directory itself (Windows: `deltree`). For example,\n    `rm -r books` (Windows: `deltree books`).\n\n-   **Repeat a command**: The \"up arrow\" on all three operating\n    systems moves through previous commands so you can edit and\n    repeat them. On Mac/Linux, `!!` repeats the last command and\n    `!n` repeats the nth command.\n\n-   **Command history**: Use `history` in Mac/Linux or press the F7 key in Windows.\n    This gives you a list of all the commands you've entered. Mac/Linux provides\n    numbers to refer to when you want to repeat a command.\n\n### Unpacking a Zip Archive\n\nA file name ending with `.zip` is an archive containing other files in a\ncompressed format. Both Linux and Mac have command-line `unzip` utilities, and\nit's possible to install a command-line `unzip` for Windows via the Internet.\n\nHowever, in all three systems the graphical file browser (Windows Explorer, the\nMac Finder, or Nautilus or equivalent on Linux) will browse to the directory\ncontaining your zip file. Then right-mouse-click on the file and select \"Open\"\non the Mac, \"Extract Here\" on Linux, or \"Extract all ...\" on Windows.\n\n# Appendix B: Testing\n\nThe test system is built in so that we (the authors) can verify the correctness\nof what goes into the book.\n\nYou don't need to run the tests, but if you want to, you can just run `gradlew\ntest` (on Windows) or `./gradlew test` (Mac/Linux).\n\nTo compile and run everything, the command is:\n\n`gradlew run`\n\nIf you are on a Unix/Linux based system, you must select the local directory for all commands, for example:\n\n`./gradlew run`\n\nTo only compile everything, the command is:\n\n`gradlew compileJava`\n\nTo compile only a single chapter (including dependencies), use for example:\n\n`gradlew :strings:compileJava`\n\nTo run only a single chapter, say:\n\n`gradlew :strings:run`\n\nGradle can also be used to run a single program. Here, we run the **ReplacingStringTokenizer.java**\nprogram in the **strings** chapter subdirectory:\n\n`gradlew  :strings:ReplacingStringTokenizer`\n\nHowever, if the file name is unique throughout the book (the majority are), you\ncan just give the program name, like this:\n\n`gradlew  ReplacingStringTokenizer`\n\nNote that all commands are run from the base directory where the example code is\ninstalled, and where you find the `gradlew` script.\n\nYou can learn about other options by just typing `gradlew` with no arguments.\n\n# Appendix C: Troubleshooting\n\nIf any terminology or processes described here remain unclear to you, you can\nusually find explanations or answers through [Google](https://www.google.com/).\nFor more specific issues or problems, try\n[StackOverflow](http://stackoverflow.com/). Sometimes you can find installation\ninstructions on [YouTube](https://www.youtube.com/).\n\nSometimes a Gradle build will be unable to connect to the internet and download\nthe necessary components, producing an error message containing:\n\n```\njavax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty\n```\n\nNormally this means you have multiple Java installations on your machine\n(applications built with Java ordinarily install their own version of Java), and\nsomehow the `cacerts` security file is interfering with the `cacerts` file for\nthe Java you have installed. It can be difficult to know which `cacerts` file is\ninterfering with yours. The brute-force approach is to search for all the\n`cacerts` files on your machine and begin uninstalling the associated\napplications---or in some cases, simply removing the directory containing the\n`cacerts` file---until the Gradle build begins to work. You might also need to\nadjust some environment variables and/or your path. Once you get the Gradle\nbuild working successfully, you should be able to reinstall any applications you\nremoved in the process.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBruceEckel%2FOnJava8-Examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FBruceEckel%2FOnJava8-Examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBruceEckel%2FOnJava8-Examples/lists"}