r/javahelp Mar 19 '22

REMINDER: This subreddit explicitly forbids asking for or giving solutions!

48 Upvotes

As per our Rule #5 we explicitly forbid asking for or giving solutions!

We are not a "do my assignment" service.

We firmly believe in the "teach a person to fish" philosophy instead of "feeding the fish".

We help, we guide, but we never, under absolutely no circumstances, solve.

We also do not allow plain assignment posting without the slightest effort to solve the assignments. Such content will be removed without further ado. You have to show what you have tried and ask specific questions where you are stuck.

Violations of this rule will lead to a temporary ban of a week for first offence, further violations will result in a permanent and irrevocable ban.


r/javahelp 3h ago

Best Roadmap for Enemy AIs in simple 2D games?

2 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 6h ago

Should I use JDK JMH benchmarks for my library?

4 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 15h ago

Transfer Student needing help for java

4 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 22h ago

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 22h ago

Rich library for Java

0 Upvotes

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


r/javahelp 1d ago

JPackage is not working

5 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 2d ago

Good Documentation For JVM Bytecode?

15 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


r/javahelp 3d ago

Workaround Race condition in SSE

3 Upvotes

Hi all, I am trying to build a real time notification service with SSE emitter but I am facing a pecuilar case of race condition which im not able to solve even via AI as it gives the same solution again and again.

scenario of cause:

I have a scheduler running every 20 mins that checks the Map of uid mapped sse emitters and pings the client. If the ping is successfull nothing happens, if error happens due to disconnection the sse emitter obj is removed via sse.complete() and then uid is removed form the list.

#pseudo code
Map<String, SseEmitter> connections = new ConcurrentHashMap<>();

onConnect(String userId){
  SSE emitter = new new SseEmitter()
  connection.add(userId,emmitter);

  // onCompletion(), onTimeout(), onError() -> removeIf()
}

u/scheduler(20mins)
checkDisconnection(){
  //iterate the map and check for disconnection if found add it to remove list
  List<string> disconnectedUsers = (adding disconnections)

  //iterate the map from disconnected user -> force complete sse if needed and                    remove user from map


}

where it breaks is if the client manually refreshes the browser at the same time the scheduler to check disconnection is invoked

why it happens:

when the browser is refreshed, the application tries to recreate the connection at which the scheduler tries to ping and sees no connection for the user. Problem is I have kept automatic reconnections on in client app but it still doesnt see an error in client. im confused. Have I had the approach wrong?

Any help will be appreciated and sorry for the questions confuse you, Il try to make it proper once i get the time.

TECH : javascript event source, springboot, kafka for scaling and mongo for scheduled notifications.


r/javahelp 4d ago

Per-Class cleanups when shutting down

7 Upvotes

Hello, I am creating a save system however it currently depends on memory limits. When the map fills up, it dumps to disk and starts filling memory again from start. When the program shuts down, I want the class responsible for saving the data to run a cleanup function the dump the half-full map to disk. I have seen several ways of doing this however I couldn't really decide what is the best choice. Thanks


r/javahelp 5d ago

Help for java 21 ocp 1z0 830 exam

5 Upvotes

Im planning to give this certificate exams cause I want to gain deeper knowledge in java and having an exam to focus on gives me a goal to achieve, so im more of a visual leaner and want to start with a pathway of videos and courses and then do practice exams, this is my strategy so far.

Im not that eager to read books or articles and prefer videos and practicing along.

I see oracle has a learning pathway that's build for java 21 programming and it has a pathway that looks good. So im trying to see if anyone has tried the pathway and found it useful for the cracking the certificate examination or are there any udemy courses that I could take that helps with my certification.

This is the pathway https://learn.oracle.com/ols/learning-path/become-a-java-se-21-developer/117252/138845

Also let me know any useful site that have a lot of practice questions to try


r/javahelp 5d ago

How to use noise maps?

4 Upvotes

I've done some very surface-level searching and I feel like the number of choices on how to do this is pretty intimidating, what libraries should I use and how?


r/javahelp 6d ago

Homework Java help

13 Upvotes

Guys help me,how I am able to learn java who don't know about coding at all , please give me legit answer and what are the steps I should follow after watching tutorial , please help me guys,want suggestions like if I watch one tutorial per day of any yt channel ,what should I do next after watching tutorial and in a month later


r/javahelp 9d ago

using dotnet media player in java

0 Upvotes

I’m trying to build a music player in Java/JVM that plays audio streamed from an API, but I’m having a hard time finding a media player library with good enough functionality.

I’ve looked at several Java libraries, but none of them really fit my needs. The best option I’ve found so far is **vlcj**, but it requires VLC to be installed separately, which I’d prefer to avoid.

I was considering using **C#/.NET for the actual audio playback** and then bridging it to Java using the **Java FFM API**.

Would this be a reasonable approach, or am I overcomplicating things?

