The Pro Java 7 NIO.2 book is all about the latest enhancements to the File NIO APIs added as part of Java 7. The book covers New Path and Paths API: A brief overview of the Path and Paths classes and how these can be used to represent a file/directory. Also explained are the different …
Reading file asynchronously in Java
We all are familiar with reading/writing file in a synchronous way. In Java 7 a new API was added to read/write the contents of the file asynchronously. The API is AsynchronousFileChannel. also read: Java 7.0 Tutorials New Features in Java 7.0 G1 Garbage Collector in Java 7.0 In this example lets look at how to …
How to use Socket API for creating Client-Server application in Java
In this example we make use of ServerSocketChannel and SocketChannel to create a simple Echo application where in the Server would print the data sent by the client. also read: Java Tutorials Java EE Tutorials Design Patterns Tutorials Java File IO Tutorials The code is explained with the required comments: and the client which connects …
How to use ByteBuffer in Java?
ByteBuffer API has been in Java since 1.4. The name itself suggests that these contain bytes of data. The data to be stored in the buffer can be Integer (int, long), Characters (char), Floating value (double), all these are converted into bytes before being stored in the buffer array. ByteBuffer can be of two types- …
Lazy Initialization, Singleton Pattern and Double Checked locking
Lazy Initialization Lazy Initialization is a technique where one postpones the instantiation of a object until its first use. In other words the instance of a class is created when its required to be used for the first time. The idea behind this is to avoid unnecessary instance creation. But there are concerns related to …
Visiting all the files and directories for a directory in Java using NIO2
At times we might want to search for some file in a directory traversing recursively into other directories with in that directory, I know getting the recursive program right at the first time is always a challenge. Or we might want to list all the contents of a directory. For all these operations the NIO2 …
Listing and filtering directory content using Java NIO2
The Files class provides a method- newDirectoryStream to get the Directory contents for a give path instance. There are other overloaded versions of newDirectoryStream method which take in filters to apply on the directory content. also read: Java 7.0 Tutorials New Features in Java 7.0 G1 Garbage Collector in Java 7.0 Listing all files in …
Playing with reduceLeft, reduceRight, foldLeft, foldRight API in Scala
In our previous post we saw in detail about the foreach. map, flatMap and collect methods in the Iterable trait. In this post we will look into detail about reduceLeft, reduceRight, foldLeft, foldRight methods of the Iterable trait. These methods are almost similar in the way the operate on the collection so it should be …