On Java 8 Examples

repository·master·Indexed 25 days ago

https://github.com/bruceeckel/onjava8-examples

Automatically extracted code examples from the book On Java 8 by Bruce Eckel. Includes a Gradle-based build system and tests to verify the correctness of the book's code, with instructions for JDK 8 installation and Gradle execution across Windows, macOS, and Linux.

Tokens
1.2K
Snippets
5
Records
9
Agent score
35%

What's inside onjava8-examples

  1. Quick start: Build and run book examples

    master

    To run the code examples from the On Java 8 book, you must first install JDK 8. After downloading and unzipping the repository, navigate to the root directory (where gradlew and gradlew.bat are located) and run the Gradle wrapper tests. An internet connection is required for the first run to allow Gradle to download necessary dependencies.

    Important Compatibility Note: Do not use JDK 16 or greater with Gradle in this repository, as it will produce a BUG! message.

  2. Basic shell operations for managing files and directories

    master

    The following commands are essential for navigating the project structure and managing files. Note the differences between Unix-based systems (Mac/Linux) and Windows.

    TaskMac/Linux CommandWindows Command
    Change directorycd <dir> or cd ..cd <dir> or cd ..
    Move & remember pathpushd <dir> (then popd to return)N/A
    List filesls or ls *.extdir or dir *.ext
    Create directorymkdir <name>md <name>
    Remove filerm <file>del <file>
    Remove directoryrm -r <dir>deltree <dir>
    Repeat last command!!N/A
    View command historyhistoryF7 key
  3. Start a shell on Mac, Windows, or Linux

    master

    To run the book's examples, you will need to use a command-line shell. Use the following methods to open one:

    • Mac: Open Spotlight (magnifying glass icon), type "terminal", and press Return.
    • Windows:
      • Windows 7: Search for "explorer" in the Start Menu and press Enter.
      • Windows 8: Press Windows+Q, type "explorer", and press Enter.
      • Windows 10: Press Windows+E.
      • Once Explorer is open, navigate to your desired folder, click the file tab at the top left, and select "Open Windows Powershell".
    • Linux:
      • Debian/Fedora: Press Alt+F2 and type gnome-terminal.
      • Ubuntu: Right-click the desktop and select "Open Terminal" or press Ctrl+Alt+T.
      • Redhat: Right-click the desktop and select "Open Terminal".
  4. Run, compile, and test book examples using Gradle

    master

    All commands must be run from the base directory where the gradlew script is located. On Unix/Linux systems, you must prefix commands with ./.

    Running the project

    • Compile and run everything: gradlew run (Unix: ./gradlew run)
    • Run a specific program: gradlew <program_name> (e.g., gradlew ReplacingStringTokenizer)
    • Run a program in a specific chapter: gradlew :<chapter>:<program_name> (e.g., gradlew :strings:ReplacingStringTokenizer)

    Compiling

    • Compile everything: gradlew compileJava (Unix: ./gradlew compileJava)
    • Compile a specific chapter: gradlew :<chapter>:compileJava (e.g., gradlew :strings:compileJava)

    Testing

    • Run all tests: gradlew test (Windows) or ./gradlew test (Mac/Linux)
  5. Troubleshoot SSL/cacerts errors in Gradle

    master

    If a Gradle build fails with an SSLException related to trustAnchors, it typically indicates a conflict between multiple Java installations on your machine. The cacerts security file of one installation may be interfering with the one used by Gradle.

    Error signature: javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty

    Resolution steps:

    1. Identify all cacerts files on your machine.
    2. Uninstall conflicting Java applications or remove the directory containing the interfering cacerts file.
    3. Adjust environment variables or your system PATH if necessary.
    4. Once Gradle works, reinstall required applications.
    javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty