• Complain

Kishori Sharan [Kishori Sharan] - Java Language Features: With Modules, Streams, Threads, I/O, and Lambda Expressions

Here you can read online Kishori Sharan [Kishori Sharan] - Java Language Features: With Modules, Streams, Threads, I/O, and Lambda Expressions full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2018, publisher: Apress, genre: Computer. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

Kishori Sharan [Kishori Sharan] Java Language Features: With Modules, Streams, Threads, I/O, and Lambda Expressions
  • Book:
    Java Language Features: With Modules, Streams, Threads, I/O, and Lambda Expressions
  • Author:
  • Publisher:
    Apress
  • Genre:
  • Year:
    2018
  • Rating:
    3 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 60
    • 1
    • 2
    • 3
    • 4
    • 5

Java Language Features: With Modules, Streams, Threads, I/O, and Lambda Expressions: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Java Language Features: With Modules, Streams, Threads, I/O, and Lambda Expressions" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Work with essential and advanced features of the Java programming language such as Java modules development, lambda expressions (closures), inner classes, threads, I/O, Collections, garbage collection, and more. Author Kishori Sharan provides over 50 diagrams and 290 complete programs to help you visualize and better understand the topics covered in this book.
Java Language Features, Second Edition starts with a series of chapters on the essential language features provided by Java, including annotations, reflection, and generics. These topics are then complemented by details of how to use lambda expressions, allowing you to build powerful and efficient Java programs. The chapter on threads follows this up and discusses everything from the very basic concepts of a thread to the most advanced topics such as synchronizers, the fork/join framework, and atomic variables.
This book contains unmatched coverage of Java NIO, the Stream API, the Path API, the FileVisitor API, the watch service, and asynchronous file I/O. With this in-depth knowledge, your data- and file-management programs will be able to take advantage of every feature of Javas powerful I/O framework and much more.
Additionally, three appendices are available for free via the Download Source Code on apress.com. These appendices will give you a head start on the most important features of Java 10 and the new Java versioning scheme.
What Youll Learn
  • Use essential and advanced features of the Java language
  • Code Java annotations and inner classes
  • Work with reflection, generics, and threads
  • Take advantage of the garbage collector
  • Manage streams with the Stream API

Who This Book Is For
Those new to Java programming and continues the learning Java journey; it is recommended that you read an introductory Java programming book first, such as Beginning Java Fundamentals, from Apress.

Kishori Sharan [Kishori Sharan]: author's other books


Who wrote Java Language Features: With Modules, Streams, Threads, I/O, and Lambda Expressions? Find out the surname, the name of the author of the book and a list of all author's works by series.

Java Language Features: With Modules, Streams, Threads, I/O, and Lambda Expressions — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Java Language Features: With Modules, Streams, Threads, I/O, and Lambda Expressions" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Kishori Sharan 2018
Kishori Sharan Java Language Features
10. New Input/Output 2
Kishori Sharan 1
(1)
Montgomery, Alabama, USA
In this chapter, you will learn:
  • What New Input/Output 2 is
  • How to work with a file system and file store
  • How to represent a platform-dependent abstract pathname using a Path
  • How to perform different file operations on a Path object
  • How to traverse a file tree
  • How to manage file attributes
  • How to watch a directory for changes
  • How to perform asynchronous file I/O operations
All example programs in this chapter are members of a jdojo.nio2 module, as declared in Listing . The JDK9 module system discourages including digits at the end of a module name. However, jdojo.nio2 (note the at the end of the name) is the best name that I can give to this module, as it contains examples for the New Input/Output 2 topic.
// module-info.java
module jdojo.nio2 {
exports com.jdojo.nio2;
}
Listing 10-1.
The Declaration of a jdojo.nio2 Module
What Is New Input/Output 2?
Java 7 introduced the New Input/Output 2 (NIO.2) API, which provides a new I/O API. It provides many features that were lacking in the original File I/O API. The features provided in NIO.2 are essential for working with a file system efficiently. It adds three packages to the Java class library: java.nio.file , java.nio.file.attribute , and java.nio.file.spi . The following are some of the new features of NIO.2:
  • It lets you deal with all file systems in a uniform way. The file system support provided by NIO.2 is extensible. You can use the default implementation for a file system or you can choose to implement your own file system.
  • It supports basic file operations (copy, move, and delete) on all file systems. It supports an atomic file move operation. It has improved exception handling support.
  • It has support for symbolic links. Whenever applicable, operations on a symbolic link are redirected to the target file.
  • One of the most important additions to NIO.2 is the support for accessing the attributes of file systems and files.
  • It lets you create a watch service to watch for any events on a directory such as adding a new file or a subdirectory, deleting a file, etc. When such an event occurs on the directory, your program receives a notification through the watch service.
  • It added an API that lets you walk through a file tree. You can perform a file operation on a node as you walk through the file tree.
  • It supports asynchronous I/O on network sockets and files.
  • It supports multicasting using a DatagramChannel .
