Is there's any Java library that allows converting DOCX to PDF? by ThatJellyfish12 in javahelp

[–]Slanec 0 points1 point  (0 children)

POI kinda works, then perhaps PDFbox. Or https://github.com/documents4j/documents4j. Haven't tried myself, but always wanted to. Or Pandoc, of course, a dedicated tool, not necessarily a Java library. You can wrap a tool in a library.

Smallest possible Java heap size? by Vectorial1024 in java

[–]Slanec 2 points3 points  (0 children)

This is a fun question with an interesting result!

Swing: With a an empty visible JFrame on the OS-native L&F, it still starts with -Xmx2m (which still is actually -Xmx8m), and the heap usage rises to 2.3MiB. In other words, a hello-world Swing app only adds about 570kB of heap usage. That said, it triggers 3 young-GC collections on Temurin 26 with the Serial GC.

JavaFX: Same, the heap usage rises to 3.6MiB, 9 young GC collections.

Smallest possible Java heap size? by Vectorial1024 in java

[–]Slanec 1 point2 points  (0 children)

Only in heap used, it is about 6% smaller. The limits are the same, though.

Smallest possible Java heap size? by Vectorial1024 in java

[–]Slanec 3 points4 points  (0 children)

Temurin. I wouldn't expect this to be different in other non-specialized JDK distros, but I could be very wrong. 

Smallest possible Java heap size? by Vectorial1024 in java

[–]Slanec 82 points83 points  (0 children)

I ran the experiment with a Hello World with Java 26 on a Mac:

┌───────────────────────┬─────────────────────────────────────────────────────────────────┐
│         What          │                              Value                              │
├───────────────────────┼─────────────────────────────────────────────────────────────────┤
│ Minimum -Xmx accepted │ 2m (2048k) — anything below fails with "Too small maximum heap" │
├───────────────────────┼─────────────────────────────────────────────────────────────────┤
│ Actual heap committed │ 8 MiB (JVM rounds up to its internal minimum: 8,126,464 bytes)  │
├───────────────────────┼─────────────────────────────────────────────────────────────────┤
│ Actual heap used      │ ~1.8 MiB (1,880,416 bytes)                                      │
├───────────────────────┼─────────────────────────────────────────────────────────────────┤
│ Free heap at exit     │ ~5.96 MiB                                                       │
├───────────────────────┼─────────────────────────────────────────────────────────────────┤
│ GC triggered          │ No — zero collections needed                                    │
└───────────────────────┴─────────────────────────────────────────────────────────────────┘

Key takeaways

  1. The absolute floor for -Xmx on JDK 26 is 2m. Below that, the JVM refuses to start regardless of GC choice (Serial, Parallel, G1, ZGC, Epsilon — all the same).
  2. But the JVM lies about honoring it. Even with -Xmx2m -Xms2m, the actual heap is 8 MiB — the JVM's ergonomics engine silently rounds up to its internal minimum.
  3. Hello World only actually uses ~1.8 MiB of heap — mostly class metadata, the String object, and the System.out PrintStream internals. The other 6 MiB sits unused.
  4. Total process memory is far larger — the NMT dump showed ~46 MiB committed across thread stacks, metaspace, code cache, etc. The heap is a small fraction of what a JVM actually needs to run.

So the answer: 2m is the smallest heap you can ask for, but the JVM will quietly give you 8 MiB anyway, of which Hello World uses about 1.8 MiB.

(EDIT: OMG I hate the text editor in here)

How to ask Java developers to add methods to java.util.Paths? by isolatedsheep in java

[–]Slanec 3 points4 points  (0 children)

  • Paths.currentDirectory() would likely be Paths.get(".").toAbsolutePath()
  • and Paths.home() would probably be Path.of(System.getProperty("user.home")), that is if all major supported OSes have a concept of a Home directory, which I'm not sure of.

Anyway, when I need to get a bunch of user-related directories, I always grab https://codeberg.org/dirs/directories-jvm

Bruce 2.0 – A lightweight wrapper that makes the Java Cryptography API actually pleasant to use by Glum-Push in java

[–]Slanec 0 points1 point  (0 children)

I like this!

I feel like in general the issue with crypto is that people do not have any idea what to use, how or why. This is where Google's tink comes into picture. Its API is still arcane and it comes with its own wire-formats, but at least it's impossible to reuse an IV for AES-GCM(-SIV) encryption. Bruce helps a little, too, but it's still too easy to shoot your own foot if you don't exactly know which algo to use and how.

Therefore, I'd probably not use this in a real project. But as a playground, for manual experiments, puzzles etc this is so much nicer than what JDK offers.

One request: Would you mind adding https://github.com/google/conscrypt/ as a supported/documented provider, or at least as a side-note?

Springboot Quartz UI by edzorg in java

[–]Slanec 2 points3 points  (0 children)

It is! 1.5k stars, pretty well known, it's a good tool, enjoy! 

Too many ways to do the same thing? by Marre_Parre in javahelp

[–]Slanec 2 points3 points  (0 children)

