Questions tagged [java]
Java (not to be confused with JavaScript) is a class-based, object-oriented, strongly typed, reflective language and run-time environment (JRE). Java programs are compiled to bytecode and run in a virtual machine (JVM) enabling a "write once, run anywhere" (WORA) methodology.
10,850
questions
3
votes
1
answer
31
views
Time based cache for single element
The container should be thread safe and provide lazy load of data, and cache the data for set period of time.
...
1
vote
0
answers
18
views
User Management System: a web app for management of user records (Part I: Backend)
Note: It's Part I of the User Management System project, focused on the backend. See Part II here.
I made this app about a year ago. I was a fledgling developer who didn't have a lot of clues to what ...
1
vote
0
answers
30
views
(Another) text formatting method with word wrapping in Java
Please take a look at my code for (simply) formatting/wrapping a text. Is there anything to improve or have I missed something? I have also added some tests.
Here are my requirements:
a line of text ...
-3
votes
0
answers
22
views
Debugging Leader-Election Algorithm in Ring of Rings Network Structure [closed]
I am developing a leader-election algorithm within a hierarchical ring network structure, where each subnetwork (ring) contributes to forming a larger, encompassing ring (referred to as the main ring)....
0
votes
0
answers
26
views
Efficient least-significant digit (LSD) radix sort for int and long keys in Java - iteration II
This post elaborates on Efficient least-significant digit (LSD) radix sort for int keys in Java. This time, I made mild corrections to my code and provided the radix sort for ...
0
votes
0
answers
29
views
ParamInitializer framework: automatic provision of expected request parameters by Spring Cloud Gateway
I continue to share portions of my Dynamic Gateway project
This time, I want to publish the types relating to its "parameter initializing" functionality. The idea is simple: if my gateway ...
0
votes
0
answers
32
views
Retrieving resources of JWT-authenticated user Spring Boot Java
I have a Java Spring Boot Rest-API which is authenticated using JWT-tokens. Currently the API only contains Users and CashflowCategories. An user can have many CashflowCategories.
When the user makes ...
3
votes
1
answer
110
views
Efficient least-significant digit (LSD) radix sort for int keys in Java
(This post has a continuation post.)
This one is my attempt at LSD radix sort:
Code
com.github.coderodde.util.LSDRadixsort.java:
...
0
votes
0
answers
25
views
Scaffolding through my own language (Rapid Application Development)
I'm developing a webapp where some parts that repeat, so I made source code to generate source code.
I had a lot of fun using Spring-Roo and Grails in the past but was sad that the difference between ...
3
votes
1
answer
30
views
Any possible issues with my approach to Access Management where I'm associating the list of Departments with the User class?
I have a spring boot project with JWT being used for Spring Security. I want to implement Access Management in my project and I'm using this approach. In my project, whenever a user is created, a list ...
1
vote
1
answer
60
views
Multiple Producer and Multiple Consumer Implementation Using Locks and Semaphore
This solution has a total of four classes.
Main.java: Class with main method. Execution starts here.
...
3
votes
1
answer
288
views
Implementation of java.util.stream.Stream (and friends) that reads lines from the internet without requiring you to manage the resources
This streams lines of information over the internet using BufferedReader::lines.
However, what makes this special (and thus, extraordinarily complicated imo) is ...
4
votes
2
answers
431
views
Leetcode: Steps to Make Array Non-decreasing
I was trying out leetcode's Steps to Make Array Non-decreasing
As per the challenge's description:
You are given a 0-indexed integer array nums. In one step, remove all
elements nums[i] where nums[i ...
4
votes
2
answers
77
views
Choosing Between Field Injections and Constructor Injections for Modular Java Applications with Spring Boot
I'm six months into a Java training program and have developed a Spring Boot application, adhering to Java's separation of concerns principle. I've organized my application with distinct sections for ...
1
vote
1
answer
58
views
An API fetcher class - afraid of overengineering class
I'd like to ask you for a code review of this class. I'm quite new to Java and I'm afraid I have way overengineered this class. It's goal is only to fetch a specified data from given API, whose link ...
1
vote
3
answers
105
views
Find min sum for indices to match equation
I want to reduce time complexity of my code:
I have an array of integers arr say [1, 2, 3, 6, 67]
I have an equation :
a*x+b*y=z, I can use the array values in this ...
1
vote
0
answers
62
views
Skip list -based Map in Java
Now I have this result.
Code
com.github.coderodde.util.SkipListMap.java:
...
9
votes
4
answers
2k
views
Leetcode : First Missing Positive
I was trying out leetcode's first missing positive.
As per the challenge's description:
Given an unsorted integer array nums, return the smallest missing
positive integer.
You must implement an ...
2
votes
2
answers
100
views
Simple authentication server
Here's a simple authentication server. It's pretty basic but has the core functionality of sign-up and log-in handling. Your best bet is to simply run the ...
2
votes
1
answer
126
views
First order hidden Markov model with Viterbi algorithm in Java
Introduction
A first order HMM (hidden Markov model) is a tuple \$(H, \Sigma, T, E, \mathbb{P})\$, where \$H = \{1, \ldots, \vert H \vert\}\$ is the set of hidden states, \$\Sigma\$ is the set of ...
-4
votes
1
answer
35
views
Find the greatest possible non repeating sub-string in a string in java [closed]
Here i tried to find the longest possible non repeating sub string in a string in java..plz check my code for errors and give some suggestions for improvement...
...
3
votes
1
answer
101
views
Parsing Java's class file
The structure of a class file consists of a single structure (presented here using pseudostructures written in a C-like structure notation):
...
5
votes
2
answers
207
views
2048 game in Java
I am a beginner learning Java, and I coded a command line version of the game 2048 for practice. Any feedback, especially regarding best practices, object-oriented principles, and tidying up the code ...
1
vote
3
answers
92
views
Maximum Sum BST in a Binary Tree
I was trying to find the Maximum sum BST of a binary tree on LeetCode. While the Java code I have come up with, mostly seems right and is able to pass 55 out of the given 59 test cases too, the error ...
1
vote
0
answers
76
views
Flexible AuthenticationExtractionWebFilter
I decided to share with you a portion of my gateway project. It's an authentication extraction filter that extracts authentication claims without being coupled to any specific authentication mechanism....
7
votes
2
answers
157
views
Java code to delete all empty folders within a directory
Given the path to a filesystem directory, the task is to delete all empty directories within that root directory. After the process is finished, no empty dir should exist under the root directory (the ...
4
votes
1
answer
511
views
Lazily decode a buffer with a thread-safe Iterator
I have implemented an Iterator for my Pojo class.
The purpose here is to lazily decode multiple ...
6
votes
3
answers
107
views
Pascal's triangle in Java
I created a Pascal's triangle. I'm in 2nd semester, so I'm not that professional in programming. If there are some suggestions for improvement, please tell (took me 2 & 1/2 hrs to find the logic).
...
1
vote
0
answers
70
views
custom serialization of an HttpSession-stored class to get it replicated between cluster nodes
As a part of guice-context-scopes library for building custom Guice Scopes, I have a class named InjectionContext (code below), that stores scoped objects in a <...
2
votes
1
answer
76
views
Semi-dynamic range minimum query (RMQ) tree in Java
Introduction
I have this semi-dynamic range minimum query (RMQ) tree in Java. It is called semi-dynamic due to the fact that it cannot be modified after it is constructed. However, the values ...
1
vote
0
answers
41
views
updated utility for automatic websocket ping-pong and receiving round-trip time reports
This is a follow-up to this question. Please check it out first for the motivations, known use-cases and explanations.
In this new version I've applied several of advices from this answer by @J_H:
...
3
votes
1
answer
54
views
UriValidator (+ tests)
My last project shared here was apparently too complex so I figured I'd share something really simple
Here's a UriValidator. Its purpose is to validate URI paths ...
1
vote
2
answers
80
views
Java Queue data structure
Could you review this implementation of a queue data structure according to the principles of Object Oriented Programming and Clean Code?
...
2
votes
3
answers
196
views
Java Clean Code, use of enums in data structure
I have defined a data structure in Java that allows to manage certain type of elements like a Queue, with the special feature of using 2 inner rows (windows) to attend elements:
...
1
vote
1
answer
95
views
Bit vector in Java supporting O(1) rank() and O(log n) select() - follow-up
(This post is the continuation of Bit vector in Java supporting O(1) rank() and O(log n) select(). It resides here (version 1.0.1).)
Basically, I have implemented everything harold suggested, except ...
-2
votes
1
answer
39
views
which layer is more fit to check data integrity: service or database? [closed]
I read a book named Effective SQL and found this interesting part.
Enforcing and maintaining business rules and relationships in
the data is part of the data model, and the responsibility belongs to ...
1
vote
1
answer
65
views
Inserting large number of rows into database with Spring boot
I need to insert many million rows + many GB of data into a database for a project that uses Spring boot. I recreated a minimal example with a one to many relationship and am trying to find the ...
1
vote
1
answer
145
views
Bit vector in Java supporting O(1) rank() and O(log n) select()
Introduction
I have this GitHub repository (version 1.0.0.). It implements a rank(i) operation in \$\Theta(1)\$ time, and ...
3
votes
2
answers
102
views
Text based Java game "Battle Arena"
This is my first java program. I'm coming from a python background. This is a text based combat arena game.
Are there any ways I could better implement the overall code structure?
How might I improve ...
3
votes
2
answers
100
views
utility for automatic websocket ping-pong and receiving round-trip time reports
Without ping-pong websocket connections are usually dropped by intermediary proxies/routers after some time of inactivity, so you can't go make yourself a coffee because your chat connection will ...
0
votes
2
answers
50
views
How to find a more effective way to load a file and compare in the service
I have a malware detection system that includes a subsystem responsible for IBAN checks. Initially, this subsystem needs to load and parse data from a specific URL. Subsequently, it checks whether the ...
2
votes
2
answers
176
views
Encrypt a String using AES in CBC mode
Your opinion interests me regarding this program.
This program encrypts a text message using the AES256 algorithm and CBC.
It allows the creation of an encrypted message that contains:
The salt used ...
2
votes
0
answers
56
views
Implement Iterable where hasNext depends on mutable object state, which is mutated through explicit call
I am trying to implement the Iterable interface on an object, where the hasNext method on iterator will depend on mutable object state. This state is mutated by ...
3
votes
1
answer
89
views
utility to manipulate java.util.logging config using command-line system properties
This is intended for temporary ad-hoc changes to logging config, for example when debugging etc. Also included are functions to easily manipulate config from a code (for example at the beginning of a ...
2
votes
1
answer
95
views
Add field and value into an object by reflection
original code:
import, hide some irrelevant company package
...
0
votes
1
answer
67
views
decorator for an Executor that allows to get a List of running tasks
As stated in the javadoc below, this is intended for monitoring and debugging. I've found it especially useful for figuring out which tasks got stuck and prevented clean terminations of my ...
3
votes
1
answer
202
views
Read a list of value display it depends on pagesize and current page
code feature: read a list of value display it depends on pagesize and current page
original code:
...
1
vote
2
answers
132
views
Fully generic, very efficient bidirectional Dijkstra's algorithm in Java
After finding out that my previous implementations are incorrect, I decided to give it another try. I relied on this post.
(The entire project resides in this GitHub repository. Contains some unit ...
2
votes
2
answers
89
views
Add category section and save in database in admin section with java and javafx using mvc
As I newbie in (java and MVC), I want to know if I understand MVC using java.
My concern is that some of the calls of the class are in the wrong place or, for example, I should have used the interface ...
3
votes
1
answer
95
views
simple multi-threaded TCP chatroom in Java
I'm fairly new at coding and looking to improve. Down below is all of my files for a TCP chatroom with a GUI in java. This is my first networking project so I'm sure it has many problems and does not ...