# Examples for *On Java 8* by Bruce Eckel
If you want to experiment with the code examples from the book [On Java
8](https://www.onjava8.com/), you're in the right place.
These examples are automatically extracted directly from the book. This repository
includes tests to verify that the code in the book is correct.
> NOTE: Do not attempt to use JDK 16 or greater with gradle.
> This produces a `BUG!` message from Gradle, which is broken for those versions.
## Contents
- [Building From the Command Line: Quick Version](#building-from-the-command-line-quick-version)
- [Building From the Command Line: Detailed Instructions](#building-from-the-command-line-detailed-instructions)
* [Install Java](#install-java)
+ [Windows](#windows)
+ [Macintosh](#macintosh)
+ [Linux](#linux)
* [Verify Your Installation](#verify-your-installation)
* [Installing and Running the Book Examples](#installing-and-running-the-book-examples)
- [Appendix A: Command-Line Basics](#appendix-a-command-line-basics)
* [Editors](#editors)
* [The Shell](#the-shell)
+ [Starting a Shell](#starting-a-shell)
+ [Directories](#directories)
+ [Basic Shell Operations](#basic-shell-operations)
+ [Unpacking a Zip Archive](#unpacking-a-zip-archive)
- [Appendix B: Testing](#appendix-b-testing)
- [Appendix C: Troubleshooting](#appendix-c-troubleshooting)
# Building From the Command Line: Quick Version
Before you can run the examples from this repository, you must install
[JDK8](http://www.oracle.com/technetwork/java/javase/downloads/index.html), the
*Java Development Kit* for version 8 of the language.
If you just want to download and check the code, [Download
Here](https://github.com/BruceEckel/OnJava8-Examples/archive/refs/heads/master.zip)
and [unzip it](#unpacking-a-zip-archive) into your destination directory. Open
a [shell/command window](#appendix-a-command-line-basics) and move into the
root of that directory. You'll know you are in the right directory if you see
the files `gradlew` and `gradlew.bat`.
You'll need an Internet connection the first time you compile the code,
because Gradle needs to first install itself, then all the support libraries.
Once these are installed you can perform additional compiling and running
offline.
On Mac/Linux, enter:
```
./gradlew test
```
(If you get a *Permission denied* error, run `chmod +x ./gradlew`)
On Windows, enter
```
gradlew test
```
If all goes well, the tests will run. Everything should complete without errors.
All the book examples are in the subdirectory `Examples` in subdirectories
corresponding to the atom names.
# Building From the Command Line: Detailed Instructions
If you are not familiar with the command line, first read [Command-Line
Basics](#appendix-a-command-line-basics).
## Install Java
You must first install the *Java Development Kit* (JDK).
### Windows
1. Follow the instructions to [install Chocolatey](https://chocolatey.org/).
2. At a [shell prompt](#appendix-a-command-line-basics), type: `choco install
jdk8` (you may also select a more recent version, like `jdk11`). The
installation process takes some time, but when it's finished Java is installed
and the necessary environment variables are set.
### Macintosh
The Mac comes with a much older version of Java that won't work for the
examples in this book, so you'll need to update it to (at least) Java 8.
1. Follow the instructions at this link to [Install HomeBrew](http://brew.sh/)
2. At a [shell prompt](#appendix-a-command-line-basics), first type
`brew update`. When that completes, enter `brew cask install java`.
**NOTE:** Sometimes the default version of Java that you get with the above
installation will be too recent and not validated by the Mac's security
system. If this happens you'll either need to turn off the security by hand
or install an earlier version of Java. For either choice, you'll need to Google
for answers on how to solve the problem (often the easiest approach is to just
search for the error message produced by the Mac).
### Linux
Use the standard package installer with the following [shell commands](#appendix-a-command-line-basics):
*Ubuntu/Debian*:
1. `sudo apt-get update`
2. `sudo apt-get install default-jdk`
*Fedora/Redhat*:
```
su -c "yum install java-1.8.0-openjdk"
```
## Verify Your Installation
[Open a new shell](#appendix-a-command-line-basics) and type:
```
java -version
```
You should see something like the following (Version numbers and actual text
will vary):
```
openjdk version "11" 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)
```
If you see a message that the command is not found or not recognized, review
the installation instructions. If you still can't get it to work, check
[StackOverflow](http://stackoverflow.com/search?q=installing+java).
## Installing and Running the Book Examples
Once you have Java installed, the process to install and run the book examples
is the same for all platforms:
1. Download the book examples from the
[GitHub Repository](https://github.com/BruceEckel/OnJava8-Examples/archive/refs/heads/master.zip).
2. [Unzip](#unpacking-a-zip-archive) the downloaded file into the directory of your choice.
3. Use the Windows Explorer, the Mac Finder, or Nautilus or equivalent on Linux
to browse to the directory where you uzipped `OnJava8-Examples`, and
[open a shell](#appendix-a-command-line-basics) there.
4. If you're in the right directory, you should see files named `gradlew` and
`gradlew.bat` in that directory, along with numerous other files and
directories. The directories correspond to the chapters in the book.
5. At the shell prompt, type `gradlew test` (Windows) or `./gradlew test`
(Mac/Linux).
The first time you do this, Gradle will install itself and numerous other
packages, so it will take some time. After everything is installed, subsequent
builds and runs will be much faster.
Note that you must be connected to the Internet the first time you run `gradlew`
so that Gradle can download the necessary packages.
# Appendix A: Command-Line Basics
Because it is possible for a "dedicated beginner" to learn programming from
this book, you may not have previously used your computer's command-line shell.
If you have, you can go directly to the
[installation instructions](#building-from-the-command-line-detailed-instructions).
## Editors
To create and modify Java program files—the code listings shown in this
book—you need a program called an *editor*. You'll also need the editor to
make changes to your system configuration files, which is sometimes required
during installation.
Programming editors vary from heavyweight *Integrated Development Environments*
(IDEs, like Eclipse, NetBeans and IntelliJ IDEA) to more basic text
manipulation applications. If you already have an IDE and are comfortable with
it, feel free to use that for this book.
Numerous explanations in this book are specific to IntelliJ IDEA so if you
don't already have an IDE you might as well start with IDEA. There are many
other editors; these are a subculture unto themselves and people sometimes get
into heated arguments about their merits. If you find one you like better, it's
not too hard to change. The important thing is to choose one and get
comfortable with it.
## The Shell
If you haven't programmed before, you might be unfamiliar with your operating
system *shell* (also called the *command prompt* in Windows). The shell harkens
back to the early days of computing when everything happened by typing commands
and the computer responded by displaying responses—everything was text-based.
Although it can seem primitive in the age of graphical user interfaces, a shell
provides a surprising number of valuable features.
To learn more about your shell than we cover here, see
[Bash Shell](https://en.wikipedia.org/wiki/Bash_(Unix_shell)) for Mac/Linux
or [Windows Shell](https:/
没有合适的资源?快使用搜索试试~ 我知道了~
OnJava8-Examples-master
共1117个文件
java:1073个
gradle:8个
py:5个
需积分: 5 0 下载量 78 浏览量
2023-06-14
17:42:58
上传
评论
收藏 690KB RAR 举报
温馨提示
OnJava8-Examples-master
资源推荐
资源详情
资源评论
收起资源包目录
OnJava8-Examples-master (1117个子文件)
gradlew.bat 3KB
chkstyle.bat 80B
Mixins.cpp 1KB
DogsAndRobots.cpp 693B
DogsAndRobots.cpp 568B
Templates.cpp 538B
InstantiateGenericType.cpp 471B
Cheese.dat 193B
Trash.dat 169B
.gitattributes 378B
.gitignore 2KB
petspeak.go 994B
dogsandrobots.go 710B
dogsandrobots.go 569B
junit-jupiter.gradle 2KB
subprojects.gradle 1KB
java.gradle 742B
build.gradle 693B
settings.gradle 308B
jmh.gradle 301B
checkstyle.gradle 280B
findbugs.gradle 212B
gradlew 6KB
TaggingPlugin.groovy 4KB
Tags.groovy 4KB
ExampleOutputVerificationPlugin.groovy 513B
gradle-wrapper.jar 58KB
Countries.java 10KB
Wildcards.java 9KB
AllOps.java 7KB
HTMLColors.java 7KB
Rand.java 6KB
AtUnit.java 6KB
ListOps.java 6KB
Count.java 6KB
PostOffice.java 6KB
TestRand.java 5KB
CopyConstructor.java 5KB
ClassNameFinder.java 5KB
TestCount.java 4KB
VendingMachine.java 4KB
CollectionMethodDifferences.java 4KB
MappedIO.java 4KB
PrimitiveOverloading.java 4KB
DynamicStringInverterTests.java 4KB
DynamicFields.java 4KB
GreenhouseControls.java 4KB
PriorityBlockingQueueDemo.java 4KB
ObservedFlower.java 3KB
TableCreator.java 3KB
CircularQueueTest.java 3KB
RecycleC.java 3KB
DoubleDispatch.java 3KB
GuavaPreconditions.java 3KB
ListFeatures.java 3KB
Utilities.java 3KB
BitManipulation.java 3KB
CollectionMethods.java 3KB
Frog.java 3KB
ConvertTo.java 3KB
AStoreCADState.java 3KB
References.java 3KB
IfaceExtractorProcessor.java 3KB
MyWorld.java 3KB
CheckCloneable.java 3KB
BeeAndFlowers.java 3KB
CollectionDifferences.java 3KB
StormyInning.java 3KB
TypesForSets.java 3KB
TrashVisitor.java 3KB
Worm.java 3KB
CountedListTest.java 3KB
CircularQueue.java 3KB
ZipCompress.java 3KB
Conversion.java 3KB
TestConvertTo.java 2KB
StartEnd.java 2KB
Directories.java 2KB
DualCompletableOperations.java 2KB
BufferToText.java 2KB
SimpleHashMap.java 2KB
MapOps.java 2KB
CatchCompletableExceptions.java 2KB
DelayQueueDemo.java 2KB
CountMap.java 2KB
PathInfo.java 2KB
CADSystem.java 2KB
SuppliersCollectionTest.java 2KB
Music4.java 2KB
APerson.java 2KB
AddAndSubtractPaths.java 2KB
ShowMethods.java 2KB
Music3.java 2KB
BoxObserver.java 2KB
ParseTrash.java 2KB
AtUnitExample4.java 2KB
Store.java 2KB
Staff.java 2KB
ArrayCopying.java 2KB
NavMap.java 2KB
共 1117 条
- 1
- 2
- 3
- 4
- 5
- 6
- 12
资源评论
一只小熊猫呀
- 粉丝: 707
- 资源: 48
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功