85 guides

Java tutorials

Practical Java walkthroughs, troubleshooting notes, and best practices.

Topic archive

All Java guides

Browse every Knowledge Basement article filed under Java.

Java

Quartz is a popular Java library for scheduling and managing jobs or tasks in applications. It allows you to schedule jobs to run at specific times…

4 min read 👁 Read guide →
Java

In Java, a Provider is a class or interface that provides a way to obtain or create instances of a specific type or service. It is a concept that is…

3 min read 👁 Read guide →
Java

In Java, a supplier is a functional interface from the Java.util.function package that represents a supplier of results. It does not take any…

3 min read 👁 Read guide →
Java

AtomicStampedReference is a class in Java that provides atomic operations on a reference object along with a stamp or version number. It is…

4 min read 👁 Read guide →
Java

Reflection in Java is a mechanism that allows you to inspect and modify the behavior of classes, methods, interfaces, and fields at runtime, even if…

4 min read 👁 Read guide →
Java

H2Database (or simply H2) is an open-source, lightweight, and fast relational database management system written in Java. It is a pure Java database…

4 min read 👁 Read guide →
Java

The static keyword is often overused in Java and this can lead to several risks, including: Tight Coupling: When you declare a member (variable or…

4 min read 👁 Read guide →
Java

Lambdas are a concise way to define and use functional interfaces in Java. Here are some guidelines on how to use lambdas effectively in Java: Know…

3 min read 👁 Read guide →
Java

In Java, a predicate is a functional interface from the java.util.function package that represents a function that takes in one argument and returns…

2 min read 👁 Read guide →
Java

In Maven, you can manage dependencies using a pom.xml file. Here's how you can add dependencies to your pom.xml file: Open your pom.xml file in a…

3 min read 👁 Read guide →
Java

Polymorphism in Java is a concept that allows objects of different classes to be treated as if they were of the same type. It allows you to write…

4 min read 👁 Read guide →
Java

In Java, a resource leak occurs when a program fails to properly release system resources after they are no longer needed. This can lead to a range…

6 min read 👁 Read guide →
Java

Making methods final in Java can provide several benefits, including: Preventing method overriding: When a method is marked final , it cannot be…

4 min read 👁 Read guide →
Java

Hystrix is a library created by Netflix that provides fault tolerance and latency tolerance for distributed systems. It is particularly useful in…

4 min read 👁 Read guide →
Java

Optional in Java is a container object that is used to represent the presence or absence of a value. It is a powerful tool that can help to avoid…

4 min read 👁 Read guide →
Java

In Java, generics provide a way to specify a type parameter for a class, method, or interface. A type parameter is a placeholder for a type that is…

3 min read 👁 Read guide →
Java

In Java, a method reference is a shorthand notation for referring to a method as a lambda expression. Method references provide a way to pass a…

3 min read 👁 Read guide →
Java

In Java, annotations are a form of metadata that provide additional information about program elements such as classes, methods, fields, and…

3 min read 👁 Read guide →
Java

Lambda expressions were introduced in Java 8, and they provide several benefits over traditional anonymous inner classes. Some of the benefits of…

2 min read 👁 Read guide →
Java

In Java, when you pass a parameter to a method, a copy of the value of that parameter is passed to the method, rather than the original object…

2 min read 👁 Read guide →
Java

In Java, varargs (variable-length arguments) are a feature that allows a method to accept an arbitrary number of arguments of the same type. The…

2 min read 👁 Read guide →
Java

Java is a cross-platform language, which means that Java applications can run on a variety of operating systems, including Linux and Windows. The…

2 min read 👁 Read guide →
Java

The performance of PHP and Java can depend on a variety of factors, including the specific implementation, the hardware and software environment,…

3 min read 👁 Read guide →
Java

There are several good security practices to follow when developing Java applications. Here are some of the most important ones: Keep your Java…

2 min read 👁 Read guide →
Java

SP (JavaServer Pages) pages are essentially HTML files with embedded Java code. To rewrite JSP pages in Java, you will need to extract the Java code…

3 min read 👁 Read guide →
Java

Orcacle releases new Java versions quite often and the current one is 19. However, plenty of production code is still running on older Java versions…

3 min read 👁 Read guide →
Java

There are several quick wins that can be achieved through refactoring Java code: Removing duplicate code: Duplicate code can make the codebase…

3 min read 👁 Read guide →
Java

Retry logic can be implemented in Java using various libraries and frameworks, but the general idea is to have a block of code that can potentially…

3 min read 👁 Read guide →
databases

In case you have wondered how to back up a MySQL database using Java code, here is one way to do it: import java.io.File; import…

2 min read 👁 Read guide →
Java

Console programs in Java can be easily written using System.out.println for output and Scanner for input. For example, here is a simple guessing…

2 min read 👁 Read guide →
Java

Writing clean, easy-to-read code in Java is important for improving code readability, maintainability, and overall quality. Here are some tips for…

3 min read 👁 Read guide →
Java

To some people obfuscating programming code, including Java, means: Job security. If no one can understand their code, they are irreplaceable.…

2 min read 👁 Read guide →
Java

If you still run your Java code with JVM 8, it's probably high time to move on and starting using a newer JVM version such as 11. For this reasons,…

2 min read 👁 Read guide →
Java

One of our latests posts was how to become a better programmer with the help of OpenGPT . Still, even without the help of AI, there are things you…

3 min read 👁 Read guide →
Java

Test driven development is the standard nowadays but sometimes somehow there appears a class before the test is written. This is especially true for…

2 min read 👁 Read guide →
Java

A common interview question for Java developers is to write some code inside a try / catch / finally statement so that the finally statement is not…

3 min read 👁 Read guide →
Java

A deadlock is a situation in computer programming where two or more processes are blocked, each waiting for the other to release a resource that…

3 min read 👁 Read guide →
Java

You might want to have more than one JDK on your Mac and run different programs with different JDK versions as it is with me. The easiest and safest…

2 min read 👁 Read guide →
Java

A Singleton class is a class of which only one instance exists. There is a need for such a design pattern for loggers, database connections and…

3 min read 👁 Read guide →
Java

Period, Duration and Instant are three different classes introduced since Java 8 to help us deal better with time. Period measures the time with…

1 min read 👁 Read guide →
Java

The Optional object type in Java was introduced with version 8 of Java. It is used when we want to express that a value might not be known (yet) or…

2 min read 👁 Read guide →
Java

Streams are a wonderful feature in Java allowing you to write clean, efficient and powerful code. If you haven't consumed the output of the stream,…

2 min read 👁 Read guide →
Java

The Telescoping anti-pattern is widely-spread, just like a virus. It starts with good intentions. For example, a class that has two properties like…

3 min read 👁 Read guide →
Java

A functional interface is an interface that contains a single abstract method. It is used as the basis for lambda expressions in functional…

1 min read 👁 Read guide →
Java

Another useful feature introduced since Java 8 is the possibility to use lambdas instead of anonymous classes. Here is an example: Imagine you have…

1 min read 👁 Read guide →
Java

Java 8 introduced streams, among other things, and one of my favourite features is the reduce() method. It combines a stream into a single method.…

1 min read 👁 Read guide →
Java

A friend asked me to help him with the following in Bash - delete all files but a whitelisted and use mix / max depth for directory traversal. It's…

1 min read 👁 Read guide →
Java

I am sure that there are plenty of honeypots for logging remote intruders but none yet has been done on Spring Boot. So I decided to write a simple…

2 min read 👁 Read guide →
Java

Mockito is a popular Java framework which comes to great help in Unit testing. In Unit testing it's important to get to a state where you can…

3 min read 👁 Read guide →
Java

Using Maven to maintain and build your Java projects has a lot of advantages including automatically resolving dependencies, running tests and…

5 min read 👁 Read guide →
Java

The best way to terminate a Java thread is with a switch such as a boolean property, .e.g abort . As soon as a condition is met, usually a timeout,…

1 min read 👁 Read guide →
Java

Working with time and date in Java is essential to any project. There are three important classes you can use: java.time.LocalTime - working only…

1 min read 👁 Read guide →
Java

To parse time in Java, the most trouble-free and programatic way is using the parse method of the LocalTime class like this: import…

1 min read 👁 Read guide →