Jersey Client: How to Set Cookie in Request?

In this example, we will learn to set cookies into HTTP requests invoked by the Jersey client. This example makes use of Invocation.Builder for setting cookies into outgoing REST calls. 1. Syntax The following is the syntax to set a cookie in a Jersey client request using the Cookie class …

Multiple Inheritance in Java

Multiple inheritance is a feature of some object-oriented computer programming languages in which an object or class can inherit characteristics and behavior from more than one parent object or parent class.

Jersey REST API Security Example

In this Jersey rest security example, we will learn to secure Jersey REST APIs with basic authentication. This will make mandatory every user to provide username/password to authenticate into portal. Also, user must have certain level of role as well. I have extended this example from my other example created …

Jersey + Google Gson Example

This tutorial explains how to use google Gson with Jersey 2.x. There are some other java libraries also capable of doing this conversion e.g. MOXy, Jackson or JSONP; but Gson stands among very few which do not require any pre-annotated java classes OR sourcecode of java classes in any way. …

Jersey + JSONP Example

This tutorial explains how to use JSONP JSON provider with Jersey 2.x. JSONP is also auto-discoverable just like what we discussed in Jersey MOXy example. Table of Contents JSONP maven dependencies/changes REST API code Model bean changes Manually adding JsonProcessingFeature JSONP maven dependencies/changes JSONP media module is one of the …

Jersey + MOXy JSON Example

This tutorial explains how to use MOXy JSON feature with Jersey 2.x. MOXy is the default JSON-Binding Provider in Jersey 2.x. Though I still personally prefer Jackson over MOXy for performance reasons. Table of Contents MOXy maven dependencies/changes REST API code Model bean changes Manually adding MoxyJsonFeature Customize behavior using …

Jersey-quickstart-archetype Hello World Example

In this example, we will create a jersey RESTful API web application using jersey-quickstart-webapp maven archetype in eclipse. Table of Contents Install remote archetypes in eclipse Create new maven project using jersey-quickstart-webapp Generated Files Run The Application Install remote archetypes in eclipse The very first step before creating actual maven …

Jersey: Case-insensitive @Path URLs

By default in JAX-RS, ALL URLs specified in @Path annotations are case-sensitive. Learn to support case-insensitive URLs using regex and ResourceConfig.

Getting Started with Jersey Client

Jersey 2 client API finds inspiration in the proprietary Jersey 1.x Client API. In this Jersey client example, we will learn to build client API and invode different REST methods and consule the API results.

Jersey exception handling – Jersey ExceptionMapper Example

In Jersey ExceptionMapper example, we will learn to handle custom exceptions using ExceptionMapper interface while developing Jersey RESTful web services. For demo purpose, I am modifying the sourcecode written for jersey download file example. Table Of Contents 1. Jersey custom exception with ExceptionMapper 2. How to throw exception from REST …

Jersey – Ajax Multi-File Upload Example

Learn to use Ajax with JAX-RS webservices (Jersey used in example) to upload multiple files with single button click. Also look at form based file upload example and file download example as well. Table of Contents Jersey maven multipart dependency Add MultiPartFeature Write Upload REST API HTML/Ajax code Demo of …

Jersey file download example – StreamingOutput

In this Jersey file download example, we will learn to write a Jersey rest api which will be able to stream or download file (e.g. PDF/Excel/Text files) to requesting client. I will be using javax.ws.rs.core.StreamingOutput class for building this JAX-RS API. Table of Contents 1. REST API to stream file …

Implement Phonetic Search with Soundex Algorithm

Have you ever wondered how spell checkers, in any word editor, suggest you a list of probable other words whenever you have any spelling mistake?? This is done using phonetic search. Soundex is a phonetic algorithm for indexing names by sound, as pronounced in English. The goal is for homophones …

[Solved] org.hibernate.QueryException: Cannot mix named and positional parameters

