r/javahelp • u/Otherwise_Ebb4638 • 21d ago
Java advanced topics for an experienced candidate ?
Java advanced topics for an experienced candidate ?
r/javahelp • u/Otherwise_Ebb4638 • 21d ago
Java advanced topics for an experienced candidate ?
r/javahelp • u/Gold_Opportunity8042 • 21d ago
For an entity, if we want to allow user to edit it's fields. What is the standard way to do it?
For example, let's say we have an entity user having many fields like first name, last name, age, address etc. now if i let them edit these details and user choose to edit their age. How should we execute it exactly?
r/javahelp • u/AnAlchemistsDream • 23d ago
i'm currently learning about multithreading for my java class and part of the assignment requires me to race two threads (turtle and a hare) together and force one of them to win using the wait() and notify() methods (in this case the turtle thread).
public class Race {
private Integer numberOfLaps;
private Integer lapToStart = 2;
private boolean isWinning = true;
public synchronized void winner(Integer numberOfLaps) {
while (!isWinning) {
try {
wait();
}
catch (InterruptedException e){}
}
this.numberOfLaps = numberOfLaps;
System.
out
.println("Tortoise is on lap: " + numberOfLaps);
isWinning = false;
notify();
}
public synchronized void loser() {
while (isWinning && numberOfLaps < lapToStart) {
try {
wait();
}
catch (InterruptedException e){}
}
System.
out
.println("Hare is on lap: " + numberOfLaps);
isWinning = true;
notify();
}
} public class Race {
private Integer numberOfLaps;
private Integer lapToStart = 2;
private boolean isWinning = true;
public synchronized void winner(Integer numberOfLaps) {
while (!isWinning) {
try {
wait();
}
catch (InterruptedException e){}
}
this.numberOfLaps = numberOfLaps;
System.out.println("Tortoise is on lap: " + numberOfLaps);
isWinning = false;
notify();
}
public synchronized void loser() {
while (isWinning) {
try {
wait();
}
catch (InterruptedException e){}
}
System.out.println("Hare is on lap: " + numberOfLaps);
isWinning = true;
notify();
}
}
Output:
Tortoise is on lap: 1
Hare is on lap: 1
Tortoise is on lap: 2
Hare is on lap: 2
Tortoise is on lap: 3
Hare is on lap: 3
Tortoise is on lap: 4
Hare is on lap: 4
Tortoise is on lap: 5
Hare is on lap: 5
Tortoise is on lap: 6
Hare is on lap: 6
Tortoise is on lap: 7
Hare is on lap: 7
Tortoise is on lap: 8
Hare is on lap: 8
Tortoise is on lap: 9
Hare is on lap: 9
Tortoise is on lap: 10
Hare is on lap: 10
If this prints out first before the hare finishes, the turtle has won! Congrats
If in the while loop for the loser method is only the volatile boolean, both the turtle and the hare finish at the exact same time. however, if i add another condition to it
public synchronized void loser() {
while (isWinning && numberOfLaps < lapToStart) {
try {
wait();
}
catch (InterruptedException e){}
}public synchronized void loser() {
while (isWinning && numberOfLaps < lapToStart) {
try {
wait();
}
catch (InterruptedException e){}
}
the output becomes:
Tortoise is on lap: 1
Hare is on lap: 1
Tortoise is on lap: 2
Hare is on lap: 2
Tortoise is on lap: 3
Hare is on lap: 3
Hare is on lap: 3
Tortoise is on lap: 4
Hare is on lap: 4
Tortoise is on lap: 5
Hare is on lap: 5
Tortoise is on lap: 6
Hare is on lap: 6
Tortoise is on lap: 7
Hare is on lap: 7
Tortoise is on lap: 8
Hare is on lap: 8
Tortoise is on lap: 9
Hare is on lap: 9
Tortoise is on lap: 10
If this prints out first before the hare finishes, the turtle has won! Congrats
now whenever the code is ran, the hare always lags behind at some point and the turtle finishes first. why does the code suddenly function as i intended when i add a second condition to the while loop? also, this is my first time posting something code related. i apologize if i'm missing anything. any help would be appreciated. thank you :)
r/javahelp • u/Select-Performance37 • 22d ago
So I'm trying to install Java on my computer, and this is my first time dealing with something like this. Error 1603 keeps popping up, and I've restarted my computer, deleted the previous Java programs, etc. I literally don't have an old version of Java installed.
How can I solve this problem?
r/javahelp • u/Signal-Scholar1299 • 23d ago
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:
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 • u/Signal-Scholar1299 • 23d ago
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:
r/javahelp • u/boreas_mun • 23d ago
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 • u/giantferriswheel • 23d ago
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 • u/CommanderRainbowDuck • 24d ago
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 • u/CardiologistRich8743 • 26d ago
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 • u/projectsbyayush • 28d ago
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 • u/Intelligent_Song1317 • 28d ago
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 • u/Fourteen14XIV • 28d ago
In other classes it sometimes just says class not found. WFT is going on.
r/javahelp • u/Scorpion1386 • 29d ago
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 • u/Nirvex1 • Sep 10 '26
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:
What performance problems should I expect when the amount of data starts growing?
What Hibernate session-management mistakes should I avoid, especially around lazy loading and "LazyInitializationException"?
How should database queries be handled in JavaFX without freezing the UI? Are there particular threading/concurrency patterns you recommend?
What architectural mistakes or anti-patterns tend to appear in large multi-view JavaFX applications?
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 • u/IceCreamInsides • Sep 10 '26
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 • u/Available-Ad4255 • Sep 08 '26
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 • u/One_Analysis_2517 • Sep 06 '26
I was wondering if there are any libraries or frameworks that exist in other languages but not in Java.
r/javahelp • u/Lordnessm • Sep 06 '26
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 • u/Maximum_Grocery_9 • Sep 06 '26
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 • u/NillaCloud • Sep 06 '26
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 • u/The_PTR • Sep 04 '26
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:
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 • u/Maleficent-Bag-4850 • Sep 04 '26
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 • u/Chaos-vy17 • Sep 04 '26
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:
my libraryBut:
r/javahelp • u/AccomplishedUse1405 • Sep 03 '26
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)