Home » Core Java

Core Java

Java 8 Array to Stream Example

java-logo

1. Introduction Official javadoc of java.util.stream.Stream states that it is “A sequence of elements supporting sequential and parallel aggregate operations”. And such every Stream is backed by a source which would provide the Stream with its “sequence of elements”. In Java, like most other programming languages, sequence of elements is generally provided via two constructs: (i) the java.util.Collection instances and ...

Read More »

Java Nio Read File Example

java-logo

With this example we are going to demonstrate how to use the Non-blocking I/O API, or NIO.2 API (NIO API) for short, to read the contents of a file. The examples in this article are compiled and run in a Mac OS unix environment. Please note that Java SE 8 is required to run the code in this article. 1. Introduction ...

Read More »

Mockito List Matcher Example

mockito-logo

In the Mockito Tutorial for Beginners, we saw a general overview of the use of Mockito framework for Java unit tests. In this example,we will see how are and how to use the Mockito Matchers for List elements. For this example, we will use: Java 1.7.0 Eclipse Mars 2, release 4.5.2. JUnit 4. Mockito 1.10.19. Tip You may skip project ...

Read More »

Mockito Test Case Example

mockito-logo

A unit test should test a class in isolation. Side effects from other classes or the system should be eliminated if possible. Mockito lets you write beautiful tests with a clean & simple API. In this example we will learn how to write a simple test case using Mockito. Tools and technologies used in this example are Java 1.8, Eclipse ...

Read More »

Java 8 Date and Time API Tutorial

java-logo

JDK 1.0 had java.util.Date class giving access to Java’s first Date API. However soon after its usage, it started to show cracks of problems on its brittle surface. It did not take any longer to realize that java.util.Date was not thread-safe! Table Of Contents 1 . Introduction 2. The new Date and Time API 2.1 LocalDate 2.2 LocalTime 2.3 Amalgamating ...

Read More »

Mockito: How to mock void method call

mockito-logo

A unit test should test a class in isolation. Side effects from other classes or the system should be eliminated if possible. Mockito lets you write beautiful tests with a clean & simple API. In this example we will learn how to mock a void method call using Mockito. Tools and technologies used in this example are Java 1.8, Eclipse ...

Read More »

JAVA Swing Menu Example

java-logo

1. Introduction A menu provides a space-saving way to let the user choose one of several options. Other components with which the user can make a one-of-many choices include, combo boxes, lists, radio buttons, spinners, and tool bars. Menus are unique in that, by convention, they aren’t placed with the other components in the UI. Instead, a menu usually appears ...

Read More »

Junit Unrooted Tests

junit-logo

1. Introduction One common mistake that developers make in creating JUnit is the version mismatch. Projects seems to be now keen on creating Junit test cases using the more advance annotation based (JUnit 4) rather than the older way (Extending TestCase class) of doing it. A common error or issue is when a developer loads/imports a JUnit 4 on the ...

Read More »

Trie tutorial in java

java-logo

In this tutorial, we are going to discuss a data structure called Trie. Trie is a tree structure representing words. It could be used for implementing dictionary or spell checker. The following tutorial is implemented in java using junit 4.12 for unit test. 1. Introduction to Trie Trie is an ordered tree structure which takes advantage of the structure of the keys ...

Read More »

Test-Driven Development With Mockito

mockito-logo

In this example we will learn how to do a Test Driven Development (TDD) using Mockito. A unit test should test a class in isolation. Side effects from other classes or the system should be eliminated if possible. Mockito lets you write beautiful tests with a clean & simple API. Tools and technologies used in this example are Java 1.8, ...

Read More »

Want to take your Java skills to the next level?

Grab our programming books for FREE!

Here are some of the eBooks you will get:

  • Advanced Java Guide
  • Java Design Patterns
  • JMeter Tutorial
  • Java 8 Features Tutorial
  • JUnit Tutorial
  • JSF Programming Cookbook
  • Java Concurrency Essentials