r/javahelp • • 18d ago

JVM Object immutability

16 Upvotes

I'm trying to better understand what immutability actually means from the JVM/JIT point of view,.

We often say that immutable objects are easier for the JVM to optimize, but I'm interested in what HotSpot can actually detect, prove, and exploit at runtime.

A few questions:

  • How does the JVM determine that a field, value, or object is effectively immutable or stable?
  • What optimizations does HotSpot actually enable when it has this information?
  • Conversely, what optimizations become impossible or harder when an object remains mutable?

I looked through some HotSpot code and didn't find much explicit handling of immutable objects for constant folding, apart from specific cases such as trusted/final fields some whitelisted JDK classes, and records.

I'm also curious about the practical trade-off:

How do you balance a low-allocation design based on reusable mutable objects, which reduces GC pressure, against a more immutable design, which may give the JIT more optimization opportunities but can increase allocation and GC pressure when you have a use case of mutable object ?


r/javahelp • • 17d ago

ZGC vs Shenandoah: what are the fundamental differences today?

6 Upvotes

I'm trying to better understand the differences between ZGC and Shenandoah, beyond the usual "both are low-latency concurrent collectors" explanation.

From a JVM/runtime perspective, what are the fundamental architectural differences between them?

In particular:

  • How do their barriers differ (load/store barriers, SATB, colored pointers, etc.)?
  • ZGC uses forward table and shenandoah no, what does it imply ?

r/javahelp • • 17d ago

Problem with xmlread. It crashes Octave.

0 Upvotes

I loaded io package, added 2 jar files. It didn't work, had to install Java, now I get:

xmlread();

xerces:

- xercesimpl.jar OK

- xml-apis.jar OK

xerces version: 2.12.2

But then I use it on any xml file Octave crashes.

Also when I run:

parser = javaObject("org.apache.xerces.parsers.DOMParser");
parser.parse(filename);
xDoc = parser.getDocument();

it crashes on the 3rd line.

version 11.1.0

Can anyone help me with it?


r/javahelp • • 17d ago

Unsolved How can I propagate MDC in an Asynchronous call.

1 Upvotes

So I have an issue that I'm dealing with, basically my Microservice has a controller and the request lands with a unique x-request-id, I save that request ID in MDC, basically what happens is in the method call stack there are asynchronous API calls to other services, as soon as the async boundry is reached the MDC gets lost.

Now this is happening because, MDC is thread specific and I am returning a CompletableFuture response which sends an asynchronous response and that specific thread completed the lifecycle.

A simple fix would be to pull out and propagate the x-request-id(s) in method calls, but I don't think this is the best solution since there are multiple internal libraries involved and I would have to change implementations there that can also alter the existing behavior of the application unexpectedly.

Next, I thought of initialising a MDC that can hold the request ID at different points of time, the issue in this approach is that if the MDC doesn't get cleared in time after getting initialised, the requestId can be wrongly used for different requests, that could happen because the thread in a high traffic system?

What are some other options that I can try?

To have context: I am implementing this with Quarkus and Mutiny


r/javahelp • • 18d ago

Uninitialized variables are null or zero?

7 Upvotes

Inside public static void main(String[] args) and static void namehere() {}.

Int X;

would be "Uninitialized" and give errors when compiling.

Outside main and any other method, right after public class xxx.

public static int x;

holds no value whatsoever, yet the program doesn't complains about it when compiling, when printing it gives 0 as an int rather than null or NaN.


I am expecting:

Strings: "Null", Null or "".

Int: Null, None, NaN.

booleans give false by default.


What's different in this language?


Edit:

public static int X;

public static boolean Check;



static void Method A() {

X = 1

}



static void Method B() {

    boolean ThisLoop = true;

    String AverageText = "Average";

    int Number;

    if (Check == false) {

       Number = X;

    }

    int Average;

    while (ThisLoop == true) {

             try {

             Average = Integer.parseInt(JOptionPane.showInputDialog("Input " + AverageText + 

             Integer.toString(Number)));

             if (Average >= 0 || Average <= 0) { 

             Number = Number++;

             InputNumber = Average;

             ThisLoop = false;

             }

             }

            catch (NumberFormatException e) {

            JOptionPane.showMessageDialog(null, "Not a number", "Alert: Stupidity detected", 

            JOptionPane.ERROR_MESSAGE);

            ThisLoop = true;


            }

}                            

}

