The problem you are facing is one I’ve seen over and over again, but with video production on the newer MacBook Pro’s. Apple undersized its power systems with the CPU’s/GPU’s they are using in these systems when you are doing heavy processing like you appear to be doing with Java.
The problem is the amount of power the CPU (and/or its GPU) can use can strip out the stored power within the onboard battery faster than what the charger can supply to backstop it.
Here’s a mind drawing to see this: You have two tanks one holds 50 gallons of water and you have a second larger tank with has 100 gallons of water but the pipe between the two tanks is half as large as the pipe exiting the smaller tank. Now normally your system never draws more than 25 gallons in a session. But when you run your app the power need is 90 gallons so in a short amount of time the first tank is emptied and now the larger tank is being drawn from but as its connection is limited it can’t back fill the smaller tank fast enough for the amount you are drawing off.
You’re hitting the limits of the system. It’s also possible the spill left a trail of corrosion which is also effecting things here as well.
You also have a second issue which is you are over stressing the battery. Clearly you’ve used a lot of cycles (220) in about six months! That’s a lot! You are draining your battery down to the bone and then recharge it which besides ticking off a cycle you are likely boiling the electrolytic so the battery is starting to breakdown (blister) as repeated deep discharge and recharges is not the expected use pattern Apple was expecting in its design.
'''So what to do???'''
I think you’ll need to look at getting a more powerful desktop to compile your larger Java code projects.
You may need to also get your Mac’s battery replaced to if you find its blistered to much as well as inspect the logic board for any corrosion. And lastly get into the habit of plugging in more and not letting the battery drain below 1/3 of its capacity before recharging. I would also recommend getting a good thermal management program like [https://www.tunabellysoftware.com/tgpro/|TG Pro] so you don’t run into a second issue which is over heating your T-CON board which creates black bands at the top and bottom of the display.