Java ExecutorService examples

This post will provide a brief description of the different types of ExecutorService available in java. This post will also include some Java ExecutorService examples. What is the ExecutorService: The executor service is provided by the java JDK because it helps simplifies the execution of asynchronous tasks. It provides a pool of threads and an API allowing you … Continue reading Java ExecutorService examples

Handle an exception thrown by a callable

In this post an example is provided to demonstrate how to handle an exception thrown by a Callable object. Handle exception thrown by callable:

A few points to note from the above code. A callable object which throws a RuntimeException, is passed into the submit() method. The result of the callable object is retrieved … Continue reading Handle an exception thrown by a callable

How to create a Thread in Java

In this post we will provide an example of how to create a thread in Java. A thread can be created by either extending the thread class or implementing the runnable interface. How to create a Thread in Java Example 1: Extending the Thread class.

The above class extends the Thread class and overrides … Continue reading How to create a Thread in Java

How to move a file in Java

In this post we will provide an example of how to move a file in Java. This example uses the standard java libraries so you will not need any external dependencies. How to move a file in Java: The example below uses the Files class which is available from Java 1.7 and above.

  … Continue reading How to move a file in Java

How to rename a file in Java

In this post we will provide an example of how to rename a file in Java. The example uses the standard libraries so no external dependencies will be needed. How to rename a file in Java:

As you can see from the example above its fairly straight forward to rename a file in Java. … Continue reading How to rename a file in Java

How to get file size in Java

In this post we will provide two examples on how to get file size in Java. How to get file size in Java Example 1: Using the Files class

Files.size() will return the size of the file you specified in bytes Example 2: Using the File class

The length() method on the file … Continue reading How to get file size in Java

How to delete a file in Java

In this post we will provide an example on how to delete a file in Java. This example requires no additional libraries we will use the builtin features of Java to delete a file. How to delete a file in Java

The above example shows you need to do the following: Construct the path … Continue reading How to delete a file in Java