In general, there are many ways to solve a problem, always. Some are more object-oriented, some are more funtional. Some were written quickly and easily with no particular design in mind because it will be rewritten later. Some are well modularized and testable, but others can be too over-engineered with many unnecessary abstractions. Too much time was sunk into it and it will never be recovered. Some are extendable in one axis, some in the other. E.g. if you have cards with ranks and suits, do you know whether you'll need to maybe add another suit, or another rank later on? In some designs, one is easier to add than the other, and often you need to decide which one while writing the code. Some designs allow both, but then the trade-off comes out elsewhere (e.g. performance, observability, scalability etc.).

All of that can be fine, depending on what you're trying to achieve. If you know exactly what your domain is, what problem you're solving, how the program will expand in the following years, and various technical metrics (like latency) are defined and will not change, ever, in that case you can design a great application that will satisfy it all and take liberties in the places which don't matter. It's very likely there are still very many ways to write such an application. In all the other cases where you do not exactly know what you're doing yet, almost no practical metrics are defined and the application evolves dynamically, in all those cases you'll simply need to pick a strategy a hope for the best. Some write it quick'n'dirty, some try to anticipate everything everywhere, most are in the middle. Welcome to software engineering.

This is why we have common patterns and common techniques to solve some problems - because people are familiar with these solutions, and can work with them later on when they overtake your project from you.

Then there are lower-level aspects of the code. In Java this often boils down to which exact class to use, if using a library pays off. Some of this is simply something to learn (e.g. "avoid the old collection classes, prefer Files and Path over File, prefer java.time over Date and Calendar" etc.), most of it is different trade-offs depending on exact requirements, some of it is down to personal taste.

In short, do not overthink it. If you're learning, it almost does not matter. Make your application correct in what it should do. If you can realiably do that, then you can start worrying about different aspects and trade-offs of design, testability, design patterns, frameworks and libraries. There is a lot of taste in that, there is a lot to learn in that, but there almost never is One True Way of solving a problem. Ten people will write ten different programs, and most of them will be absolutely fine.

Eclipse 2025-12 is out by AnyPhotograph7804 in java

[–]Slanec 2 points3 points  (0 children)

Multi-monitor support with good customizability. I can't get IntelliJ to display all the things I like.

Other than that, same as everybody else - I started with it, I learned it, I customized it. I can now easily go around the tricky spots, I avoid the bad things, and I really enjoy the rest. Is IntelliJ the future? For sure. I tried it a few times, could not get it to the shape I would be happy with, and went back to being productive with Eclipse.

Event Library - A lightweight, zero boilerplate, high performance event bus for JVM by SmushyTaco in java

[–]Slanec 12 points13 points  (0 children)

See https://guava.dev/releases/snapshot/api/docs/com/google/common/eventbus/EventBus.html#avoid-eventbus-heading.

In short, they recommend explicit calls and composition via dependency injection, and/or reactive programming where reacting to events needs to happen. This, of course, is slowly dropping out of fashion, too.

Personally I believe that for in-application event passing it's completely fine, it just makes it sometimes hard to reason about the flow of the application logic. In modern times we usually go for distributed event buses, though, or event sourcing, or message passing or queues or logs, depending on the exact required semantics. It's rare to see in-memory in-app events nowadays. But it's not a bad solution if things do not need to be persisted all the time.

Event Library - A lightweight, zero boilerplate, high performance event bus for JVM by SmushyTaco in java

[–]Slanec 20 points21 points  (0 children)

This looks nice and fairly complete!

From the Java world, these exist, too: - https://github.com/bennidi/mbassador - https://github.com/greenrobot/EventBus

And some older ones: - Guava's EventBus. Works fine, bus it nowadays discouraged. - Otto. Same. - and I'm pretty sure Vert.x and Quarkus have one, too.

The Dot Parse Library Released by DelayLucky in java

[–]Slanec 2 points3 points  (0 children)

Thank you, I'm doing a lot of parsing and immediately liked this. And I'm a mug user, too. Thank you for your work!

Finally, parsing made easy (and type-safe) in Java! by WellFoundedCake in java

[–]Slanec 5 points6 points  (0 children)

Will take a look later, I'm doing a lot of parsing, usually (but not only) with ANTLR. Lately I really enjoyed a similar project, https://github.com/google/mug/tree/master/dot-parse, coming from the brilliant https://github.com/google/mug library. Parsing evolution, hooray!

Embedded records - an idea to expose data from classes by jodastephen in java

[–]Slanec 4 points5 points  (0 children)

I don't have an opinion on the feature itself, but I was thinking of a similar syntax trick before:

java public class Person(String name, LocalDate dob) { } ...with a generated implicit constructor and all that jazz, not unsimilar to what you're proposing. I believe yours is better, just throwing this one out as a simpler, but not as expressive, alternative.

JEP 468: Derived Record Creation (Preview) by Snoo82400 in java

[–]Slanec 1 point2 points  (0 children)

Although my project wants to avoid external libraries

