Skip to content

Tag: java

Selection sort with LinkedList in Java

I would like to implement selection sort using LinkedList in Java. I know how to do it with ArrayList, please don’t comment that I should use it instead. I am interested in demonstrating the advantages (fast insertion and removal) and disadvantages of linked lists compared to arrays. I know how to do th…

Thread.sleep behaviour with non-volatile boolean variable

According to the JLS 17 specification section 17.3: For example, in the following (broken) code fragment, assume that this.done is a non-volatile boolean field: The compiler is free to read the field this.done just once, and reuse the cached value in each execution of the loop. This would mean that the loop w…

Spring event lifecycle

To understand if the spring events fits the task im working on I need to understand how they work, where are they stored? as I can guess they are stored in a spring application context and disappears if the application crashes, is my guess correct? Answer Spring events are intended to use when calling methods…

Removal of usage-links in IntelliJ

While changing PCs I downloaded the latest version of IntelliJ (2022.1.2 Build #IU-221.5787.30) and I can now see usage links for all fields, methods and such in my code. It does seem to work as it is supposed to, but I find that it takes up too much space and would like to turn it off. I am yet to

Java streams – Get max two objects depending on condition

Relatively new to java streams and I have encountered an issue which I could not find a solution for. I have A list of 10 objects and filtered them to return 4 objects. this returns 4 objects: So basically what I am trying to do is take stages that have the same value of stageToCalc and find the maximium stag…

How to pars inner XML Tags with SAX

I am trying to read data from an XML file by using SAX. But i cant figure out how to handle the inner <Path> Tag… How to do pars the inner path element? This is my XML file. Here the neccessary java code snippets. I dont feel like adding the following code is the right approach at all … I

AES Encryption algorithms and padding scheme

Hello currently i have to do an AES encription and send it to an external SW but i am having trouble with the sonarqube. this is the relevant part of my current code: Is a little spaguetti cause it´s recyclated for an old code (TripleDES) sorry for that. But we can get the gist of it that`s that we are