Java 8 Streams Map Examples

Convert one value to another in a Streams Operation

“Always and never are two words you should always remember never to use. ” ― Wendell Johnson

1. Introduction

Do you know about Java 8 Streams?

Java 8 streams is a very powerful facility for working with collections. What formerly required multiple lines of code and loops can now be accomplished with a single line of code. A part of Java 8 streams is the map() facility which can map one value to another in a stream. In this article, let us examine some common use cases where map() is useful.

Continue reading “Java 8 Streams Map Examples”

Add Javascript Scripting to your Java Application

Extend your application’s usability with a scripting interface

“Success is not how high you have climbed, but how you make a positive difference to the world.” ― Roy T. Bennett, The Light in the Heart

1. Introduction

A non-trivial program of any type has a reasonably complex interface and probably supports multiple options with several ways of controlling input and output. Invoking such a program can be done via the command line, but here we run into limitations of what you can do with the command line. You can probably add options for all supported settings and multiple modes for the program to run.

Continue reading “Add Javascript Scripting to your Java Application”

How to use Selenium for Driving the Chrome Browser

Learn how to automate tasks on the web using Selenium

“Indifference and neglect often do much more damage than outright dislike.” ― J.K. Rowling, Harry Potter and the Order of the Phoenix

1. Introduction

Selenium is a handy tool for controlling a web browser (such as Google Chrome) through a program. It allows you to automate tasks on a website by using the browser much the same way a human user would. Such automation can be useful for a variety of tasks including: regression testing of web applications, data extraction and more. In this article, we will learn how to use Selenium to drive the Chrome Browser.

Continue reading “How to use Selenium for Driving the Chrome Browser”

How to Search XML Using XQuery from Java

Use XQuery for more powerful XML search than is possible with XPath

“I guess there are never enough books.” ― John Steinbeck, A John Steinbeck Encyclopedia

1. Introduction

XPath offers an easy way to search an XML document using java. It is much more convenient than having to crawl through the document tree using the DOM API. XQuery builds on XPath and provides an SQL-like language for querying XML documents. It is also capable of updating and modifying the XML document, something which XPath cannot do. In this article, we present a beginner’s introduction to XQuery and how to use it from java.

Continue reading “How to Search XML Using XQuery from Java”

How to Install and Use Oracle XQuery Processor for Java

Use XQuery to Query, Update and Modify XML Documents

“Trees that are slow to grow bear the best fruit.” ― Molière

1. Introduction

As a Java Programmer, if you work in any way with XML, you should learn about XQuery and how to use it.

XQuery is a query language for XML. It is similar to XPath in that it uses the same or similar constructs to identify specific parts of an XML document.

Continue reading “How to Install and Use Oracle XQuery Processor for Java”

How to Pretty Print XML from Java?

Use XSL Tranformation to Pretty Print and XPath to remove indentation

“Time is a drug. Too much of it kills you.” ― Terry Pratchett, Small Gods

1. Introduction

XML is easiest to understand when it is properly indented to indicate the element hierarchy. However the extra space added to XML when it is transported increases file sizes. So it makes sense to remove all extraneous information from the document, including ignorable white space. This article will show you how to indent and pretty print an XML document.

Continue reading “How to Pretty Print XML from Java?”

Converting Between XML and JSON Using JAXB and Jackson

JAXB converts XML to Java and Jackson handles the Java to JSON Conversion

“You only live once, but if you do it right, once is enough.” ― Mae West

1. Introduction

In a previous article we covered the basics of using JAXB with its annotations to convert java objects to XML and back. In this article, we take a look at converting from XML to JSON and back, using jackson for the JSON conversion.

Continue reading “Converting Between XML and JSON Using JAXB and Jackson”

Using JAXB for Java to XML Conversion

Do you know how easy it is to convert java objects to and from XML using JAXB?

“Failure is the condiment that gives success its flavor.” ― Truman Capote

1. Introduction

JAXB (Java Architecture for XML Binding) offers a very easy path to integrate XML into your java application. Using JAXB you can easily serialize java objects as XML, and also load java objects from XML. Let us investigate JAXB for this purpose.

Continue reading “Using JAXB for Java to XML Conversion”

Using the SAX API to Parse XML in Java

Learn how to parse XML using the SAX API

“A word to the wise ain’t necessary, it’s the stupid ones who need advice.”
― Bill Cosby

1. Introduction

Java provides three APIs to parse XML in java: DOM, SAX and StAX. Each API fulfills different requirements, so it is important to know all three. The SAX API is useful particularly when you have large XML documents which you cannot loading using the DOM API. It is also useful when you have your own data structures and need to perform processing while parsing the XML. Let us get to know the SAX API.

Continue reading “Using the SAX API to Parse XML in Java”

Introduction to Date Time API in Java 8

Work with time and date using the date-time API, new in java 8.

“Never tell the truth to people who are not worthy of it.”
― Mark Twain

1. Introduction

Java 8 provides a new package for date, time and calendar calculations as an improvement over the earlier Date and Calendar classes. This is called the Date-Time API. Let us learn how to use this API.

Continue reading “Introduction to Date Time API in Java 8”