r/javahelp

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

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??

reddit.com
u/Chaos-vy17 — 17 hours ago

Java

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

reddit.com
u/Objective-Forever-65 — 2 days ago

Should I have to be very good at this topic ?

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
reddit.com
u/Financial_Baker9908 — 2 days ago

Guide for Concurrency in Java

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??

reddit.com
u/Chaos-vy17 — 3 days ago
▲ 1 r/javahelp+1 crossposts

How to start codeforces with Java?

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.

reddit.com
u/Sure-Willow5490 — 3 days ago

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

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?

reddit.com
u/KeineAhnungBruder001 — 4 days ago

i want to start java spring boot from 0

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

reddit.com
u/Spirited-Mine-3011 — 4 days ago

Is spring boot + Netty a good idea or no ?

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 ?

reddit.com
u/Hamza_yassen — 6 days ago

Is an IDE absolutely needed for java development?

Hello.

Edit: I've decided it's probably best to use an IDE either way.

Whenever I search for the best Java compilers, I've only founds sites listing the best IDE.

Is there a way to keep java development minimal? Can I just use vim and a java compiler like you can with C?

I'm very inexperienced when it comes to Java.

Thank you in advance.

reddit.com
u/Rogaev — 9 days ago

From text games to a Dwarf Fortress-style ASCII roguelike in Java: where to start?

Hi r/javahelp, I already know the syntax and OOP, of course. I've written a couple of text-based games, I know about the GameLoop and other stuff. My main goal is to make a game like Dwarf Fortress Classic, you know, with ASCII graphics and Perlin noise generation. Could you advise me on what I need to learn for this and maybe provide links to documentation? I understand that writing something like this at my level is still unrealistic, which is why I'm asking to know which direction to move in. Thanks

reddit.com
u/Artek_2023 — 7 days ago

Just finished Java basics & OOP. What's the best next step to keep practicing daily?

​Hi everyone,

​I’ve recently wrapped up learning Java fundamentals and core OOP concepts. Now I’m looking for the most effective roadmap or daily routine to stick with the language and apply what I've learned through real practice.

​For those who stayed consistent:

​What projects or challenges (like LeetCode, HackerRank, or building specific projects) helped you the most at this stage?

​What is the natural next step? (e.g., Spring Boot, Data Structures, JDBC/Databases)?

​Any advice or resources would be greatly appreciated! Thanks in advance.

reddit.com
u/sedrtt — 9 days ago

I keep getting moved between technologies/projects and now I'm struggling with a huge Java codebase — how do I build real depth?

I'm looking for advice from experienced developers, especially people who have worked on large enterprise/legacy Java codebases.

I'm in a situation where I can complete development tasks, especially with the help of AI, but I don't feel that I have developed the depth of understanding I should have. I'm trying to figure out how to fix that while also considering a job switch.

How I got here

My career so far hasn't been very consistent in terms of technology.

Before moving to my current main client/project, I worked on several POCs and smaller projects where I got exposure to:

- React.js

- JavaScript

- Java

Then, when I moved to the main client project, I was initially assigned to C#/.NET work.

I spent around 6–7 months working in the .NET stack.

After that, because of project/team requirements, I was moved again and eventually ended up working on a large Java-based enterprise product.

So my journey has been roughly:

React/JavaScript → Java exposure → C#/.NET for ~6–7 months → large enterprise Java codebase

The problem is that I never really got the opportunity to stay with one technology/product for a long enough uninterrupted period to build very deep expertise.

At the same time, some of my colleagues have been working continuously on this same product for around 1.5–2 years.

They also had senior developers guiding them when they started, explaining the architecture, code flow, conventions, design decisions, etc.

I didn't have the same kind of guidance.

So now I'm comparing myself with people who have spent much more continuous time in the same ecosystem, and I feel significantly behind them.

The current codebase

The product I'm working on is a very large enterprise Java application.

It's not a typical Spring Boot application.

It primarily uses things like:

- Core Java

- GWT

- Plugin/module-based architecture

- Java services

- Various internal frameworks/utilities

- Different plugins handling different responsibilities

For example, there may be separate plugins/modules for:

- Authentication

- UI

- User management

- Product-specific functionality

- HTML generation/building

- Other platform functionality

So when I receive a defect, the difficult part isn't always writing the Java code.

The difficult part is figuring out where the code actually is and how everything connects.

I might have to determine:

Which plugin owns this functionality?

Which class is the entry point?

Which service is called?

Does it call another plugin/service?

Where does the actual problem occur?

What will be affected if I change it?

This is where I struggle.

My dependence on AI

Because the codebase is huge and work is high-pressure, I rely quite heavily on AI.

For example, when I receive a defect, I might give the defect description to AI and ask it to identify potentially relevant classes.

Then I inspect those classes, understand the suggested flow, make the changes, debug/test them, and review the code myself.

I don't want to blindly copy AI-generated code.

The problem is that sometimes I'm under enough time pressure that I end up using AI to get to the solution much faster than I could independently.

Then I realize:

"I fixed this, but do I actually understand the complete flow?"

Sometimes the answer is no.

And that bothers me.

Code reviews are where I feel the gap most

My colleagues who have been working on the product for 1.5–2 years can often look at a defect and immediately understand where the problem is likely to be.

They know things like:

«"This functionality belongs to this plugin."»

«"This service eventually calls this manager."»

«"Don't modify this class because it's shared by these flows."»

«"This behavior is actually controlled somewhere else."»

I don't have that intuition yet.

During code review, I sometimes get questions like:

«"Why did you change this here?"»

«"Explain the flow."»

«"What happens if this condition occurs?"»

«"Why did you choose this approach?"»

And sometimes I can explain my actual code change, but I can't confidently explain the entire architecture or execution flow behind it.