Working with a File System
An object of the FileSystem class represents a file system in a Java program. A FileSystem object is used to perform two tasks:
  • To act as an interface between a Java program and a file system.
  • To act as a factory for creating many types of file system-related objects and services.
A FileSystem object is platform-dependent. You do not create an object of the FileSystem class directly. To obtain the default FileSystem object for a platform, you need to use the getDefault() static method of the FileSystems class as follows:
// Create the platform-specific default file system object
FileSystem fs = FileSystems.getDefault();
Typically, a file system consists of one or more file stores. A file store provides storage for files. The getFileStores() method of the FileSystem class returns an Iterable , which you can use to iterate over all file stores of a file system.
A file system may be represented differently on different platforms. One platform may represent a file system in a single hierarchy of files with one top-level root directory, whereas another may represent it in multiple hierarchies of files with multiple top-level directories. The getRootDirectories() method of the FileSystem class returns an Iterable , which can be used to iterate over paths to all top-level directories in the file system. I discuss the Path class in detail in the next section.
You can use the isReadOnly() method of the FileSystem object to test if it only allows read-only access to the file stores. You will work with the FileSystem class in subsequent sections to create the file system-related objects and services.
Listing demonstrates how to use a FileSystem object. It uses the default file system for the platform. The output shows the file system information when the program was run on Windows; you may get different output when you run the program.
// FileSystemTest.java
package com.jdojo.nio2;
import java.nio.file.FileStore;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.io.IOException;
public class FileSystemTest {
public static void main(String[] args) {
// Get the reference to the default file system
FileSystem fs = FileSystems.getDefault();
System.out.println("Read-only file system: " + fs.isReadOnly());
System.out.println("File name separator: " + fs.getSeparator());
System.out.println("\nAvailable file-stores are");
for (FileStore store : fs.getFileStores()) {
printDetails(store);
}
System.out.println("\nAvailable root directories are");
for (Path root : fs.getRootDirectories()) {
System.out.println(root);
}
}
public static void printDetails(FileStore store) {
try {
String desc = store.toString();
String type = store.type();
long totalSpace = store.getTotalSpace();
long unallocatedSpace = store.getUnallocatedSpace();
long availableSpace = store.getUsableSpace();
System.out.println(desc + ", Total: " + totalSpace
+ ", Unallocated: " + unallocatedSpace
+ ", Available: " + availableSpace);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Listing 10-2.
Retrieving Information About a File System
Read-only file system: false
File name separator: \
Available file-stores are
OS (C:), Total: 985563918336, Unallocated: 828183392256, Available: 828183392256
Available root directories are
C:\
E:\
Working with Paths
Typically, a file system stores objects (files, directories, symbolic links, etc.) in a hierarchical fashion. A file system uses one or more root nodes that serve as the root of the hierarchy. An object in a file system has a path, which is typically represented as a string, such as C:\home\test.txt on Windows, and /home/test.txt on UNIX-like operating systems. A path string may contain multiple components separated by a special character called a separator or delimiter . For example, the path C:\home\test.txt consists of three components: C:\ as the root, home as a directory, and test.txt as a file name. A backslash is a path separator on Windows. UNIX-like operating systems use a forward slash ( / ) as the path separator. Note that path representation is platform-dependent.
Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Java Language Features: With Modules, Streams, Threads, I/O, and Lambda Expressions»

Look at similar books to Java Language Features: With Modules, Streams, Threads, I/O, and Lambda Expressions. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Java Language Features: With Modules, Streams, Threads, I/O, and Lambda Expressions»

Discussion, reviews of the book Java Language Features: With Modules, Streams, Threads, I/O, and Lambda Expressions and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.