Further Updates prior to releasing Version 2.0 of book
This commit is contained in:
parent
7bf3a4c7b7
commit
ade1d5ef12
@ -16,19 +16,23 @@ public class AsListInference {
|
||||
List<Snow> snow1 = Arrays.asList(
|
||||
new Crusty(), new Slush(), new Powder());
|
||||
//- snow1.add(new Heavy()); // Exception
|
||||
//- snow1.remove(0); // Exception
|
||||
|
||||
List<Snow> snow2 = Arrays.asList(
|
||||
new Light(), new Heavy());
|
||||
//- snow2.add(new Slush()); // Exception
|
||||
//- snow2.remove(0); // Exception
|
||||
|
||||
List<Snow> snow3 = new ArrayList<>();
|
||||
Collections.addAll(snow3,
|
||||
new Light(), new Heavy(), new Powder());
|
||||
snow3.add(new Crusty());
|
||||
snow3.remove(0);
|
||||
|
||||
// Hint with explicit type argument specification:
|
||||
List<Snow> snow4 = Arrays.<Snow>asList(
|
||||
new Light(), new Heavy(), new Slush());
|
||||
//- snow4.add(new Powder()); // Exception
|
||||
//- snow4.remove(0); // Exception
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +0,0 @@
|
||||
0: main
|
||||
1: main
|
||||
2: main
|
||||
3: main
|
||||
4: main
|
||||
5: main
|
||||
6: main
|
||||
7: main
|
||||
8: main
|
||||
9: main
|
100000
concurrent/primes.txt
100000
concurrent/primes.txt
File diff suppressed because it is too large
Load Diff
@ -52,13 +52,12 @@ public class AddAndSubtractPaths {
|
||||
}
|
||||
}
|
||||
/* Output:
|
||||
Windows 8.1
|
||||
Windows 10
|
||||
C:\Git
|
||||
(1)r OnJava8\ExtractedExamples\files\AddAndSubtractPath
|
||||
s.java
|
||||
RealPath: C:\Git\OnJava8\ExtractedExamples\files\AddAnd
|
||||
SubtractPaths.java
|
||||
(2)r OnJava8\ExtractedExamples\strings\..\files
|
||||
(1)r OnJava8\ExtractedExamples\files\AddAndSubtractPaths.java
|
||||
RealPath:
|
||||
C:\Git\OnJava8\ExtractedExamples\files\AddAndSubtractPaths.java
|
||||
(2)r OnJava8\ExtractedExamples\files
|
||||
RealPath: C:\Git\OnJava8\ExtractedExamples\files
|
||||
(3)r OnJava8\ExtractedExamples\files
|
||||
RealPath: C:\Git\OnJava8\ExtractedExamples\files
|
||||
@ -68,7 +67,7 @@ RealPath: C:\Git\OnJava8
|
||||
RealPath: C:\Git\OnJava8
|
||||
(6)r OnJava8
|
||||
RealPath: C:\Git\OnJava8
|
||||
(7)r OnJava8\ExtractedExamples\files\.\..\..
|
||||
(7)r OnJava8
|
||||
RealPath: C:\Git\OnJava8
|
||||
(8)r OnJava8
|
||||
RealPath: C:\Git\OnJava8
|
||||
|
@ -26,20 +26,22 @@ public class FileSystemDemo {
|
||||
}
|
||||
}
|
||||
/* Output:
|
||||
Windows 8.1
|
||||
Windows 10
|
||||
File Store: (C:)
|
||||
File Store: System Reserved (E:)
|
||||
File Store: (F:)
|
||||
File Store: Google Drive (G:)
|
||||
Root Directory: C:\
|
||||
Root Directory: D:\
|
||||
Root Directory: E:\
|
||||
Root Directory: F:\
|
||||
Root Directory: G:\
|
||||
Separator: \
|
||||
UserPrincipalLookupService:
|
||||
sun.nio.fs.WindowsFileSystem$LookupService$1@19e0bfd
|
||||
sun.nio.fs.WindowsFileSystem$LookupService$1@1bd4fdd
|
||||
isOpen: true
|
||||
isReadOnly: false
|
||||
FileSystemProvider:
|
||||
sun.nio.fs.WindowsFileSystemProvider@139a55
|
||||
sun.nio.fs.WindowsFileSystemProvider@55183b20
|
||||
File Attribute Views: [owner, dos, acl, basic, user]
|
||||
*/
|
||||
|
@ -23,7 +23,7 @@ public class PartsOfPaths {
|
||||
}
|
||||
}
|
||||
/* Output:
|
||||
Windows 8.1
|
||||
Windows 10
|
||||
Git
|
||||
OnJava8
|
||||
ExtractedExamples
|
||||
|
@ -38,7 +38,7 @@ public class PathAnalysis {
|
||||
}
|
||||
}
|
||||
/* Output:
|
||||
Windows 8.1
|
||||
Windows 10
|
||||
Exists: true
|
||||
Directory: false
|
||||
Executable: true
|
||||
@ -49,8 +49,8 @@ notExists: false
|
||||
Hidden: false
|
||||
size: 1617
|
||||
FileStore: (C:)
|
||||
LastModified: : 2021-01-24T15:48:37.461504Z
|
||||
LastModified: : 2021-11-08T00:34:52.693768Z
|
||||
Owner: GROOT\Bruce (User)
|
||||
ContentType: null
|
||||
ContentType: text/plain
|
||||
SymbolicLink: false
|
||||
*/
|
||||
|
@ -9,17 +9,17 @@ import java.io.IOException;
|
||||
|
||||
public class PathInfo {
|
||||
static void show(String id, Object p) {
|
||||
System.out.println(id + ": " + p);
|
||||
System.out.println(id + p);
|
||||
}
|
||||
static void info(Path p) {
|
||||
show("toString", p);
|
||||
show("Exists", Files.exists(p));
|
||||
show("RegularFile", Files.isRegularFile(p));
|
||||
show("Directory", Files.isDirectory(p));
|
||||
show("Absolute", p.isAbsolute());
|
||||
show("FileName", p.getFileName());
|
||||
show("Parent", p.getParent());
|
||||
show("Root", p.getRoot());
|
||||
show("toString:\n ", p);
|
||||
show("Exists: ", Files.exists(p));
|
||||
show("RegularFile: ", Files.isRegularFile(p));
|
||||
show("Directory: ", Files.isDirectory(p));
|
||||
show("Absolute: ", p.isAbsolute());
|
||||
show("FileName: ", p.getFileName());
|
||||
show("Parent: ", p.getParent());
|
||||
show("Root: ", p.getRoot());
|
||||
System.out.println("******************");
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
@ -37,15 +37,16 @@ public class PathInfo {
|
||||
System.out.println(e);
|
||||
}
|
||||
URI u = p.toUri();
|
||||
System.out.println("URI: " + u);
|
||||
System.out.println("URI:\n" + u);
|
||||
Path puri = Paths.get(u);
|
||||
System.out.println(Files.exists(puri));
|
||||
File f = ap.toFile(); // Don't be fooled
|
||||
}
|
||||
}
|
||||
/* Output:
|
||||
Windows 8.1
|
||||
toString: C:\path\to\nowhere\NoFile.txt
|
||||
Windows 10
|
||||
toString:
|
||||
C:\path\to\nowhere\NoFile.txt
|
||||
Exists: false
|
||||
RegularFile: false
|
||||
Directory: false
|
||||
@ -54,7 +55,8 @@ FileName: NoFile.txt
|
||||
Parent: C:\path\to\nowhere
|
||||
Root: C:\
|
||||
******************
|
||||
toString: PathInfo.java
|
||||
toString:
|
||||
PathInfo.java
|
||||
Exists: true
|
||||
RegularFile: true
|
||||
Directory: false
|
||||
@ -73,7 +75,8 @@ FileName: PathInfo.java
|
||||
Parent: C:\Git\OnJava8\ExtractedExamples\files
|
||||
Root: C:\
|
||||
******************
|
||||
toString: C:\Git\OnJava8\ExtractedExamples\files
|
||||
toString:
|
||||
C:\Git\OnJava8\ExtractedExamples\files
|
||||
Exists: true
|
||||
RegularFile: false
|
||||
Directory: true
|
||||
@ -92,7 +95,7 @@ FileName: PathInfo.java
|
||||
Parent: C:\Git\OnJava8\ExtractedExamples\files
|
||||
Root: C:\
|
||||
******************
|
||||
URI: file:///C:/Git/OnJava8/ExtractedExamples/files/Pat
|
||||
hInfo.java
|
||||
URI:
|
||||
file:///C:/Git/OnJava8/ExtractedExamples/files/PathInfo.java
|
||||
true
|
||||
*/
|
||||
|
@ -2,7 +2,6 @@
|
||||
// (c)2021 MindView LLC: see Copyright.txt
|
||||
// We make no guarantees that this code is fit for any purpose.
|
||||
// Visit http://OnJava8.com for more book information.
|
||||
import java.util.*;
|
||||
|
||||
interface Callable { // [1]
|
||||
void call(String s);
|
||||
|
@ -1 +0,0 @@
|
||||
Some text Some more
|
@ -1,25 +0,0 @@
|
||||
// references/ImmutableStrings.java
|
||||
// (c)2021 MindView LLC: see Copyright.txt
|
||||
// We make no guarantees that this code is fit for any purpose.
|
||||
// Visit http://OnJava8.com for more book information.
|
||||
// Demonstrating StringBuilder
|
||||
|
||||
public class ImmutableStrings {
|
||||
public static void main(String[] args) {
|
||||
String foo = "foo";
|
||||
String s = "abc" + foo + "def"
|
||||
+ Integer.toString(47);
|
||||
System.out.println(s);
|
||||
// The "equivalent" using StringBuilder:
|
||||
StringBuilder sb =
|
||||
new StringBuilder("abc"); // Creates String
|
||||
sb.append(foo);
|
||||
sb.append("def"); // Creates String
|
||||
sb.append(Integer.toString(47));
|
||||
System.out.println(sb);
|
||||
}
|
||||
}
|
||||
/* Output:
|
||||
abcfoodef47
|
||||
abcfoodef47
|
||||
*/
|
@ -1,22 +0,0 @@
|
||||
// references/Stringer.java
|
||||
// (c)2021 MindView LLC: see Copyright.txt
|
||||
// We make no guarantees that this code is fit for any purpose.
|
||||
// Visit http://OnJava8.com for more book information.
|
||||
|
||||
public class Stringer {
|
||||
public static String upcase(String s) {
|
||||
return s.toUpperCase();
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
String q = new String("howdy");
|
||||
System.out.println(q); // howdy
|
||||
String qq = upcase(q);
|
||||
System.out.println(qq); // HOWDY
|
||||
System.out.println(q); // howdy
|
||||
}
|
||||
}
|
||||
/* Output:
|
||||
howdy
|
||||
HOWDY
|
||||
howdy
|
||||
*/
|
Loading…
x
Reference in New Issue
Block a user