Administrator

Lokesh Gupta

A fun-loving family man, passionate about computers and problem-solving, with over 15 years of experience in Java and related technologies. An avid Sci-Fi movie enthusiast and a fan of Christopher Nolan and Quentin Tarantino.

Website: https://howtodoinjava.com

Github: https://github.com/lokeshgupta1981/

Twitter: @HowToDoInJAVA

LinkedIn: https://www.linkedin.com/in/lokeshgupta1981/

My Articles:

Java Builder Pattern: Build Complex Objects Efficiently

The builder pattern, as the name implies, is an alternative way to construct complex objects. This pattern should be used when we want to build different immutable objects using the same object-building process. 1. The GoF Builder Pattern Before starting the discussion, I want to make it clear that the …

Java Base64 Encode and Decode Example

Java 8 introduced ‘java.util.Base64‘ utility class that provides built-in support for performing base64 encoding and decoding operations as specified in RFC 4648 and RFC 2045. Let us explore Base64 encode and decode processes with various usecases with examples. 1. What is Base64? Base64 is a binary-to-text encoding scheme that converts …

Java Read a File Line by Line

In this Java tutorial, we will learn to read a text file line-by-line methods such as Streams or FileReader. We will also learn to iterate through lines and filter the file content based on some conditions. 1. Files.lines() – Stream through Lines of a File in Java 8 The Files.lines() …

Java Exact Arithmetic Operations Support in Math Class

Java 8 has brought many awesome features for java developers. Some of them I have already described in Comparator changes, Streams examples, Internal vs. external iterations, predicates, functional interfaces, default methods, lambda expressions and date and time API changes. All above changes were related to lambda expressions, which is the …

Java String.join()

Since Java 8, we can use String.join() method to concatenate strings with a specified delimiter. For advanced usages, use StringJoiner class.

Real Java Interview Questions asked in Oracle

Sreenath Ravva, one of the readers of HowToDoInJava, has appeared in an interview in Oracle for a position in the Oracle Enterprise Manager product. The below-listed questions were shared by him so that I can share them with all of you, in hope that it will benefit few of us …

Java Comparator with Lambda

Learn to create a Comparator instance with lambda expressions, method references and chaining multiple comparators for complex comparisons.

Internal vs. External Iteration in Java

Learn the difference between internal iteration and external iteration in Java with examples. 1. External Iteration Till Java 7, the collections framework relied on the concept of external iteration where the Collection provides a means to enumerate its elements by implementing the Iterator interface. The clients use the iterator to …

Functional Interfaces in Java

Introduced in Java 8, a functional interface is simply an interface that has exactly one abstract method. Learn more about functional interfaces in this tutorial.

Java 8 Predicate Example

Java Predicates are boolean-valued statements that may be true or false depending on the test argument. Predicates are used to filter Streams.

Java Default Methods Tutorial

In previous post, we learned about Lambda expressions and functional interfaces. Now, let’s move on the discussion and talk about another related feature i.e. default methods. Well, this is truly revolutionary for java developers. Till java 7, we have learned a lot of things about interfaces and all those things …

Lambda Expressions in Java

Lambda expressions are known to many of us who have worked on advanced languages like Scala. The term “lambda” has its origin in Lambda calculus that uses the Greek letter lambda (λ) to denote a function abstraction. Lambda expressions were introduced to Java as part of Java 8 release. 1. What are …

Maven BOM: Bill Of Materials Dependency

To solve the version mismatch issue, you can use the concept of a “bill of materials” (BOM) dependency. A BOM dependency keeps track of version numbers and ensures that all dependencies (both direct and transitive) are at the same version. 1. Why do we need the BOM file? If you …

Spring Method Security with Protect-Pointcut

Spring Method Security with Protect-Pointcut is a mechanism to apply security at the method level based on AOP-style expressions (pointcuts). This allows the Spring security configuration to be segregated from the application code.

Spring version-less schema for latest version

If you have worked on Spring framework projects, then you must have seen spring context configuration files (e.g. applicationContext.xml) where in header you specify the schema references (.xsd) for various spring modules. In schema references, we mention the xml namespace and as well as schema version number. Well specifying schema …

Spring AbstractRoutingDataSource Example

AbstractRoutingDataSource is a very useful feature if we have a design which permits multiple databases based on certain criteria which may change for each user request. An example can be when we can use a particular database when the user belongs to a certain locale and switch to another locale …

Java Standard IO vs New IO

Java New input/output (NIO) was introduced with JDK 1.4. Picking up where Standard IO leaves, NIO provides high-speed, block-oriented IO to Java library. By defining classes to hold data, and by processing that data in blocks, NIO takes advantage of low-level optimizations in a way that the java.io package could …

