Skip to content

Commit d88c904

Browse files
author
jim.deng
committed
1
1 parent 0a4365e commit d88c904

File tree

1,051 files changed

+40784
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,051 files changed

+40784
-0
lines changed

code/.gitattributes

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto
3+
4+
# Custom for Visual Studio
5+
*.cs diff=csharp
6+
7+
# Standard to msysgit
8+
*.doc diff=astextplain
9+
*.DOC diff=astextplain
10+
*.docx diff=astextplain
11+
*.DOCX diff=astextplain
12+
*.dot diff=astextplain
13+
*.DOT diff=astextplain
14+
*.pdf diff=astextplain
15+
*.PDF diff=astextplain
16+
*.rtf diff=astextplain
17+
*.RTF diff=astextplain

code/.gitignore

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Windows image file caches
2+
Thumbs.db
3+
ehthumbs.db
4+
5+
# Folder config file
6+
Desktop.ini
7+
8+
# Recycle Bin used on file shares
9+
$RECYCLE.BIN/
10+
11+
# Windows Installer files
12+
*.cab
13+
*.msi
14+
*.msm
15+
*.msp
16+
17+
# Windows shortcuts
18+
*.lnk
19+
20+
# =========================
21+
# Operating System Files
22+
# =========================
23+
24+
# OSX
25+
# =========================
26+
27+
.DS_Store
28+
.AppleDouble
29+
.LSOverride
30+
31+
# Thumbnails
32+
._*
33+
34+
# Files that might appear on external disk
35+
.Spotlight-V100
36+
.Trashes
37+
38+
# Directories potentially created on remote AFP share
39+
.AppleDB
40+
.AppleDesktop
41+
Network Trash Folder
42+
Temporary Items
43+
.apdisk
44+
45+
*.class
46+
*output.txt
47+
Generated.txt
48+
*-control.txt
49+
*-results.txt
50+
*-out.txt
51+
OutputErrors.txt
52+
report.txt
53+
failures
54+
People.xml
55+
annotations/Test0.txt
56+
annotations/Test1.txt
57+
annotations/Test2.txt
58+
io/*.out
59+
io/*.txt
60+
io/*.dat
61+
io/*.tmp
62+
io/test.zip
63+
io/test.gz
64+
io/X.file
65+
*.pyc
66+
67+
*.out
68+
*.err
69+
/files/bytes.dat
70+
/files/test/
71+
/exceptions/Results.txt
72+
/files/Cheese.txt
73+
/files/StreamInAndOut.txt
74+
75+
.gradle
76+
/*.iml
77+
/.idea/
78+
79+
/serialization/Blip3.serialized
80+
/serialization/Blips.serialized
81+
82+
build/
83+
buildSrc/
84+
85+
/compression/test.gz
86+
/compression/test.zip
87+
/iostreams/BasicFileOutput.dat
88+
/iostreams/Data.txt
89+
/iostreams/FileOutputShortcut.dat
90+
/iostreams/rtest.dat
91+
/logging/LogToFile.xml
92+
/logging/LogToFile2.txt
93+
/logging/MultipleHandlers.xml
94+
/logging/MultipleHandlers2.xml
95+
/logging/java0.log
96+
/logging/java1.log
97+
/logging/java2.log
98+
/newio/TransferTo.txt
99+
/newio/data2.txt
100+
/newio/file.txt
101+
/newio/test.dat
102+
/newio/test.txt
103+
/serialization/CADState.dat
104+
/serialization/worm.dat
105+
/serialization/Logon.dat
106+
/serialization/X.file
107+
/standardio/Redirecting.txt
108+
/threads/PSP2.txt
109+
/threads/primes.txt
110+
_*
111+
config.py

code/.travisXX.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
language: java
2+
jdk:
3+
- oraclejdk11
4+
install: true
5+
script:
6+
- ./gradlew --no-daemon --stacktrace run
7+
# - ./gradlew --parallel --stacktrace run
8+
# - ./gradlew --parallel --stacktrace :validating:jmh

code/CI.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Links formerly in the README. Both of these mysteriously started breaking.
2+
3+
[![](https://travis-ci.org/BruceEckel/OnJava8-Examples.svg?branch=master)](https://travis-ci.org/BruceEckel/OnJava8-Examples)
4+
5+
[![](https://ci.appveyor.com/api/projects/status/github/BruceEckel/OnJava8-Examples)](https://ci.appveyor.com/project/BruceEckel/onjava-examples)

code/Copyright.txt

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright.txt
2+
This computer source code is Copyright �2020 MindView LLC.
3+
All Rights Reserved.
4+
5+
Permission to use, copy, modify, and distribute this
6+
computer source code (Source Code) and its documentation
7+
without fee and without a written agreement for the
8+
purposes set forth below is hereby granted, provided that
9+
the above copyright notice, this paragraph and the
10+
following five numbered paragraphs appear in all copies.
11+
12+
1. Permission is granted to compile the Source Code and to
13+
include the compiled code, in executable format only, in
14+
personal and commercial software programs.
15+
16+
2. Permission is granted to use the Source Code without
17+
modification in classroom situations, including in
18+
presentation materials, provided that the book "On
19+
Java 8" is cited as the origin.
20+
21+
3. Permission to incorporate the Source Code into printed
22+
media may be obtained by contacting:
23+
24+
MindView LLC, PO Box 969, Crested Butte, CO 81224
25+
MindViewInc@gmail.com
26+
27+
4. The Source Code and documentation are copyrighted by
28+
MindView LLC. The Source code is provided without express
29+
or implied warranty of any kind, including any implied
30+
warranty of merchantability, fitness for a particular
31+
purpose or non-infringement. MindView LLC does not
32+
warrant that the operation of any program that includes the
33+
Source Code will be uninterrupted or error-free. MindView
34+
LLC makes no representation about the suitability of the
35+
Source Code or of any software that includes the Source
36+
Code for any purpose. The entire risk as to the quality
37+
and performance of any program that includes the Source
38+
Code is with the user of the Source Code. The user
39+
understands that the Source Code was developed for research
40+
and instructional purposes and is advised not to rely
41+
exclusively for any reason on the Source Code or any
42+
program that includes the Source Code. Should the Source
43+
Code or any resulting software prove defective, the user
44+
assumes the cost of all necessary servicing, repair, or
45+
correction.
46+
47+
5. IN NO EVENT SHALL MINDVIEW LLC, OR ITS PUBLISHER BE
48+
LIABLE TO ANY PARTY UNDER ANY LEGAL THEORY FOR DIRECT,
49+
INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
50+
INCLUDING LOST PROFITS, BUSINESS INTERRUPTION, LOSS OF
51+
BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS, OR FOR
52+
PERSONAL INJURIES, ARISING OUT OF THE USE OF THIS SOURCE
53+
CODE AND ITS DOCUMENTATION, OR ARISING OUT OF THE INABILITY
54+
TO USE ANY RESULTING PROGRAM, EVEN IF MINDVIEW LLC, OR
55+
ITS PUBLISHER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
56+
DAMAGE. MINDVIEW LLC SPECIFICALLY DISCLAIMS ANY
57+
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
58+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
59+
PURPOSE. THE SOURCE CODE AND DOCUMENTATION PROVIDED
60+
HEREUNDER IS ON AN "AS IS" BASIS, WITHOUT ANY ACCOMPANYING
61+
SERVICES FROM MINDVIEW LLC, AND MINDVIEW LLC HAS NO
62+
OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
63+
ENHANCEMENTS, OR MODIFICATIONS.
64+
65+
Please note that MindView LLC maintains a Web site which
66+
is the sole distribution point for electronic copies of the
67+
Source Code, https://github.com/BruceEckel/OnJava8-examples,
68+
where it is freely available under the terms stated above.
69+
70+
If you think you've found an error in the Source Code,
71+
please submit a correction at:
72+
https://github.com/BruceEckel/OnJava8-examples/issues

code/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Example Source Code for the Book "On Java 8" by Bruce Eckel
2+
3+
Download release from [here](https://github.com/BruceEckel/OnJava8-Examples/releases/tag/v1.0).
4+
5+
To compile and run these programs, you only need JDK 8 installed.
6+
Invoking `gradlew` will automatically download and install Gradle.
7+
Gradle will also install all additional libraries necessary to compile
8+
and run the Java examples in the book.
9+
10+
To compile and run everything, the command is:
11+
12+
`gradlew run`
13+
14+
If you are on a Unix/Linux based system, you must select the local directory for all commands, for example:
15+
16+
`./gradlew run`
17+
18+
To only compile everything, the command is:
19+
20+
`gradlew compileJava`
21+
22+
To compile only a single chapter (including dependencies), use for example:
23+
24+
`gradlew :strings:compileJava`
25+
26+
To run only a single chapter, say:
27+
28+
`gradlew :strings:run`
29+
30+
Gradle can also be used to run a single program. Here, we run the **ReplacingStringTokenizer.java**
31+
program in the **strings** chapter subdirectory:
32+
33+
`gradlew :strings:ReplacingStringTokenizer`
34+
35+
However, if the file name is unique throughout the book (the majority are), you can just give the
36+
program name, like this:
37+
38+
`gradlew ReplacingStringTokenizer`
39+
40+
Note that all commands are run from the base directory where the example code is installed, and where you find the
41+
`gradlew` script.
42+
43+
You can learn about other options by just typing `gradlew` with no arguments.

code/annotations/AUComposition.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// annotations/AUComposition.java
2+
// (c)2020 MindView LLC: see Copyright.txt
3+
// We make no guarantees that this code is fit for any purpose.
4+
// Visit http://OnJava8.com for more book information.
5+
// Creating non-embedded tests
6+
// {java onjava.atunit.AtUnit
7+
// build/classes/java/main/annotations/AUComposition.class}
8+
package annotations;
9+
import onjava.atunit.*;
10+
import onjava.*;
11+
12+
public class AUComposition {
13+
AtUnitExample1 testObject = new AtUnitExample1();
14+
@Test
15+
boolean tMethodOne() {
16+
return testObject.methodOne()
17+
.equals("This is methodOne");
18+
}
19+
@Test
20+
boolean tMethodTwo() {
21+
return testObject.methodTwo() == 2;
22+
}
23+
}
24+
/* Output:
25+
annotations.AUComposition
26+
. tMethodTwo This is methodTwo
27+
28+
. tMethodOne
29+
OK (2 tests)
30+
*/

