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:

Negating a Predicate in Java

Java 8 predicate negate() returns a predicate that is the logical negation of this predicate. Java 11 introduced not() which is also the same.

Java Stream filter()

Learn to use Stream.filter(Predicate) method to traverse all the elements and filter all items which match a given condition through Predicate argument. 1. Stream filter() Method The stream() method syntax is as follows: Predicate is a functional interface and represents the condition to filter out the non-matching elements from the …

Java Stream forEachOrdered()

Learn to use Stream.forEachOrdered(Consumer action) method to traverse all the elements and performs an action for each element of this stream, in the encounter order of the stream if the stream has a defined encounter order.

Java Stream forEach()

Learn to use Stream forEach(Consumer action) method to traverse all the elements of stream and performs an action for each element of this stream.

Creating Streams in Java

Learn to create Streams of primitives and objects in Java using some most popular ways. We will learn to create finite as well as infinite streams.

Single Responsibility Principle

The single responsibility principle (SRP) states that a software component (in general, a class) must have one and only one responsibility.

State Design Pattern

The state pattern is a behavioral design pattern. According to GoF definition, a state allows an object to alter its behavior when its internal state changes. The object will appear to change its class. It can be drawn from above definition that there shall be a separate concrete class per …

Mediator Design Pattern

Mediator helps in establishing loosely coupled communication between objects and helps in reducing the direct references to each other.

Observer Design Pattern

According to the GoF definition, the observer pattern defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. It is also referred to as the publish-subscribe pattern. In the observer pattern, many observers (subscriber objects) observe a particular subject …

Memento Design Pattern

Memento design pattern is behavioral pattern and one of 23 design patterns discussed by Gang of Four. Memento pattern is used to restore state of an object to a previous state. It is also known as snapshot pattern. A memento is is like a restore point during the life cycle …

Iterator Design Pattern

An iterator design pattern provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation.

Proxy Design Pattern

According to GoF definition of proxy design pattern, a proxy object provide a surrogate or placeholder for another object to control access to it. A proxy is basically a substitute for an intended object which we create due to many reasons e.g. security reasons or cost associated with creating fully …

Flyweight Design Pattern

As per GoF definition, flyweight design pattern enables use sharing of objects to support large numbers of fine-grained objects efficiently. A flyweight is a shared object that can be used in multiple contexts simultaneously. The flyweight acts as an independent object in each context. 1. When to use flyweight design …

Facade Design Pattern

Facade design pattern provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.

Secure Random Number Generation in Java

If you’ve been developing software for a while, you know how to generate a random number and perhaps even securely with Java’s SecureRandom class. Unfortunately, generating secure random numbers is not as easy as simply using SecureRandom. In this java example, we’ve assembled a simple checklist to help you be …

Spring Boot, Mockito and JUnit 5 Example

Learn to write unit tests for the service layer of Spring boot applications using JUnit 5 and Mockito testing frameworks. We are using Spring Boot 3 in this demo. For Spring Boot applications, we only need to change the import statements, and everything should work automatically. 1. Maven The spring-boot-starter-test …

JMeter tutorial

Learn to perform load and performance testing for a web application in this step by step JMeter tutorial. This Jmeter example is intended for beginners who are trying to use the Jmeter for the first time.

Using ‘if-else’ Conditions with Java Streams

Learn to apply if-else logic in a Java 8 stream of elements to filter elements based on certain condition. The if-else condition can be applied using the lambda expressions in stream filter() function.

Java forEach()

Java forEach() is a utility function to iterate over a Collection (list, set or map) or Stream. It performs the specified Consumer action on each item in the Collection.

Union of Two Arrays in Java

Learn to find the union of two arrays in Java using HashSet and Stream APIs with easy-to-understand Java examples.

Intersection of Two Arrays in Java

Learn to find the intersection of two arrays in Java using HashSet and Stream API. An intersection contains the items present in both arrays.

Spring Boot Multi-Module Maven Project

Learn to create a spring boot project having multiple modules. The parent project will work as a container for base maven configurations. The child modules will be actual spring boot projects – inheriting the maven properties from the parent project. 1. Parent Spring Boot Project The parent project is single …

Maven Multi-Module Project using Eclipse

Learn how to create a multi-module maven project in eclipse IDE. In this maven tutorial, we will learn to create nested maven projects in Eclipse. 1. Multi-module Project Structure Let’s create a maven project having modules packaging ear, war and jar types. We are creating the structure of an enterprise …

Java Instance Initializer Block

Java instance initializers are the code blocks containing the instructions to run every time a new class instance is created in runtime.

Java Naming Conventions

Java naming conventions are sort of guidelines that application programmers are expected to follow to produce consistent and readable code throughout the application. If teams do not follow these conventions, they may collectively write an application code that is hard to read and difficult to understand. Always try to give …

Difference between this and super in Java

this and super are reserved keywords in Java. this refer to current instance of a class while super refer to the parent class of that class where super keyword is used.

Difference between final, finally and finalize in Java

In this Java tutorial, learn about difference between final, finally and finalize in detail. In short, final is a keyword, finally is a block and finalize is a method. They have their own very specific purpose in Java programs.

Java extends vs. implements

In Java, the extends keyword is used for extending a class or interface; and the implements keyword is used for implementing the interfaces.

Java instanceof Operator

Java instanceof (type comparison operator) is used to test if a specified variable is an instance of the specified class or interface

Java throw and throws Keywords

In Java exception handling, throw keyword is used to explicitly throw an exception from a method or constructor. And throws keyword is used to declare the list of exceptions that may be thrown by that method or constructor. 1. Throw Let us learn basic things about throw keyword before going …

Java synchronized keyword

Java synchronized keyword marks a block or method a critical section. A critical section is where one and only one thread is executing at any given time.

Java try catch finally

Java try catch finally blocks helps in writing the application code which may throw exceptions in runtime and gives us chance to recover from the exception.

Java boolean keyword

Java boolean keyword is used to declare a variable as a boolean type which represents only one of two possible values i.e. either true or false.

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.