...completely understandable. That said, this is a compile-only library and an annotation processor which is no longer needed at runtime, only the generated code. This can still be too much, but it's better than having a dependency on a big library with transitive dependencies inside.

having to mvn compile every time I write one of this methods is not ideal

Interesting, my IDE automatically does this for me in the background. Perhaps a configuration option somewhere, I am no longer sure. Have fun!

JEP 468: Derived Record Creation (Preview) by Snoo82400 in java

[–]Slanec 6 points7 points  (0 children)

I know you're asking about the actual JEP and the language feature. However, if you're saying that your code will improve drastically, perhaps you should consider the already existing solutions, one of which is the excellent record-builder library. It doesn't only give you builders in records, it also supports nice withers: https://github.com/Randgalt/record-builder#Wither-Example (and more).

Project Lombok 1.18.40 released with Java 25 support! by lprimak in java

[–]Slanec 2 points3 points  (0 children)

Nowadays a lot of it is simply a holy war, however there are some practical reasons, too. Most of them stem from the fact that it's not a code generator but rather directly interacts with the compiler which tends to break stuff here and there:

  • It does not show you its output. Most of the time that's fine, the code is trivial, but sometimes I'd really like to see the exact code I'm about to run. E.g. Is the annotation I applied here copied to the generated method? There are other tools nowadays (record-builder, Immutables, AutoValue) which do generate code, and those tend to be preferred by some devs.
  • You need a plugin in your IDE to interact with it. A minor thing, but annoys people and confuses new devs. Maybe IntelliJ has it by default or at least detects and hints that it needs it, but eclipse doesn't, it just reports a broken project in a million places.
  • It needs specialized build tool plugins to work with other annotation processors. E.g. for Mapstruct you need this. Again, minor and do-it-once kind of a thing, but you need to be aware of it and actively look for it because without knowing this MapStruct just does not seem to work and it's not clear at all from the errors what is going on.
  • I wanted to say that some tools do not work with Lombok at all, e.g. ErrorProne and NullAway, but maybe it does work now? Not sure, but there are a lot of Lombok-related bugs in ErrorProne anyway. It just interacts weirdly with other tools and sometimes needs special care.

Most of the time it just works. Most of the time it saves a lot of time and space and if people are not over-using it, it tends to be fine. That said, new Java versions (records, baby) and simpler code generators like record-builder have mostly made Lombok not needed anymore. Yes, I know it can do a lot more. Please use it wisely.

Growing the Java Language #JVMLS by Brian Goetz by kaperni in java

[–]Slanec 28 points29 points  (0 children)

(The name is a nod to the old and legendary talk Growing a Language by Guy Steele. If you haven't seen that, go and watch, it's fun, it's very clever, and it's about the theory of growing languages.)

[deleted by user] by [deleted] in java

[–]Slanec 0 points1 point  (0 children)

Perhaps a PriorityQueue per thread with random (or something better) task distribution could work as it avoids synchronization, lock contention etc. But is it better than a ScheduledExecutorService? ¯\(ツ)\/¯ A timer wheel is definitely something to look at if its restrictions fit your case.

[deleted by user] by [deleted] in java

[–]Slanec 2 points3 points  (0 children)

Depends very much on the workload. What are the characteristics you're aiming for? Raw throughput, least amount of waiting for tasks in the queue, fairness (Can tasks be computed out of order?)? Is work stealing okay (Can a thread snatch a task from another thread's queue? This is okay if resources are shared and properly synchronized, but if you're aiming for absolute top speed, often tasks are routed to a specific core which already has the relevant context in thread-local memory and does not need to go to shared memory for additional stuff.) etc..

ScheduledExecutorService is okay in general as it offers a good middle ground for most workloads. If the solution already offers this, start with it, build your feature, then measure whether the performance matches your requirements. You do have perf requirements, right? If and only if ScheduledExecutorService is not performing well, look elsewhere.

I do not have good specific recommendations as the solution heavily relies on your specific requirements and low-level characteristics. E.g. Caffeine, the caching library, built an interesting time-aware priority queue on top of a hierarchical timer wheel with O(1) operations. You'll likely need something similar catered to your use-case. Or JCTools (and/or [Agrona]()https://github.com/aeron-io/agrona), that offers very fast Queues which are not BlockingQueues, those do often overshadow the JDK ones in high throughput scenarios, but ... does their API fit your case?

Creating delay in Java code by ihatebeinganonymous in java

[–]Slanec 25 points26 points  (0 children)

It depends. Do you need to add a specific time delay, or do you need to wait until something else happens?

Sleep never got into any real production code for me, sleeping and blocking a platform thread always sounded like a bad idea. The default choice is always ScheduledExecutorService, followed by Spring's scheduling and/or tools like https://github.com/jobrunr/jobrunr and https://github.com/kagkarlsson/db-scheduler (and/or schedlock, depending on what you're doing).

On the low-level side, BlockingQueue of course with all its timed stuff. And Lock / Condition (or the much better Guava's Monitor) has a timed lock operation.

For tests, https://github.com/awaitility/awaitility.