[SOLVED] java.lang.NoClassDefFoundError: Lorg/hibernate/cache/CacheProvider

If you are trying to setup your project/ or adding dependency for hibernate 4 then you might face this error in your server logs. Stack-trace will be looking like this: Solution: Reason is that you have incompatible jar’s versions in your application classpath. To resolve this issue, make sure you …

Java Checked vs Unchecked Exceptions

Learn the difference between checked vs unchecked exceptions in Java, with simple explanations and examples. Learn Java exception handling best practices.

Java SWT Splash Window Example

Learn to create a splash window using the Java SWT toolkit for Windows applications that need a delay during application loading and initialization.

Usage of class sun.misc.Unsafe

This post is next update in sequence of discussions regarding little known features of java. Please subscribe through email to get updated when next discussion goes live. And do not forget to express your views in comments section. Java is a safe programming language and prevents programmer from doing a …

Guide to Java SerialVersionUID

Java SerialVersionUID example. Learn to create generate serialVersionUID for classes to be serialized. Learn to change serialversionuid correctly.

How does a Web Servers Work?

Today the line between “app server” and “web server” is fuzzy. But people continue to use the terms differently, primarily for emphasis.

Decorator Pattern

In software engineering, the decorator design pattern is used to add additional features or behaviors to a particular instance of a class without modifying the other instances of the same class. The decorator pattern is often useful for adhering to the Single Responsibility Principle, as it allows functionality to be …

Visitor Design Pattern Example

Design patterns are used to solve the problems which occur in a pattern, we all know that, right? Also we know that behavioral design patterns are design patterns that identify common communication patterns between objects. One of such behavioral patterns is visitor pattern, which we are going to learn about …

JavaScript: Correct way to define global variables

We know that what global variables or constants are, these are fields which are accessible application wide. In java, it is done usually done using defining “public static” fields. Here by adding final keyword, we can change the global variable to global constant. So easy, right? But what about javascript? …

Why are Strings Immutable in Java?

The immutable strings help in achieving the required data safety and performance in a Java application with help of underlying string pool.

Spring Security Siteminder Pre-authentication Example

So far we have learned about securing spring application using login form based security, custom user details security and many more such security related concepts. In this post, I am giving an example of scenario where use is already authenticated via any third party application or tool e.g. site minder …

RESTEasy – Enable Gzip Compression Content Encoding

JAX-RS Resteasy has automatic GZIP decompression support. If the client framework or a JAX-RS service receives a message body with a Content-Encoding of “gzip”, it will automatically decompress it. The client framework automatically sets the Accept-Encoding header to be “gzip, deflate”. So you do not have to set this header …

JAX-RS 2.0 RESTEasy 3.0.2.Final Client API example

JAX-RS 2.0 has brought lots of improvement over previous version. One of major improvement is client API which was completely missing in JAX-RS 1.0. While it was easy to write a portable JAX-RS service, each JAX-RS implementation defined their own proprietary API. JAX-RS 2.0 fills in this gap with a …

[SOLVED] java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder

If you are using RESTEasy 3.x.y which has been support for JAX-RS 2.0, and you are trying to write RESTEasy client then you can face this exception. Full stack trace might look like this: Exception in thread “main” java.lang.RuntimeException: java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:103) at test.jaxrs2.Demo_JAXRS_2_Example.main(Demo_JAXRS_2_Example.java:14) Caused by: java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder at …

JAXB: Marshal / Unmarshal a Map in Java

We know that JAXB(Java Architecture for XML Binding) allows Java developers to map Java classes to XML representations. JAXB provides two main features: the ability to marshal Java objects into XML and the inverse, i.e. to unmarshal XML back into Java objects. JAXB mostly is used while implementing webservices or …

JAXB AnnotationsException: 3 counts of IllegalAnnotationExceptions

This exception occurs when you are using JAXB to marshal a Java object (collection type) to xml format. The stack trace looks like this in case of Lists. OR in the case of Maps. Exception in thread "main" com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 3 counts of IllegalAnnotationExceptions java.util.Map is an interface, and JAXB can't …

Securing REST APIs with RESTEasy Filter

Learn to use RESTEasy ContainerRequestFilter to create security filter which is able to to perform authentication and authorization on RESTEasy based web applications.

Java View Bytecode of a Class File

Java compiler rearranges the statements we write in a Java program for performance improvements. Learn to generate the byte code for a class file to see how they have been rearranged.

Java CountDownLatch with Example

Learn the basics of CountDownLatch and how to use it in real-life applications, its methods and use it to control the flow of application.

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.