If using .NET makes sense, what would be the best library for **streaming audio from an HTTP/API source** in .NET? Ideally, I’d like something that supports things like seeking, buffering, metadata, different audio formats, etc.

Alternatively, are there any good JVM-native solutions for this that I’m overlooking?

I’m mainly interested in **streaming audio received from an API**, rather than playing local files.


r/javahelp 10d ago

Is the TreeSet Slow or is My Benchmark Wrong?

5 Upvotes

Currently to Optimize my library I have been reading ben paff guide on iterative approach of tree, from which I got the Idea of RBT and AVL for iterative approach. In which I made use AVL as parent based tree. But it is that when I did the benchmark with JVM21 these were my result ,it's tested three time for consistent behaviour of data, error and changes to occur for each time. which stands out firmly consistent behavior. tthis is one sample of it.

Benchmark                                                         (size)    Mode      Cnt        Score   Error   Units
InsertDeleteBenchmark.avlInsertDelete                              10000  sample  2828056      228.686 ± 2.651   ns/op
InsertDeleteBenchmark.bstInsertDelete                              10000  sample  3131645      190.531 ± 2.344   ns/op
InsertDeleteBenchmark.javaTreeSetInsertDelete                      10000  sample  4416191      228.719 ± 1.637   ns/op
InsertDeleteBenchmark.rbtInsertDelete                              10000  sample  2766974      211.846 ± 2.505   ns/op
InsertDeleteBenchmark.treapInsertDelete                            10000  sample  4749890      232.499 ± 1.485   ns/op

The benchmark was done 3 time, the config I used were for the benchmark were
10K - randomized dataset
warmup = 3 warmup time = 5s each
measurement = 3 measurement time = 5s each
fork = 5.
All the tree used same Set as interface for test. The doubt is currently my RBT tree is working safe with recursive delete and performing edge with TreeSet. What is the reason for TreeSet to be slow given that TreeSet is highly optimized. When I think of Benchmark I assume to be correct. This is really too good to be proud or confused??. But there is greed of also stripping recursive delete of RBT which I want to do and not do. Because it's too hard😢
For reference of Benchmark code

Edit:My wordings and grammar are not too good please do ignore that.


r/javahelp 10d ago

How to check if an array contains another specific array?

5 Upvotes

sorry if im stupid here but

i have an array that contains multiple coordinates, so for example [2,8], and i need to check if that array contains a specific coordinate

how do i do that


r/javahelp 10d ago

Unsolved I need help with getResourceAsStream

2 Upvotes

u/wildjokers (reaching out to you because I saw you in this thread)

https://www.reddit.com/r/javahelp/comments/sypxqz/getresourceasstream_null_when_run_from_jar/

I'm trying to run a Isometric Tile game, from chapter 13 of Killer Games Programming in Java, a very old book.
I'm using Eclipse. I'm not sure what classpath means, but I think mine is set up as

Project

src

Images

Sounds

I'm getting these errors when I run:

Exception in thread "main" java.lang.NullPointerException

at java.base/java.io.Reader.<init>(Reader.java:168)

at java.base/java.io.InputStreamReader.<init>(InputStreamReader.java:88)

The relevant code is:

{

String imsFNm = IMAGE_DIR + fnm;

System.out.println("Reading file: " + imsFNm);

try {

InputStream in = this.getClass().getResourceAsStream(imsFNm);

BufferedReader br = new BufferedReader( new InputStreamReader(in));

// BufferedReader br = new BufferedReader( new FileReader(imsFNm));

String line;

The image file is defined in another class, and then piped into ImageLoader class, where it's appended to the directory, which is defined in ImageLoader class.

When I run, it's showing the correct directory in the console, so I believe getResourceAsStream is where it's being messed up.

I did right click on the images folder, Build Path > Add to Build Path.

I can provide more information, which will probably be needed.


r/javahelp 11d ago

Solved How do i make a java bug report. Ive search everywhere but nothing found

4 Upvotes

I cant really find a way to contact the dev team
I want to report a bugfix for jdk21


r/javahelp 14d ago

Solved Help me decide minimum JDK for my library

8 Upvotes

Should I move my Java library from JDK 11+ to JDK 21+?

I am genuinely confused at this point 😭

I've been reading a lot of posts and tech articles about companies/projects migrating from older Java versions like JDK 8/11 to JDK 21+.

And now I'm stuck with the same question for my own Java library.

On one side, keeping JDK 11+ gives better compatibility. There are still a lot of projects out there running on older Java versions, and since this is a library, compatibility matters because I'm basically deciding the minimum JDK required for everyone who wants to use it.

On the other side, JDK 21+ gives a much more modern Java baseline, newer APIs/features, and potentially better JVM performance.

Also, most of the migration stories I'm finding are from large companies / enterprise applications, which makes me wonder if the same reasoning actually applies to an open-source Java library. Even if big companies are migrating to JDK 21+, their interviews and hiring expectations are also increasingly centered around JDK 21 and the major changes since JDK 8, which makes the whole situation even more confusing for someone learning/maintaining Java.

So I'm trying to understand what people actually do in real-world Java libraries today.

Would you help me decide the minimum at JDK 11+ or move to JDK 21+?

And if you maintain a Java library yourself:

  • How do you decide the minimum supported JDK?
  • How important is JDK 11 compatibility today?
  • Is JDK 21 actually worth making the minimum?
  • Would you only raise the minimum JDK in a major release?

I would really appreciate some practical opinions because I am totally fed up with reading migration articles . Please it's more likely a great help for me.

https://github.com/Chaos-vy/ChaosTree

Reached conclusion:

I read through the recent JLS and JVM changes. JLS got new features and reduced boilerplate, while JVM got some massive improvements.
But since ChaosTree is zero-dependency, I don't have the same CVE/dependency issue.
So for now I'm wrapping it around JDK 11+ and letting users run it on newer JDKs if they want.

Thanks everyone for dropping your thoughts


r/javahelp 14d ago

Where to Deploy ?

6 Upvotes

I build a small service with spring and react, bow I need to deploy it using a domain. Which hosting solutions do you use ? I evaluated to use GCP but I am worried that some day I will find a giant unknown bill cost.

could you give me some recommendations please


r/javahelp 14d ago

Book recommendations for experienced developer coming from C#

4 Upvotes

Hi, I'll keep this short and sweet. I'm looking for a book to get me up to speed with Java development without it covering basics like variables and OOP.

I'd like it to cover building web applications with Spring/Spring Boot and using libraries like Lombok.

I'm already well versed in C# and ASP.NET, and I've found the differences between the two languages is bigger than I originally expected.

Does such a book exist? Thanks!


r/javahelp 15d ago

Finally did my first Multithreading program!! But why Amdahl's law fails?

5 Upvotes

The code was:

long parallelSum(int[] ar, int threadCount) throws InterruptedException {
        int n = ar.length;
        long[] result = new long[threadCount];
        Thread[] threads = new Thread[threadCount];
        int chunk = n / threadCount;
        for (int i = 0; i < threadCount; i++) {
            int index = i;
            int start = i * chunk;
            int end = (i == threadCount - 1) ? n : start + chunk;
            threads[i] = new Thread(() -> result[index] = sum(ar, start, end));
            threads[i].start();
        }
        for (Thread thread : threads) thread.join();
        long total = 0;
        for (long value : result) total += value;
        return total;
    }

Which I benchmarked using JMH to see how it will behave under increase thread. But It's gets better and better until 24 thread that the reason I know my P-core are Hyperthreaded so maximum improvement is seen at 24. But after that why is'nt it constant as the law stated when N-> increases it becomes directly 1/S.

The Benchmark was performed with 3 warmup 5 iteration 1sec each and 100M dataset. I did use first 1K to see how it behaves but I forgot that until the thread get created sequential would have finished that. So after rigrously increasing dataset to 100M this was my result:

Thread Count Score (ns/op) Error (ns/op)
1 36,386,448.214 ±1,198,308.768
2 19,973,254.073 ±1,647,022.164
4 11,605,188.001 ±409,298.394
8 8,493,406.418 ±439,947.023
16 8,070,964.770 ±101,846.828
24 7,880,208.459 ±179,094.210
32 8,075,411.516 ±211,717.162
64 8,256,737.790 ±282,807.150
128 8,855,717.582 ±121,931.514
256 10,475,522.486 ±258,283.333
512 29,275,816.985 ±9,028,465.533

Is my benchmark wrong or I am understanding different??


r/javahelp 15d ago

Suggest me a best Java Web Development course to learn...

0 Upvotes

Hey, I want to learn java web development. I know java programming at intermediate level by solving leetcode problems... I want to become a java developer. Guide me guys... Help me out... I am a final year student trying for placement but I didn't believe that I will be placed suggest me a roadmap too


r/javahelp 16d ago

Java

8 Upvotes

If anybody has done Kunal Kushwaha's OOPs playlist and finished after doing OPPs from him how to progress forward for Java Full Stack I know SoringBoot is needed but my question is can I directly jump to Spring and SpringBoot


r/javahelp 16d ago

Should I have to be very good at this topic ?

0 Upvotes

I have been learning java deeply in the recent times....... hoping to crack a 10+lpa job so please guide me through this.

1 . Should I have to be very good at this topic ? or the basic understanding of these topics are enough for cracking faang companies .

  • Writing basic recurrence relations
  • Master Theorem basics
  • Common recurrence results
  • Types of Recurrence Relations
  • Divide-and-Conquer Recurrence Relation
  • Akra-Bazzi Theorem
  • Linear Recurrence Relation
  • Solving Homogenous Linear
  • Recurrence Relation
  • Q: Find nth Fibonacci Number using Golden ratio
  • Q : Solve Recurrence Relation with Repeated Roots
  • Non-Homogeneous Linear Recurrence Relation