/r/java
News, Technical discussions, research papers and assorted things of interest related to the Java programming language
NO programming help, NO learning Java related questions, NO installing or downloading Java questions, NO JVM languages - Exclusively Java
These have separate subreddits - see below.
Upvote good content, downvote spam, don't pollute the discussion with things that should be settled in the vote count.
With the introduction of the new release cadence, many have asked where they should download Java, and if it is still free. To be clear, YES — Java is still free.
If you would like to download Java for free, you can get OpenJDK builds from the following vendors, among others:
Adoptium (formerly AdoptOpenJDK)
RedHat
Azul
Amazon
SAP
Liberica JDK
Dragonwell JDK
GraalVM (High performance JIT)
Oracle
Microsoft
Some vendors will be supporting releases for longer than six months. If you have any questions, please do not hesitate to ask them!
Learn Programming
Java Help ← Seek help here
Learn Java
Java Conference Videos
Java TIL
Java Examples
JavaFX
Oracle
/r/java
Hi. Unlike e.g. String templating which is being worked on, or pattern matching which is almost(?) done, I have seen any discussion on adding extension methods to Java. I know Lombok does have them, but are they really so unpopular within the decision maker community that it is not even on the table? What are some strong arguments against them? Shouldn't it be an "easier" feature, given that is is essentially only syntactic sugar at compile time? (Or is it?).
Many thanks.
Just joined a team that builds microservices with both Java (11) and Groovy for business logic. Some services are entirely one or the other, and some have a mixture of both.
####- The services in question are critical, high-volume, enterprise applications. Our build tool is Gradle.
####- There doesn't seem to be any guidance/guardrails in place regarding when/if to use one language over the other. It's up to the developer to choose.
####- Our company licenses the JDK.
I'm not a Java purist or fanboy. I use (and prefer) other languages for front-end word and side projects. Initially, I was excited to learn that team leadership grants us autonomy to use the tool we think is best. Having looked at the codebase however, it seems very haphazard.
Below are some concerns. Admittedly, I am not in the best position to make objective criticisms, as I am still new to programming with Groovy and it's possible that I am just reacting negatively to something unfamiliar/uncomfortable - which is why I'm making this post.
1.) In my very short time with Groovy, I am not seeing a massive syntactical improvement over newer versions of Java.
2.) The context shifting from one to the other adds mental load to the already expensive task of reading and understanding a codebase.
3.) As a dynamically typed language, Groovy IDE tooling isn't as helpful when writing. I waste a lot of time running the code and waiting for the runtime compilation to complain about errors.
4.) As a dynamically typed language, Groovy is always going to be slower than Java, even if that difference is very small.
5.) It seems wasteful to pay for a licensed JDK and not use one half of it (javac
). While I know everything becomes bytecode and most of the optimization is done by the JVM, I assume by using Apache's Groovy compiler instead of Java's, we're not getting the latest and greatest refinements.
6.) There isn't a discernible reason for the services which contain .groovy and .java classes. It seems that whenever a developer prefers Groovy over Java, they just create a src/main/groovy
folder and they implement their feature there. While I know joint compilation is a thing, this seems like an unnecessary complication which adds complexity and detracts from maintainability. My intuition is that a service should be one or the other.
Looking for some discussion about whether these complaints are merited or if I'm just being whiny. If the latter, interested in hearing about benefits to mixing and matching that I haven't considered, and perhaps some best practices.
Hi, I have just released a first version of the TypeSchema Reflection library. It helps to generate a TypeSchema specification based on any DTO using reflection. The TypeSchema specification is a language neutral JSON format to describe DTOs which then can be turned into many different target languages, which can help to re-use core data models in different environments, for example through TypeSchema you could share your Java backend models with a frontend team by generating TypeScript models.
Hi all!
I've done some Java web development in the past - mostly using Spring Boot, one project was a more classical JEE stack. I've always enjoyed using Java in the backend and would also like to pick it as my first choice for new projects.
However, I'm sort of missing a framework that allows for easy and quick prototyping. Things like authentication, basic user management (signups, password resets, etc.), an ORM, basic CRUD endpoints, etc. should already be included so I don't need to write that boilerplate code over and over again. Essentially, I'd like to be able to define a bunch of entities and then start writing application logic right away.
In other words, I'm looking for something like Django or Laravel, but in the Java ecosystem.
What probably comes closest is JHipster (even though not a "framework" by itself). Are there any other alternatives?
EDIT: Just had a look at JHipster again and it actually seems to have evolved quite a bit since I last used it! Especially this JDL Studio looks amazing. Maybe JHipster is indeed what I'm looking for.
Hello, everyone! I’m starting my journey as a back-end developer in Java, and I’m currently exploring Vert.x and Spring Boot. Although I don’t yet have solid professional experience with either, I’m looking for tips and advice from people with more expertise in the field.
I’m a big fan of performance and always strive to maximize efficiency in my projects, aiming for the best performance at the lowest cost. In all the benchmarks I’ve analyzed, Vert.x stands out significantly in terms of performance compared to Spring Boot (WebFlux). On average, it handles at least 50% more requests, which is impressive. Based solely on performance metrics, Vert.x seems to be the best option in the Java ecosystem, surpassing even Quarkus, Spring Boot (WebFlux/MVC), and others.
That said, I’d like to ask: What are your thoughts on Vert.x? Why is it still not widely adopted in the industry? What are its main drawbacks, aside from the added complexity of reactive programming?
Also, does it make sense to say that if Vert.x can handle at least 50% more requests than its competitors, it would theoretically lead to at least a 50% reduction in computing costs?
Thank you!
Hi all,
I’m working on a Spring Boot service that needs to handle task orchestration for file uploads. The workflow will be triggered by a REST call where a user provides one or more filenames. Before we upload the files, there are several steps—mostly HTTP calls to other backend systems—before we publish the file metadata to a queue for a worker to perform the actual upload. Afterward, we’ll clean up and inform the user. In total, I expect around 10 steps, and the volume will be low—just a few dozen per day. I expect the workflow to grow a bit with some (optional) steps in the future but not to much.
I’ve been looking at some solutions but am still undecided. Here’s what I’ve found so far:
Some solutions I came across (like Netflix Conductor and Apache Camel) seem too big for my needs.
Right now, I’m leaning toward Spring Batch because it’s easy to integrate into my Spring Boot app, and I only need a database for state persistence.
Has anyone worked with any of these tools for a similar use case? Any advice on which would be the best fit for a low-volume, straightforward task orchestration workflow?
Thanks for your thoughts!
In Java, any non-static call is a dynamic dispatch call, meaning the JVM decides at runtime which method to execute. While this is a core feature of the JVM, I’ve found that the overhead is actually significant.
In fact, by removing dynamic dispatch in my experiments, I observed an average 5% speedup in real-world applications. That’s equivalent to gaining half a CPU generation in performance.
I’ve been exploring the implications of this problem and am working on a new solution that I’m sharing in a series of posts. The first post explains the issue in detail and sets the stage for my benchmarks and proposed optimization in later parts.
The post is too long to share directly here, so here’s the link:
What is Dynamic Dispatch and Why It Matters
I’d love to hear your thoughts—have you encountered performance issues related to dynamic dispatch in your own projects? Let’s discuss!
Hey all. I'm trying and failing to remember the name of a framework or library for Java that was never really popular and fell out of fashion about 10 years ago.
If I remember right, it was a means of defining a grammar for a custom scripting language, which could then be used to add scripting or business logic in your custom defined programming language to extend enterprise applications.
I never used it myself, but heard mention of it a few times in capital markets applications. I don't know if user provided scripts would be compiled at compile time and run as plugins, compiled at run time, or interpreted.
I know that this is super vague but if anyone has any ideas or pointers about what it could be, if appreciate it.
To be clear, I'm not talking about JavaScript or stuff to run in a browser.
EDIT: Many thanks to all who answered with suggestions. Even though nobody said it, sheeting about the discussion triggered my memory. What I was trying to remember was Groovy and its Domain Specific Language. Almost 10 years ago, Groovy was in the top 20 of the TIOBE Index, but now it's not in the top 50. I don't know what kind of future it has (if any).
I've been working on a Kotlin multi-platform wrapper for ZLib, which has been a very stimulating project in its own right but not without its woes. For the Java implementation, I use Java FFI to wrap the host platform distribution of ZLib. Kotlin doesn't yet have a standard multiplatform IO API, so I rely on byte[]
rather than ByteBuffer
.
Panama copies arrays across the FFI boundary. While copying small arrays isn't a huge problem over the lifetime of an application, the overhead adds up to a sizable cost if allowed to run long enough.
I'd like to write up a JEP on the subject, so I'm asking the community here for some ideas. For example, one solution might be to introduce a new MemorySegment
that simply pins an array for as long as that segment is reachable. What strategies do you imagine would be ergonomic and in-line with the rest of Panama?
I am working on a project where I have developed with several people an “algorithm” using Jupyter Notebook in Python with Pandas, GeoPandas and other libraries, which is a language that the other members know and can use. This “algorithm” consumes data from a queue and databases and processes it to save the result in another database with the final results of the process.
Since we have a functional version of that algorithm, I have to develop it to an application that considers operational aspects of production applications such as CI/CD, monitoring, logging, etc. In other systems we use Java and Quarkus because it gives us many benefits in terms of performance and ease of implementing projects quickly. There are other parts of this project that already use Quarkus to capture data that is needed for this “algorithm”.
What approach would you take to port this algorithm to Java? Running the Jupyter notebook in production is out of the question. I have seen that there are dataframe libraries like DFLib.
I must consider in the future that this application is going to grow and the algorithm may change, so I must transfer those changes to the production version.
Thank you in advance for all your advice
I am working on a project where I have developed with several people an “algorithm” using Jupyter Notebook in Python with Pandas, GeoPandas and other libraries, which is a language that the other members know and can use. This “algorithm” consumes data from a queue and databases and processes it to save the result in another database with the final results of the process.
Since we have a functional version of that algorithm, I have to develop it to an application that considers operational aspects of production applications such as CI/CD, monitoring, logging, etc. In other systems we use Java and Quarkus because it gives us many benefits in terms of performance and ease of implementing projects quickly. There are other parts of this project that already use Quarkus to capture data that is needed for this “algorithm”.
What approach would you take to port this algorithm to Java? Running the Jupyter notebook in production is out of the question. I have seen that there are dataframe libraries like DFLib.
I must consider in the future that this application is going to grow and the algorithm may change, so I must transfer those changes to the production version.
Thank you in advance for all your advice
In the recent months I was working on a java library* which can be used to validate incoming HTTP requests against an OpenAPI description.
GitHub repo: https://github.com/erosb/kappa
It is useful for teams following a contract-first development approach, where the API design is agreed on between producer and consumer parties (like backend and frontend devs) before any implementation is done. Contract-first can come handy for catching API design issues early (missing endpoint, insufficient response structures), instead of developing an initial implementation, then retroactively (in several iterations) fixing it up to meet requirements.
Such back-and-forth can be largely mitigated by defining the API in advance and describing it in an OpenAPI yaml (or json) file.
Once the OpenAPI yaml is written, using Kappa, it is easy to validate HTTP requests against the defined API, in a servlet filter, so that invalid requests are caugth early and returned to the client, before any json mapping to Java POJOs happens.
This avoids relying on javax.validation annotations for request validation: instead of defining validation rules explicitly, the already existing rules defined in the OpenAPI file can be reused for run-time request validation. Moreover, JSON Schema is much more rich and expressive than validation annotations, letting us defining our expected request structures in more detail.
* More precisely, this is a permanent fork of the deprecated openapi4j library, with a replaced JSON Schema validator, aiming for OpenAPI 3.1 support.
I’m probably in the minority but I really like RxJava and the tools it gives you to handle asynchronous code and make the code a smidge more functional.
I was curious what do you do when you don’t have a toolkit like RxJava when you want to run a bunch of tasks simultaneously and then join them back? Basically, an Observable.zip function.
Do you do something like CompletableFuture.allOf() or create your own zip-like function with the java.util.concurrent.Flow api, or do you just use threads and join them?
Many many years ago (like 2010) before Spring Boot, Quarkus, Micronaut etc I wrote some configuration bootstrapping code for my company.
While Spring existed at the time it had a lot of problems with early initialization of configuration. Furthermore my company uses other stacks besides Spring.
Enter Kiwi (its original name was just kvs).
https://github.com/jstachio/kiwi
The library slowly evolved over time and one of its key niceties is that it allows developers and users to choose where the configuration comes from. It is a simple library that only cares about loading of key values (think properties) and not all the other configuration stuff (binding).
I was very hesitant on releasing this project precisely because it does not have an opinion. Also frankly loading up properties file is not exactly rocket science (or insert some AI) here.
0.1.0 is in Maven Central.
It is mostly documented. There are some missing modules I plan on adding particularly the Maven plugin which allows you to load properties using Kiwi for configuring build. I'm purposely not adding a lot of description here to see what folks reaction is to both the github page and doc.
Massive thanks to /u/thekingofsentries and u/rbygrave and hopefully soon Avaje Config will have something lighter and better!
For US folks Happy Thanksgiving!
Hi, everyone! Nine months ago, I introduced Gestalt, a Java-based configuration library designed to simplify managing application settings. I have been working hard at add some new and useful features, fixing bugs and making Gestalt more configurable.
Some of the major feature i have added are:
You can find Gestalt at https://github.com/gestalt-config/gestalt
I'm so tired of using Intellij's code refactoring and others such as openrewrite and sonarlint. These are great tools but do not solve the problem for code simplification. Any tool currently available which simplifies large clunky code? I could build this on my own as well as part of Intellij plugin marketplace. Basically it should not "suggest" but "execute" removal of dead code, merging of over modularized methods, merging of useless classes into one, merging of scattered enums into on enum file. Thoughts on this?
What's the best pdf generation library which is template based which looks good. I am using Spring Boot and Java 21
There are so many logging frameworks for Java. Pulling in deps (FOSS or otherwise) can mean you have that team's logger choice to deal with too :(
Logging Framework | Year of Creation | Pros | Cons |
---|---|---|---|
java.util.logging (JUL) | 2002 | - Built-in (no external dependencies) - Simple to use | - Limited features - Complex configuration |
Apache Log4j 2 | 2014 | - High performance - Asynchronous logging | - Larger footprint - Configuration complexity |
Logback | 2006 | - Modern design - Native SLF4J integration | - Documentation gaps - Complex configuration |
SLF4J | 2005 | - Abstraction layer - Flexibility | - Not a logger itself - Binding confusion |
Jakarta Commons Logging (JCL) | 2002 | - Abstraction layer - Automatic discovery | - ClassLoader issues - Unpredictable behavior? |
TinyLog | 2012 | - Lightweight - Easy to use | - Less established - Limited ecosystem |
java.lang.System.Logger | 2017 | - Built-in (no external dependencies) - Simple API | - Limited features - Less flexible configuration |
Google Flogger | 2014 | - High performance - Fluent API - Contextual logging | - Requires Java 8+ - Less widespread adoption |
bunyan-java-v2 | 2018 | - Structured JSON logging - Compatible with Bunyan format | - Less mature - Smaller community |
Log4j 2 with SLF4J | - Combines simplicity and advanced features - Flexibility | - Configuration complexity - Increased dependencies | |
Logback with SLF4J | - High performance - Advanced configuration | - Complex setup - Learning curve | |
java.util.logging to SLF4J Bridge | - Unified logging - Flexibility | - Additional layer - Performance overhead |
I personally wish for something that can participate in a unit testing agenda. That would be to capture output to strings for assertContains(..). It would also be a setup/configuration that was 100% Java (no config files), that supported a fresh setup/config per test method.
Logging Framework | Configurations Supported | Can Be Unit Tested (Reset Between Tests) |
---|---|---|
java.util.logging (JUL) | Properties file (logging.properties), programmatic configuration | Yes, but resetting is challenging |
Apache Log4j 2 | XML, JSON, YAML, properties files, programmatic configuration | Yes, supports resetting between tests |
Logback | XML, Groovy scripts, programmatic configuration | Yes, supports resetting between tests |
SLF4J | N/A (depends on underlying framework) | Depends on underlying framework |
Jakarta Commons Logging (JCL) | N/A (depends on underlying framework) | Depends on underlying framework |
TinyLog | Properties file (tinylog.properties), programmatic configuration | Yes, supports resetting between tests |
java.lang.System.Logger | Programmatic configuration, depends on System.LoggerFinder SPI | Yes, but resetting is challenging |
Google Flogger | Programmatic configuration, properties files | Yes, supports resetting between tests |
bunyan-java-v2 | JSON configuration, programmatic configuration | Yes, supports resetting between tests |
Log4j 2 with SLF4J | XML, JSON, YAML, properties files, programmatic configuration (via Log4j 2) | Yes, supports resetting between tests |
Logback with SLF4J | XML, Groovy scripts, programmatic configuration (via Logback) | Yes, supports resetting between tests |
java.util.logging to SLF4J Bridge | N/A (depends on underlying SLF4J implementation) | Depends on underlying framework |
What would you wish for?
Java devs! Made a tool that helps LLMs understand your project without eating up your token limit. Open source (MIT) and open to repo contributions from the community! It's like giving your LLM the cliff notes instead of the entire codebase. It creates about a 75% decrease in context window usage when informing the LLM of your project context. Come check it out.
https://github.com/brandondocusen/CntxtJV
Hi,
I’m a Java Spring Boot developer, and my workplace offers me the opportunity to attend any conference of my choosing, worldwide.
I’m looking for recommendations on conferences that are considered the best in the industry. What conferences are really up there about these days?
I’m already aware of events like Devoxx, JavaOne, and SpringOne, buti don't know how to compare them.
Which is considered the most "hype"? Any other options?
Thanks in advance for any suggestions!
I have released the final version Cabe 3.0.0. Changes since the release candidate are mainly documentation, and an updated help for the ClassPatcher command line tool.
If you missed the last post: Cabe will process your class files that are annotated witch JSpecify annotations and injects null checks into your code, either as standard assertions or throwing NullPointerExceptions.
If you use the standard configuration, you only need to add the plugin to your Gradle build script like this (example uses Kotlin DSL):
plugins {
id 'com.dua3.cabe'` version '3.0.0'
}
The standard configuration will use assertions for private API (private methods and methods of private classes that do not override a public method of another public class or interface. It will throw NullPointer exception for public methods and protected methods of public classes. This can be configured in your build file as well as null checks for method return values.
Make sure to understand how to use JSpecify to annotate your code.
If anything doesn't work, please open an issue on GitHub.
Should you also use the Badass JLink Plugin, make sure to update to version 3.1.1 which fixes a bug when a module declaration is annotated with @NullMarked
(or any other annotation).