/r/java

Photograph via snooOG

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

Submit Text

Seek Programming Help

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.

Please seek help with Java programming in /r/Javahelp!

Subreddit rules!

Upvote good content, downvote spam, don't pollute the discussion with things that should be settled in the vote count.

  • Do not post tutorials here! These should go in /r/learnjava.
  • No programming help questions here! These should be posted in /r/javahelp
  • No surveys, no job offers! Such content will be removed without warning.

Where should I download Java?

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!

Related Sub-reddits:

Programming
Computer Science

CS Career Questions

Learn Programming
Java HelpSeek help here
Learn Java
Java Conference Videos
Java TIL
Java Examples
JavaFX
Oracle

JVM Languages

Clojure
Scala
Groovy
ColdFusion
Kotlin

Want to practice your coding?

DailyProgrammer
ProgrammingPrompts
ProgramBattles

List of useful Frameworks / Libraries / Software

Awesome Java (GIT)
Java Design Patterns

/r/java

349,475 Subscribers

9

NANOWAR OF STEEL - HelloWorld.java (Source Code Video)

2 Comments
2024/12/04
10:04 UTC

0

How are you glueing BE and FE?

26 Comments
2024/12/04
01:02 UTC

30

Default App Icon: Java's Marketing Mistake

I was packaging a modular java app using jpackage (what a great tool) and forgot to add the --icon option whereupon I got a .dmg package with that steaming cuppa Java logo. I didn't like it one bit, and when I searched for my feelings why, I had this maybe obvious epiphany: when you see an app with the default logo (duke or steaming cup), it's more likely to be a shoddy, half finished job than an app that bothered to put its own icon. That, to me, is a mistake. Every time one of these shoddy programs crashes, the end user mutters to themselves "that's Java crashing again".

Imo, there should be no default icon for java apps. Apps built in other languages don't slap default logos, why do we do it Java? It only makes the language/platform look like the worst of us

13 Comments
2024/12/03
20:17 UTC

3

Resources for SOAP

Hi all

I need help with SOAP. At my job I have been tasked to communicate with an API that is using SOAP. I do not know much about SOAP and am looking for some guidance here.

The project involves, getting a request from our frontend via REST, converting the JSON request to xml and sending the data to the external API, which then I need to handle the response.

I am looking for whatever resources in the Java ecosystem that can help me out here. What libraries or frameworks are recommend?

20 Comments
2024/12/03
17:22 UTC

7

Jakarta one 2024 is 7-7, December 3

I'm honestly don't see what they could cover for 12h, but it's live streaming at (https://jakartaone.org/2024/)

I don't know what time zone either. UTC-5 or UTC-8 probably.

2 Comments
2024/12/03
02:57 UTC

44

Is there no JEP or discussion for extension methods in 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.

91 Comments
2024/12/01
14:53 UTC

45

New team uses Java and Groovy interchangeably. Curious how common this is and whether my aversion is justified.

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.

62 Comments
2024/12/01
08:13 UTC

1

TypeSchema Reflection: A Java library to generate a TypeSchema specification from any DTO

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.

1 Comment
2024/11/30
12:20 UTC

27

"Batteries-included" Java web framework?

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.

53 Comments
2024/11/30
08:36 UTC

48

SPRING BOOT vs VERT.X

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!

88 Comments
2024/11/29
23:53 UTC

21

What framework for low volume task orchestration in my springboot application?

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:

  • Spring StateMachine: This seems lightweight and simple, but I’m unsure about its current state. It doesn’t seem to be very actively maintained.
  • Spring Batch: Easy to set up and lightweight, but I don’t really need a "batch" solution. It also adds some overhead I don’t need.
  • Flowable: This looks promising but the BPMN overhead feels like overkill for my use case. I’ve used Camunda before and liked it, but due to licensing, I won’t consider it.

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!

22 Comments
2024/11/29
22:33 UTC

30

What Is Dynamic Dispatch and Why It Matters

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!

36 Comments
2024/11/29
18:30 UTC

19

Are "constant Collections" optimised away by the compiler?

16 Comments
2024/11/29
16:13 UTC

29

Please help me remember the name of this interpreter/macro framework for Java

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).

24 Comments
2024/11/29
05:58 UTC

11

Efficient marshaling of primitive arrays

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?

18 Comments
2024/11/28
17:52 UTC

9

Best approach to port Jupyter notebook in Python to Java

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

9 Comments
2024/11/28
15:40 UTC

1

Best approach to port Jupyter notebook algorithm in Python to Java

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

3 Comments
2024/11/28
15:38 UTC

31

Introducing Kappa: OpenAPI-based request validation for Contract-first teams

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.

9 Comments
2024/11/28
12:20 UTC

31

What do you do w/o RxJava?

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?

67 Comments
2024/11/27
23:54 UTC

49

Kiwi: A non-opinionated Java bootstrapping configuration library

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 EZKV (its original name was just kvs).

EDIT https://github.com/jstachio/kiwi https://github.com/jstachio/ezkv

(project renamed based on feedback)

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!

22 Comments
2024/11/27
19:31 UTC

11

Excited to Share my updates for Gestalt - A Modular and Extensible Configuration Library for Java!

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

2 Comments
2024/11/27
17:56 UTC

0

Java code simplification tool

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?

12 Comments
2024/11/27
17:45 UTC

Back To Top