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”

Using HMac Sha256 for Message Authentication (MAC) in Java

Secure message authentication using a MAC generated from a secret key with a password.

“There is some good in this world, and it’s worth fighting for.” ― J.R.R. Tolkien, The Two Towers

1. Introduction

A Message Authentication Code or a MAC provides a way to guarantee that a message (a byte array) has not been modified in transit. It is similar to a message digest to calculate a hash, but uses a secret key so that only a person with the secret key can verify the authenticity of the message.

Continue reading “Using HMac Sha256 for Message Authentication (MAC) in Java”

AES Encryption and Decryption Using a Password in Java

Encrypt a file using a password with strong AES security.

“My tastes are simple: I am easily satisfied with the best.”
― Winston S. Churchill

1. Introduction

In a previous article, we have explained how to use AES for encryption and decryption. After encryption, the AES key will need to be communicated to the receiver via a secure channel for decrypting the file.

Continue reading “AES Encryption and Decryption Using a Password in Java”

Encrypt and Sign a File Using RSA in Java

Securely exchange a file with another person using RSA for encryption and digital signature to ensure authentication.

“To acquire knowledge, one must study;
but to acquire wisdom, one must observe.”
― Marilyn Vos Savant

1. Introduction

We have previously covered using RSA for file encryption in java. We have also covered in a separate article the process of generating a digital signature for a file and verification using RSA. Let us now combine the two and develop a procedure for encrypting a file and generating a digital signature for exchange between two parties.

Continue reading “Encrypt and Sign a File Using RSA in Java”

Using AES With RSA for File Encryption and Decryption in Java

AES can be used for encrypting the file and RSA for encrypting the AES key.

“The secret of education lies in respecting the pupil.”
― Ralph Waldo Emerson

1. Introduction

In the previous part of this article, we covered the use of RSA for file encryption and decryption in java. Using RSA directly for file encryption will not work since it can only be used with small buffer sizes. In our particular case, with an RSA key size of 2048 bits, we ran into a limitation of a maximum of 245 bytes for the data size.

Continue reading “Using AES With RSA for File Encryption and Decryption in Java”