That's affecting my confidence.

My work environment doesn't help

The environment is quite stressful.

There is significant pressure around defects and failures, and I don't always feel comfortable showing uncertainty.

When something goes wrong, there can be a tendency to focus on who made the change and what mistake they made.

Because of this, I sometimes feel like I need to make sure everything is correct before showing my work, rather than being able to openly say:

«"I don't understand this part. Can someone explain it?"»

This has made me more cautious and has probably contributed to my reliance on AI.

I also don't have much energy after work

I've considered the usual advice:

«"Study Java for 2–3 hours every day."»

But realistically, my job takes a lot out of me.

I don't think I can sustainably work all day and then study several more hours every night.

So I'm thinking of integrating learning directly into my work.

For example, if I encounter:

An annotation → understand what it does and why it's being used.

An interface → understand why the code uses an interface.

Inheritance → understand why the hierarchy exists.

A design pattern → understand the problem it solves.

A plugin interaction → understand why responsibility is split between plugins.

A service → trace its callers and dependencies.

A defect → understand the complete execution flow rather than just finding the line that needs changing.

I'm also considering keeping a small knowledge base for every defect:

Defect

Root cause

Execution flow

Classes/plugins involved

Java concepts

Design pattern

Reviewer feedback

What I learned

I'm also considering switching

I'm seriously considering a job switch because I don't think the current environment is ideal for my growth.

So I have two goals that I need to balance:

Short term:

Become competent enough in my current project that I can independently understand defects and confidently explain my changes.

Medium term:

Develop transferable skills that will help me get a better software engineering role.

For the switch, I'm thinking about focusing on:

- Core Java

- OOP

- Collections

- Generics

- Exception handling

- Multithreading

- JVM fundamentals

- Design patterns

- SOLID

- SQL

- REST APIs

- Testing

- Git

- System design

- Spring/Spring Boot

The problem is finding a way to do this without burning myself out.

What I'm looking for advice on

If you were in my position, what would you do?

  1. How would you build deep understanding of a huge Java codebase while working under pressure?

  2. How would you develop the ability to trace unfamiliar code quickly?

  3. Is using AI to locate classes and understand defects a reasonable approach, provided I study the solution afterward?

  4. How would you prevent AI from becoming a crutch?

  5. What Core Java concepts should I prioritize given that my current codebase is not Spring Boot-based?

  6. How would you turn daily work/defects into actual learning?

  7. How would you balance learning my current codebase with preparing for a switch?

  8. What would you prioritize if you had very little energy left after work?

  9. For someone who has jumped between React/JS, Java, .NET and now a large Java enterprise system, how would you go about finally building depth instead of continuously accumulating shallow exposure?

I'm not looking for a shortcut.

I understand that becoming a strong developer takes years.

I just feel like I've been moving between technologies and projects without getting the opportunity to develop a really strong foundation in one area, and now I'm trying to deliberately change that.

I'd especially appreciate advice from senior developers who have had a similar experience or who have learned to navigate large unfamiliar codebases effectively.

reddit.com
u/No_opinions2829 — 8 days ago

​Hi programmers, what is your favorite Java book that you can't live without?

*I'd love to hear from developers who prefer learning through documentation and books. Which digital book helped you master Java the most?*

*​Looking forward to your recommendations.*

Thanks, everyone!

reddit.com
u/sedrtt — 8 days ago

How should I save my 7bit memory?

chaos.tree.nary.BTreeNode object internals:
OFF  SZ                                         TYPE DESCRIPTION               VALUE
  0   8                                              (object header: mark)     N/A
  8   4                                              (object header: class)    N/A
 12   4                                          int NaryNode.keyCount         N/A
 16   1                                      boolean NaryNode.isLeaf           N/A
 17   3                                              (alignment/padding gap)
 20   4                           java.lang.Object[] NaryNode.keys             N/A
 24   4   chaos.tree.core.searchtree.nary.NaryNode[] NaryNode.children         N/A
 28   4                                              (object alignment gap)
Instance size: 32 bytes
Space losses: 3 bytes internal + 4 bytes external = 7 bytes total

ExactByte : 32

Heading mistake 7 bit -> byte
There is 7byte of extra padding
25 byte If I made somehow 24byte JVM would not do padding.
Link: https://github.com/Chaos-vy/ChaosTree/blob/main/src/main/java/chaos/tree/core/searchtree/nary/NaryNode.java

reddit.com
u/Chaos-vy17 — 13 days ago
▲ 6 r/javahelp+1 crossposts

Should I get an OCP Java Certificate?

I'm a Full Stack engineer with 8+ years of experience, mainly with .NET/Angular/React. Currently I'm living in Japan and .NET jobs here are almost non existent. I want to switch to Java related jobs but my resume doesn't have any Java experience.

Is it worth investing time and money and effort to obtain an OCP Java certificate and later a Spring certificate as well? Just so that my resume doesn't automatically get disqualified? I'm interested to know what you'd do if you were in my position.

reddit.com
u/FirmBanana24 — 13 days ago

Java on Code OSS

so i use vs code OSS on void Linux, i was wondering if theirs good alternatives to microsofts java, i saw one from the oracle corp. and then a lot of other like java language support or java run. so i, wondering if i can just do the java extension, or if i need others, or if i should just switch to another IDE or text editor, and if so witch ones do you recommend?

reddit.com
u/AlarmHead1074 — 13 days ago

Can’t install new version

Every time I hit run on the installer for the version I want it tells me there are still some files or directories left over from a previous version even though I have spent hours looking for and deleting them. anyone have a fix?

Note: I have used command prompt and it says there is no Java on my computer

reddit.com
u/OneAmphibian7246 — 13 days ago