Creating Embeddings with OpenAI, Saving Them in ChromaDB, and Searching Them with Java
In the realm of natural language processing (NLP), embeddings play a pivotal role in representing textual data in a numerical format that machine…
Practical tutorials for developers and sysadmins
85 guides
Practical Java walkthroughs, troubleshooting notes, and best practices.
Topic archive
Browse every Knowledge Basement article filed under Java.
In the realm of natural language processing (NLP), embeddings play a pivotal role in representing textual data in a numerical format that machine…
In Java, mutable members (variables whose values can change after object creation) should not be stored or returned directly from a class when…
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…
To create an application in Java for preventing stressful moments in life, we can integrate ChatGPT to provide users with helpful tips, techniques,…
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…
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…
AtomicStampedReference is a class in Java that provides atomic operations on a reference object along with a stamp or version number. It is…
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…
H2Database (or simply H2) is an open-source, lightweight, and fast relational database management system written in Java. It is a pure Java database…
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…
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…
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…
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…
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…
The removeIf() method is a default method introduced in Java 8 for the Collection interface. It is used to remove all elements from the collection…
The AutoCloseable interface is a functional interface introduced in Java 7 that defines a single method called close() . This interface is used to…
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…
Making methods final in Java can provide several benefits, including: Preventing method overriding: When a method is marked final , it cannot be…
Serializing and deserializing data in Java can introduce several security risks if not implemented properly. Here are some of the main risks: Remote…
In Java, a PreparedStatement is a feature of the JDBC API that allows you to execute parameterized SQL statements. A PreparedStatement is a…
Hystrix is a library created by Netflix that provides fault tolerance and latency tolerance for distributed systems. It is particularly useful in…
Distributed maps provide a way for applications to store and access data in a distributed environment, where the data is automatically distributed…
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…
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…
The diamond operator in Java, also known as the empty angle bracket (<>) syntax, was introduced in Java 7 and provides several benefits: Improved…
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…
In Java, annotations are a form of metadata that provide additional information about program elements such as classes, methods, fields, and…
The Java 8 Stream API is the best choice when it comes to working with collections. Here's an example of how to use it to perform filtering,…
Custom exceptions should be used when you want to handle specific error scenarios in your application that are not covered by the built-in exception…
Static variables and methods are shared among all instances of a class and can be accessed without creating an object of that class. While static…
A common bad practice in Java programming is not properly handling exceptions. Java has a robust exception handling mechanism, but not using it…
Using if statements to solve Java problems is not necessarily a bad idea, as if statements are a fundamental part of the language and are used…
Lambda expressions were introduced in Java 8, and they provide several benefits over traditional anonymous inner classes. Some of the benefits of…
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…
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…
In Java, access modifiers are keywords that determine the accessibility of classes, methods, and variables in an object-oriented program. There are…
Java is a cross-platform language, which means that Java applications can run on a variety of operating systems, including Linux and Windows. The…
The performance of PHP and Java can depend on a variety of factors, including the specific implementation, the hardware and software environment,…
There are several good security practices to follow when developing Java applications. Here are some of the most important ones: Keep your 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…
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…
There are several quick wins that can be achieved through refactoring Java code: Removing duplicate code: Duplicate code can make the codebase…
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…
In Java, objects can be classified as either mutable or immutable based on whether their state can be changed or not. A mutable object is one whose…
In Java, both Boolean and AtomicBoolean are used to represent Boolean values, but they have different characteristics and use cases. Boolean is a…
One common issue when writing JUnit tests is how to create a mock when the variable is an an interface / implementation or a casting. For example,…
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…
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…
Writing clean, easy-to-read code in Java is important for improving code readability, maintainability, and overall quality. Here are some tips for…
To some people obfuscating programming code, including Java, means: Job security. If no one can understand their code, they are irreplaceable.…
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,…
If for some reasons you have decided that you don't like Lombok any longer, you can follow these steps to remove it: Remove Lombok annotations from…
In programming, boilerplate refers to sections of code that are repeated in many places throughout a project or across multiple projects. This code…
Code analysis tools are software tools that analyze source code for potential issues, errors, and vulnerabilities. These tools can help developers…
A common dilemma while writing unit tests in Java is whether to use Mockito's when/thenReturn or doReturn/when stubbings. Both when/thenReturn and…
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…
Test driven development is the standard nowadays but sometimes somehow there appears a class before the test is written. This is especially true for…
OpenGPT is very popular lately. If you haven't heard about it yet, it is a language model developed by OpenAI that can generate human-like text…
One of the fastest ways to advance in Java programming is using SolarLint's IDE extension. It helps you avoid common problems and ensures your code…
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…
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…
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…
Hazelcast is an open source in-memory data grid. It is written in Java and naturally it is popular for Java applications but not only. In simple…
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…
Concurrency problems appear when your code is executed by more than one thread. Then, in contrast to a single-threaded execution, your code might…
Period, Duration and Instant are three different classes introduced since Java 8 to help us deal better with time. Period measures the time with…
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…
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,…
In order to use lambda expressions in Java 8, you need a functional interface. For most of your needs, you can use the already built ones in Java…
Generics in Java and especially such with upper and lower bounds can be confusing even though they are otherwise very useful. Here is an example…
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…
Being able to create an immutable object in Java is one of the most essential skills for any Java programmer. Such objects are needed when you want…
A functional interface is an interface that contains a single abstract method. It is used as the basis for lambda expressions in functional…
Another useful feature introduced since Java 8 is the possibility to use lambdas instead of anonymous classes. Here is an example: Imagine you have…
There is a relatively simple challenge to extend the vowels in a string . Here is a way to do it in Java 8: import java.util.function.Function;…
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.…
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…
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…
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…
Connecting to Elasticsearch and executing queries is generally considered easy. In fact, in many cases a simple curl query like this one is all you…
Using Maven to maintain and build your Java projects has a lot of advantages including automatically resolving dependencies, running tests and…
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,…
Referencing a child object to a variable of type parent in Java can be real confusing. Here is an example of two classes Person and Student and an…
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…
To parse time in Java, the most trouble-free and programatic way is using the parse method of the LocalTime class like this: import…