According to Java, we already know booleans with no value are by default false.

I am initializing Number before the If.

Check is public and also is false.

It goes into the If and sets Number to X (Which is public)

Initializes Average.

Sets Average to [Option dialog] "Input" + AverageText + Converts Number into a String.

Java is telling me that Number is not initialize inside the Integer.toString()

If Average is 1000 to 0 or to -1000 then it sums Number + 1.

Java isn't telling me Number = Number++; are not initialized.


r/javahelp • • 20d ago

Unsolved Can't install java.

0 Upvotes

I downloaded the java installer but every time I try to run it, it returns an error code 1603, what do I do?


r/javahelp • • 22d ago

IntelliJ IDEA free vs NetBeans which should I choose?

10 Upvotes

I’m currently learning Java/Advanced Java and starting to get into Spring Boot. I’ve mostly been using NetBeans for JSP/Servlet projects, but I’m wondering if I should switch to IntelliJ IDEA.

For people who have used both, which one do you prefer and why? Mainly looking at features, Java development, Spring Boot, debugging, Maven, etc.

Would appreciate some opinions from experienced Java developers.


r/javahelp • • 22d ago

Unsolved Output

4 Upvotes

Soo uuhhhhh heres part of my code:

I told the Java code to print "result" and "p" after inputting 1, and it printed result to 11 digits after the decimal and p to 1. Specifically, the outputs were 3.141592652 and 2.0. Here's the thing:it needs to be rounded to 6 digits after the decimal. Thoughts?

        double result = Math.pow(n, 2) * 3.141592653;
        double p = Math.pow(n, 2) * 2;

r/javahelp • • 22d ago

Help, for some reason my eclipse executes the previous group of commands instead of the current ones.

0 Upvotes

In other classes it sometimes just says class not found. WFT is going on.


r/javahelp • • 23d ago

Homework Looking for some help or advice with a beginner Java problem.

4 Upvotes

I'm not sure how to do this particular problem. I'm using the textbook Introduction to Java Programming. 12th edition, by Y. Daniel Liang for an Introduction to Programming college class.

I would appreciate it if someone can possibly give me advice or hints here and guide me through this problem step-by-step. I've tried putting in int numberOfYears = input.nextInt(); among other code for example to get creative and solve it differently, but I just feel overall stuck on the logic of it.

(Population projection) Rewrite Programming Exercise 1.11 to prompt the user

to enter the number of years and display the population after the number of years.

Use the hint in Programming Exercise 1.11 for this program. Here is a sample run

of the program:

Enter the number of years: 5

The population in 5 years is 3259329

Exercise 1.11:

(Population projection) The U.S. Census Bureau projects population based on

the following assumptions:

■■ One birth every 7 seconds

■■ One death every 13 seconds

■■ One new immigrant every 45 seconds

Write a program to display the population for each of the next five years. Assume

that the current population is 312,032,486, and one year has 365 days. Hint: In Java,

if two integers perform division, the result is an integer. The fractional part is trun-

cated. For example, 5 / 4 is 1 (not 1.25) and 10 / 4 is 2 (not 2.5). To get an accu-

rate result with the fractional part, one of the values involved in the division must be

a number with a decimal point. For example, 5.0 / 4 is 1.25 and 10 / 4.0 is 2.

I honestly am struggling with this a lot. I'm trying to do it all on my own. I don't want to copy any code or Google anything, so any and all advice on how to solve this would be greatly appreciated.

Thanks!


r/javahelp • • 25d ago

Unsolved Building a JavaFX + Hibernate Talent Acquisition System — looking for some advice

0 Upvotes

Hey everyone!

I’m currently working on a desktop-based Talent Acquisition System using Java 11, JavaFX, Maven, Hibernate, and MariaDB (running through XAMPP), with Apache NetBeans as my IDE.

I’m trying to keep the project as close to proper OOP principles as possible, with a clear separation between the business logic, UI/controllers, and Hibernate entity models.

