r/javahelp Mar 19 '22

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

45 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 9h ago

Good Documentation For JVM Bytecode?

8 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 1d ago

Workaround Race condition in SSE

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

Help for java 21 ocp 1z0 830 exam

4 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 3d ago

How to use noise maps?

3 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 4d ago

Homework Java help

12 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 6d 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 8d ago

Is the TreeSet Slow or is My Benchmark Wrong?

4 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 8d ago

How to check if an array contains another specific array?

3 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 8d 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 9d ago

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

5 Upvotes

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


r/javahelp 11d ago

Solved Help me decide minimum JDK for my library

7 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 11d ago

Where to Deploy ?

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

Book recommendations for experienced developer coming from C#

5 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 13d 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 13d 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 14d 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 14d 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

r/javahelp 15d ago

Guide for Concurrency in Java

0 Upvotes

Before knowing anything I just jumped directly to the source code of jdk25u. I have just started to read the javaDocs of Thread class it was so deep that all my connected logic mapped very well but now I want to code and I can't code ahhhh... Why is this problem. I can call the syntax what to use but I don't know how to apply, why to apply is there any guide for java Concurrency ??. And there is so much .. still to know. Do any dev have any guide??


r/javahelp 15d ago

How to start codeforces with Java?

1 Upvotes

Asking because there are lot of resources to start with C++, so anyone can suggest if you are doing in Java.

Problem is that codeforces ide, boilerplate code and also the framing of questions as scenario based need some resources to follow in starting.


r/javahelp 16d ago

i want to start java spring boot from 0

17 Upvotes

best resources to learn java from the very basics till java spring boot advanced any book or any yt video would help! please recommend one


r/javahelp 17d ago

Unsolved Naive question: What Data Structure to express different layers of relationships between Objects?

8 Upvotes

Hello guys,

I wanted to ask naively, what the ideal data structure would be for expressing different layers of relationships between Objects.

For example in modern Sudoku the game has a 9x9 number grid composed of nine 3x3 sub-grids (which I call region). In each row, column and region each number between one and nine can only appear once. The goal is to find missing numbers in this number grid without violating the aforementioned rule.

One way to do it, would be to make 9x9 byte-array and express the relationship between numbers through methods checking if the rule is violated or not by checking if any row, column or region doesn't contain a value between one and ten.

I also thought on using a Graph to express the relationship between numbers in rows and columns, though I don't know how to express the relationship between numbers inside of a region.

Maybe even a multiple Objects like Board, Row, Column, Region but then I have redundant data.

Another problem I encounter with aforementioned implementations is, that if you introduce more relationships f. e. in the game of killer sudoku, where there are more rules are added f. e. by also introducing cages in which the numbers must add up to a target number, you need to implement that relationship logic tediously.

Am I overcomplicating things?


r/javahelp 18d ago

Solved Is spring boot + Netty a good idea or no ?

6 Upvotes

I'm making a game server Where I'm using Netty for messaging between the client and the server ,and spring boot for the login/register auth and database layer. Is this a valid approach, or should I just stick entirely to Netty ?


r/javahelp 18d ago

How do I do benchmark on a hybrid Intel CPU (6 P-cores + 4 E-cores)?

2 Upvotes

Recently I have been doing the benchmark test without knowing my System Multiprocessing architecture where I got to know that I have 6P + 4E core. L3 is shared among all and one instance of L2(level 2) cache is shared for E core (12-15) and it's capped at 3.2 Ghz. While my P have 2 cores paried as [(0,1),(2,3)...(10,11)] which is capped at 4.6 Ghz. each have it's own L2 instance.

Caches (sum of all):         
  L1d:                       416 KiB (10 instances)
  L1i:                       448 KiB (10 instances)
  L2:                        9.5 MiB (7 instances)
  L3:                        20 MiB (1 instance)

From /sys/devices/system/cpu/.../shared_cpu_list, I found:

P-core 0 → CPU 0,1
P-core 1 → CPU 2,3
P-core 2 → CPU 4,5
P-core 3 → CPU 6,7
P-core 4 → CPU 8,9
P-core 5 → CPU 10,11

E-cores → CPU 12,13,14,15

When I did benchmark I have noticed my benchmark showing cpu_atom -> which is for E core
and the P-core by cpu there is major change in benchmark. So how do I perform benchmark? use taskset -c 0-11 java -jar target/benchmarks.jar so that it run only only on my physical core? or simply data java -jar target/benchmarks.jar?