Home » Core Java (page 20)

Core Java

Logging System.out.println Results in a Log File Example

In Java the three main streams stdin (Standard Input), stdout (Standard Output), and stderr (Standard Output Error) are handled by default by System.in, Sytem.out, and System.err respectively. In this example, we will try to show how to redirect the System.out.println() to a log file using Log4j logging services. 1. Introduction Printing messages to the console is an integral part of ...

Read More »

JDBC DDL Example

Data Definition Language (DDL) is a unique set of SQL commands that lets you manipulate the structure of the database. In this article, we will try to show how the JDBC DDL mechanism can be applied to a Java application.               1. Introduction It might sound like its own programming language, but Data Definition ...

Read More »

JDBC Connection Pool Example

Connection pooling is a mechanism to create and maintain a collection of JDBC connection objects. The primary objective of maintaining the pool of connection object is to leverage re-usability and improve the overall performance of the application. In this article, we will try to show how connection pooling mechanism can be applied to a Java application. 1. Introduction JDBC stands ...

Read More »

JUnit doNothing Example

In this tutorial we shall show users the usage of doNothing method. This method is basically resides inside the Mockito framework and is not a part of the JUnit. 1. Introduction Many developers thought about the ways to test methods but do nothing about this. They might want to run the method only for the purpose of some other things ...

Read More »

JUnit Example for Spring Controller

In this example, we shall show users the usage of JUnit Spring Controller Example. There are many ways where we can test Spring controller. There is also a specific test framework, especially for Spring. Spring-Test is especially built for the Spring testing and we will be using it for the testing of the spring controller in our example below.   ...

Read More »

Java Nio FileChannel Example

The FileChannel is a Java Nio Channel implementation for working with a file. It facilitates reading, writing, mapping and manipulating a file. The examples in this tutorial will be demonstrated via test cases with no explicit Charset specified when encoding and decoding text from ByteBuffers.             1. Introduction The FileChannel has a rich hierarchy of interfaces extending to ...

Read More »

Xpath Unique/Distinct Value Example

In this article we will learn how to select a distinct value from an XML using XPath. We will use IntelliJ ans an IDE and will use Saxon API for XPATH evaluation. 1. Introduction XPath is a W3C recommendation and is a major element in the XSLT standard. It can be used to navigate through elements and attributes in an ...

Read More »

JUnit Temporary Folder Example

In this tutorial, we shall show users the usage of JUnit Temporary Folder. JUnit Temporary Folder Example is a simple example showing how we can use and why we should use this feature of the JUnit. Basic tutorials about JUnit can be found here.                  1. Introduction There are some scenarios where we ...

Read More »

Java 9 Functional Programming Tutorial

Hello, in this tutorial we will learn about the introduction to Functional Programming in Java 9. The idea behind this approach was to combine Haskell programming language in Java. Table Of Contents 1. Java 9 Functional Programming 1.1 All variables are final 1.2 Don’t use global variables (and forget about side effects) 1.3 Use functions as parameters 1.4 Lambda Expressions ...

Read More »

Java Nio Iterate Over Files in Directory

This example will demonstrate iterating over the files and directories recursively from a root directory. The example program will utilize some of the Java NIO features. Central to this example are the DirectoryStream, Filter, Path and Paths classes.                    1. Introduction Before diving into the example program an understanding of the 4 abstractions ...

Read More »