The candidate side is almost done. So far, users can:

\- Register and log in

\- Browse available job openings

\- Apply for jobs

\- Store their applications directly in the database

One of the more challenging parts so far has been managing around 17 different FXML views and connecting all of them properly with their controllers. I also had to spend quite a bit of time understanding "module-info.java", resource paths, and how everything fits together in a modular JavaFX application.

Thankfully, that part is finally stable.

Now I’m moving on to the more complicated part: designing and building the admin/hiring manager side.

My current TODO list looks something like this:

\- Admin/Hiring Manager module: Job posting, candidate shortlisting, interview scheduling, etc.

\- Validation & security: Phone number validation, password strength requirements, and a proper Forgot Password workflow.

\- Database/session management: Making sure Hibernate sessions are handled properly as the application grows.

Since this is a desktop application, I’m especially interested in hearing from people who have worked with JavaFX + Hibernate or similar stacks.

A few things I’m wondering about:

  1. What performance problems should I expect when the amount of data starts growing?

  2. What Hibernate session-management mistakes should I avoid, especially around lazy loading and "LazyInitializationException"?

  3. How should database queries be handled in JavaFX without freezing the UI? Are there particular threading/concurrency patterns you recommend?

  4. What architectural mistakes or anti-patterns tend to appear in large multi-view JavaFX applications?

  5. How would you structure the admin/hiring-manager module so it stays maintainable as more features are added?

I’d really appreciate any advice, criticism, or lessons learned from people who have built similar desktop applications.


r/javahelp • • 26d ago

Solved Switch case with boolean

2 Upvotes

So, there is no way I can do that?

want to check several boolean variables in a switch statement. Is `if-else` the only way to do this?

Boolean a, b, c...

Switch (false) {

Case (a) :

//some code

Case (b) :

Case (c) :

//and so on

}


r/javahelp • • 27d ago

Universal pdf gen lib

6 Upvotes

Hi,

I want to generate pdfs in many languages, including right to left languages. (Arabica, hébrew, indian langs ..)

I have a working prototype with itext 9 that works well afaik (difficult to check langs I dont read).

Itext proposes 'pdfcalligraph' for a fee, to make sure rtl texts are handled correctly (direction, ligatures...).

Is there a lib that does that too ?

I read that pdfbox is not handling rtl at all.

What other libs would you advise ?

Thanks


r/javahelp • • Sep 06 '26

Missing libraries or frameworks in Java

11 Upvotes

I was wondering if there are any libraries or frameworks that exist in other languages ​​but not in Java.


r/javahelp • • 29d ago

Wiring JAVAFX with SpringBoot Application so they run under one JVM

2 Upvotes

guys i am trying to build system monitor project with custom notification design , and ai told me to use javafx for that ,and i did that , later i learned that i cant run javafx throguh IDE run or SpringApplication. run the only way was to run it through Maven javafx->javafx:run , i am wondering how can i make it so when my app runs both of them runs


r/javahelp • • 29d ago

Unsolved Java is both installed and not installed on my computer. I want it to be not installed.

0 Upvotes

Command Prompt shows I have Java installed:

C:\Users\Drew>java --version
openjdk 21.0.6 2025-01-21 LTS
OpenJDK Runtime Environment Temurin-21.0.6+7 (build 21.0.6+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.6+7 (build 21.0.6+7-LTS, mixed mode, sharing)

Windows control panel says I don't have java installed. Java is not listed as a program when I go to uninstall it.

I would like to uninstall java, how do I do that?


r/javahelp • • Sep 06 '26

Solved Trouble with printing data using methods

2 Upvotes

Hello all! I'm brand new to java; this code comes from a FRQ exercise from unit 2 in the AP CSA course if that helps.

The purpose of the code is to check whether a string has alternating cases, with capital letters beginning at index 0 always ("ApPlE" or "CaT" for example, "cAt" would not work), and then to print "true" if the string meets the requirement.

The current error that I'm having currently is that

"s cannot be resolved"

which is underlined at line 7.

My understanding is that my code cannot access the string s and its true/false content, but I could be totally wrong here.

Thanks in advance, any help is appreciated!

GitHub Gist Link: https://gist.github.com/v4npaia-kei/5aa65b5978a7cbdd46a291ff4572237d


r/javahelp • • Sep 04 '26

Solved Best practices for JavaFX GUI

5 Upvotes

I have been trying to get into JavaFX for creating a GUI application, but I was wondering what the general best practice for that would be. I know that GUIs have several possible well-documented structures such as MVC, MVP, MVVM, etc., but I was wondering which is best applicable to JavaFX and how to best approach that. I mainly have the following questions:

  1. Should I have a class that contains static references to the various UI components so that they can be linked more easily w.r.t. event handling? If so, what would be the best place for that? Application subclass? It's own dedicated utility class? If not, what would be the better alternative for handling such UI logic (e.g. MenuItem changing color of another component)?
  2. For things that do not technically require custom classes, should I just initialize them completely inside the Application subclass or should I still make a custom class to better decompose the code? E.g. say I have this MenuBar. Should I create, configure, and store the MenuBar, Menu, and MenuItem objects inside the Application subclass or should I make a subclass of MenuBar that implicitly creates and configures the inner structure so the Application subclass code looks cleaner?
  3. For UI elements that are more complex in nature or require subclassing, should the subclass also create the UI logic or only the view related things? Since data binding is possible, the UI classes seem to have a mix of multiple components, so I am not sure what the best practice for these is, especially if the model data is more dynamic.
  4. This is a bit of an extension on the previous question, but say I have this UI element that portrays the data of some model. On top of that, I have a method that does extensive editing of the model data. Based on what I have read online, it seems that the best way to do this is to run that method on a different thread than the UI thread. Would it then be better to bind the UI data to the model data (property binding) with a conditional (when) or to manually update the UI post-method?
  5. Should the data models use the Property types or is it better to use basic primitive/object types and listeners?
  6. What is generally considered the best practice for package structure w.r.t. the UI subclasses?
  7. If I want to simultaneously have a CLI variant of the program, which uses the same data models but prints strings in chat instead, would this require extra care in terms of designing the GUI structure or would it still be very simple to do?
  8. What is the best practice w.r.t. locales? Currently I have a project with several utility classes containing static ReadOnlyStringProperty fields that are bound to a static ResourceBundle property, which is bound to a locale property, so that they automatically update upon updating the locale. Is that a good approach or are there better ways to do this? A simple example of that structure:

​

    public class LogStrings {
        public static final StringProperty WARN_MSG = getBundleProperty().map(x -> x.getString("warn"));
        public static final StringProperty ERROR_MSG = getBundleProperty().map(x -> x.getString("error"));
    }

r/javahelp • • Sep 04 '26

Best Roadmap for Enemy AIs in simple 2D games?

4 Upvotes

So, I think that the best way to go about this is making a sprite that "knows" your player's position, has different states( attack , patrol, etc) but is there something I'm missing????


r/javahelp • • Sep 04 '26

Should I use JDK JMH benchmarks for my library?

3 Upvotes

My library recently passed Guava testlib, so now I'm moving on to benchmarking.

I'm thinking about using/adapting the JMH benchmarks from the JDK.

Pros:

  • Official JDK-based JMH
  • More standardized
  • Easier comparison with my library

But:

  • The benchmark is totally focused on write-heavy operations
  • It doesn't really cover reads
  • No delete operation either

r/javahelp • • Sep 03 '26

Transfer Student needing help for java

3 Upvotes

Hey everyone,

I’m a second-year transfer student at the University of Utah, and I’m feeling pretty overwhelmed about CS 2420.

My previous programming experience is mainly Python, and I’m now trying to learn Java. I understand basic programming concepts, but I’m finding the transition to Java harder than I expected.

I’m especially struggling with the basics and knowing what I actually need to learn before getting into the CS 2420 material. I've already asked my professor for help but he just said use chatgpt and google.

I’m also pretty stressed because I’m a transfer student and feel like I’m behind everyone else. I have some programming experience, but Java is making me feel like I’m starting over. This course is also really important because if I don't pass i might fail my entire semester when I come back.

Any help would really be appreciated.

P.S (I don't know if this is the right sub but tmrw is the deadline for course swaps)


r/javahelp • • Sep 03 '26

linked lists

4 Upvotes

-- solved thank you all

what is the difference between accessing the next node using a get method or without, as in: "current.next" vs "current.getNext()" and the same applies for accessing an element, whats the difference between use the get or not, as in: "current.element" vs "current.getElement()" where current is just the name for the node variable. ive looked at so many different explanations but i cant seem to grasp the idea
edit: this is from a data structures pov, im implementing methods for the singly and doubly linked list classes in java
i want to know if they return different things or if using .next or .getnext makes a difference in the outcome, is there a scenario i should be using strictly .next or .getnext, and the getter method has no further conditions its just {return next}


r/javahelp • • Sep 03 '26

Rich library for Java

0 Upvotes

Hello, is there any library for Java similar to Rich in Python?


r/javahelp • • Sep 02 '26

JPackage is not working

6 Upvotes

I have this in a build script:

jar ^
    --create ^
    --file "%BUILD%\input\RocketTracker.jar" ^
    --manifest "%BUILD%\MANIFEST.MF" ^
    -C "%BUILD%\classes" .

jpackage ^
    --type app-image ^
    --name RocketTracker ^
    --input "%BUILD%\input" ^
    --main-jar RocketTracker.jar ^
    --main-class app.Main ^
    --module-path "%JAVAFX%\lib" ^
    --add-modules javafx.controls,javafx.fxml,javafx.graphics,java.net.http ^
    --dest "%RELEASE%"

If I run the jar manually adding the modules in the VM it works, but if I run the .exe generated by jpackage it raise an exception:

Graphics Device initialization failed for :  d3d, sw
Error initializing QuantumRenderer: no suitable pipeline found
java.lang.RuntimeException: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
        at javafx.graphics@21.0.12/com.sun.javafx.tk.quantum.QuantumRenderer.getInstance(Unknown Source)
        at javafx.graphics@21.0.12/com.sun.javafx.tk.quantum.QuantumToolkit.init(Unknown Source)
        at javafx.graphics@21.0.12/com.sun.javafx.tk.Toolkit.getToolkit(Unknown Source)
        at javafx.graphics@21.0.12/com.sun.javafx.application.PlatformImpl.startup(Unknown Source)
        at javafx.graphics@21.0.12/com.sun.javafx.application.PlatformImpl.startup(Unknown Source)
        at javafx.graphics@21.0.12/com.sun.javafx.application.LauncherImpl.startToolkit(Unknown Source)
        at javafx.graphics@21.0.12/com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
        at javafx.graphics@21.0.12/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
        at javafx.graphics@21.0.12/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.init(Unknown Source)
        at javafx.graphics@21.0.12/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(Unknown Source)
        ... 1 more
Exception in thread "main" java.lang.RuntimeException: No toolkit found
        at javafx.graphics@21.0.12/com.sun.javafx.tk.Toolkit.getToolkit(Unknown Source)
        at javafx.graphics@21.0.12/com.sun.javafx.application.PlatformImpl.startup(Unknown Source)
        at javafx.graphics@21.0.12/com.sun.javafx.application.PlatformImpl.startup(Unknown Source)
        at javafx.graphics@21.0.12/com.sun.javafx.application.LauncherImpl.startToolkit(Unknown Source)
        at javafx.graphics@21.0.12/com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
        at javafx.graphics@21.0.12/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)
Failed to launch JVM

Any idea how to fix it? the same code in bash works just fine and the path are checked already


r/javahelp • • Sep 01 '26

Good Documentation For JVM Bytecode?

13 Upvotes

I really liked the idea of an intermediate bytecode language when I first learned that Java transpiles to one, so I tried to learn about it and got pretty far (using a hexeditor to mess around was pretty painful, though). I stopped because there isn't a lot of document for it like there is for Java, the best resources are I believe docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html and docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html, but I want to know if there are any others partly because these are kind of verbose and partly because it's just better to have more than two.

I know I won't ever really need to know any of this, and I don't intend to use any of this knowledge for making classes by hand, but I believe it would still be helpful in a milder sense to understand what the class files are "literally" doing. It helped with C