1. Reason we might face this exception if we are trying to execute stored procedure using JPA 2.1 and hibernate’s entity manager, and we are not using the entity manager’s registerStoredProcedureParameter() correctly. Incorrect usage may look like below OR the one you have written. The exception will look like this: …

Hibernate @NamedStoredProcedureQuery

Learn to execute SQL stored procedures with the help of @NamedStoredProcedureQuery annotation from Jakarta persistence API that helps in specifying the name of a stored procedure, its parameters, and its result type. 1. Project Setup The support for executing stored procedures using @NamedStoredProcedureQuery has been added in JPA 2.1. So …

Static Import Statements in Java

The static import statements import the static fields and methods from a class and allow them to be used without the class reference.

Java Access Modifiers

Java provides four access modifiers to set access levels for fields, methods and constructors i.e. public, private, protected, and default.

Java Class and Object

Classes are the basic units of programming in the object-oriented paradigm. In this tutorial, learn to write Java class and how to create object in Java.

Java continue Keyword

The Java continue statement skips the current iteration of a for loop, while loop, or do-while loop and moves to the next iteration.

Java break Statement

The break keyword in Java is used to terminate for, while, or do-while loops. It may also be used to terminate a switch statement as well.

Java Do-while

Java do-while loop executes the statements in do block, and then evaluates a condition in the while block to check whether to repeat the execution.

Java while Loop

The while loop in Java continually executes a block of statements until a particular condition evaluates to true, else the loop terminates.

Java For-each Loop

Since Java 1.5, the for-each loop or enhanced for loop is a concise way to iterate over the elements of an array and a Collection.

Java For Loop

Java for-loop statement is used to iterate over the arrays or collections using a counter variable that is incremented after each iteration.

Java Switch Statement

Java switch statements help in providing multiple possible execution paths for a program. Java switch statements can be used in place of if-else statements to write more cleaner and concise code. Java switch statements have evolved over time. In this tutorial, we will learn about basic switch statement features and …

Java If-else

Java if-else statements help the program execute the blocks of code only if the specified test condition evaluates to either true or false.

Block Statements in Java

A block statement is a sequence of zero or more statements enclosed in braces. A block statement is generally used to group together several statements, so they can be used in a situation that requires you to use a single statement. 1. What is a Block Statement? Generally, a java …

Types of Statements in Java

A statement specifies an action in a Java program. For example, a statement may tell the add of values of x and y and assign their sum to the variable z. It then prints a message to the standard output or writes data to a file, etc. Java statements can …

Java Operators

Learn about available Java operators, and precedence order and understand their usages with examples. We will also try to understand when to use which operator and what to expect in the result. 1. Java Operators An operator is a symbol that performs a specific operation on one, two, or three …

Little-Endian and Big-Endian in Java

We must have heard the terms Little-Endian and Big-Endian many times in your engineering course. Let’s quickly recap the concept behind these words. 1. Little-Endian vs Big-Endian These two terms are related to the direction of bytes in a word within CPU architecture. Computer memory is referenced by addresses that …

Java Data Types with Examples

Learn about various data types in Java. Learn the differences between primitive datatypes and non-primitive datatypes (or reference datatypes). We will also learn about the data types sizes and best practices for using datatypes in Java. 1. How to Declare a Variable in Java? In Java, typically datatypes are associated …

Introduction to Java Programming Language

Java is concurrent, object-oriented, and intended to let application developers “write once, run anywhere” (WORA). Java is considered a fast language, almost as fast as languages like C and Rust, but it uses a lot of memory in comparison to these languages. 1. What is Java Programming Language Java is …

Java Primitive Datatypes and Ranges

All the values in Java are divided into two categories: reference types and primitive types. Learn about eight Java primitive data types.

Field / Property / Mixed Access Modes in JPA

In JPA, mapping information of an entity must be accessible to the ORM provider at runtime, so that when it is writing the data to storage, mapping information can be obtained from the entity instance. Similarly, when the entity state is loaded from the storage, the provider runtime must be …

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.