code/annotations/AUExternalTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// annotations/AUExternalTest.java
2+
// (c)2020 MindView LLC: see Copyright.txt
3+
// We make no guarantees that this code is fit for any purpose.
4+
// Visit http://OnJava8.com for more book information.
5+
// Creating non-embedded tests
6+
// {java onjava.atunit.AtUnit
7+
// build/classes/java/main/annotations/AUExternalTest.class}
8+
package annotations;
9+
import onjava.atunit.*;
10+
import onjava.*;
11+
12+
public class
13+
AUExternalTest extends AtUnitExample1 {
14+
@Test
15+
boolean tMethodOne() {
16+
return methodOne().equals("This is methodOne");
17+
}
18+
@Test
19+
boolean tMethodTwo() {
20+
return methodTwo() == 2;
21+
}
22+
}
23+
/* Output:
24+
annotations.AUExternalTest
25+
. tMethodOne
26+
. tMethodTwo This is methodTwo
27+
28+
OK (2 tests)
29+
*/

code/annotations/AtUnitExample1.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// annotations/AtUnitExample1.java
2+
// (c)2020 MindView LLC: see Copyright.txt
3+
// We make no guarantees that this code is fit for any purpose.
4+
// Visit http://OnJava8.com for more book information.
5+
// {java onjava.atunit.AtUnit
6+
// build/classes/java/main/annotations/AtUnitExample1.class}
7+
package annotations;
8+
import onjava.atunit.*;
9+
import onjava.*;
10+
11+
public class AtUnitExample1 {
12+
public String methodOne() {
13+
return "This is methodOne";
14+
}
15+
public int methodTwo() {
16+
System.out.println("This is methodTwo");
17+
return 2;
18+
}
19+
@Test
20+
boolean methodOneTest() {
21+
return methodOne().equals("This is methodOne");
22+
}
23+
@Test
24+
boolean m2() { return methodTwo() == 2; }
25+
@Test
26+
private boolean m3() { return true; }
27+
// Shows output for failure:
28+
@Test
29+
boolean failureTest() { return false; }
30+
@Test
31+
boolean anotherDisappointment() {
32+
return false;
33+
}
34+
}
35+
/* Output:
36+
annotations.AtUnitExample1
37+
. m3
38+
. methodOneTest
39+
. m2 This is methodTwo
40+
41+
. failureTest (failed)
42+
. anotherDisappointment (failed)
43+
(5 tests)
44+
45+
>>> 2 FAILURES <<<
46+
annotations.AtUnitExample1: failureTest
47+
annotations.AtUnitExample1: anotherDisappointment
48+
*/

0 commit comments

Comments
 (0)