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.

Filter by
Sorted by
Tagged with
0 votes
0 answers
16 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 ...
Sergey's user avatar
  • 481
2 votes
1 answer
87 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 ...
coderodde's user avatar
  • 27.6k
-3 votes
1 answer
31 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... ...
Jarrar's user avatar
  • 55
3 votes
1 answer
86 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): ...
Harith's user avatar
  • 4,071
-2 votes
0 answers
37 views

Startup code improving fetched from DB JPA

This is my startup code that joins two tables StoreConfiguration and GateConfiguration. I save the. Storeid is pk in store and FK for gate. What follows is the entity information: We store this on ...
darthwader's user avatar
5 votes
2 answers
163 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 ...
smwt's user avatar
  • 185
0 votes
2 answers
69 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 ...
Siddharth Garg's user avatar
1 vote
0 answers
55 views

AuthenticationWebFilter with no hard-coded dependency on a specific authentication scheme

I decided to share with you a portion of my gateway project. It's an authentication filter that (unlike Spring's own AuthenticationWebFilter with its hardcoded ...
Sergey's user avatar
  • 481
7 votes
2 answers
141 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 ...
blaze9's user avatar
  • 71
4 votes
1 answer
507 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 ...
William's user avatar
  • 141
6 votes
3 answers
102 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). ...
Jarrar's user avatar
  • 55
1 vote
0 answers
66 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 <...
morgwai's user avatar
  • 362
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 ...
coderodde's user avatar
  • 27.6k
1 vote
0 answers
39 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: ...
morgwai's user avatar
  • 362
3 votes
1 answer
50 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 ...
Sergey's user avatar
  • 481
1 vote
2 answers
78 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? ...
Cardstdani's user avatar
2 votes
3 answers
189 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: ...
Cardstdani's user avatar
1 vote
1 answer
93 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 ...
coderodde's user avatar
  • 27.6k
-2 votes
1 answer
37 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 ...
bear su's user avatar
1 vote
1 answer
55 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 ...
Pux's user avatar
  • 155
1 vote
1 answer
144 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 ...
coderodde's user avatar
  • 27.6k
3 votes
2 answers
101 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 ...
spaghetticode's user avatar
3 votes
2 answers
97 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 ...
morgwai's user avatar
  • 362
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 ...
Nesly's user avatar
  • 17
2 votes
2 answers
167 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 ...
b210205's user avatar
  • 33
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 ...
Abhijeet srivastava's user avatar
3 votes
1 answer
83 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 ...
morgwai's user avatar
  • 362
2 votes
1 answer
91 views

Add field and value into an object by reflection

original code: import, hide some irrelevant company package ...
leaf_yakitori's user avatar
0 votes
1 answer
62 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 ...
morgwai's user avatar
  • 362
3 votes
1 answer
201 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: ...
leaf_yakitori's user avatar
1 vote
2 answers
130 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 ...
coderodde's user avatar
  • 27.6k
2 votes
2 answers
87 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 ...
F.M's user avatar
  • 129
3 votes
1 answer
93 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 ...
James Cowsert's user avatar
5 votes
3 answers
646 views

Program that brute forces to find the minimum dominating set

This program solves the minimum dominating set but it takes an insanely long time to run. In case you do not know, in graph theory, a dominating set for a graph G is a subset D of its vertices, such ...
BeginnerProgrammer6's user avatar
4 votes
2 answers
386 views

Map constructor utility class in Java 8

In a Java 8 project, I'm using several maps, many of which contain static or default content. In Java 9 and newer, there's the convenient Map.of() method and I want ...
Green绿色's user avatar
1 vote
0 answers
14 views

Determine top t values with few calls to order(), a given procedure to order k values, Java take 2

My 2nd take of the problem in Determine top t values with few calls to order(), a given procedure to order k values: Given an array and a procedure to order \$k\$ ...
greybeard's user avatar
  • 6,286
1 vote
0 answers
34 views

Websocket code to be improved

This is the plain websocket code that connects with mobile app. Once we send a REST request from another service say B to our service A we send a websocket payload over the response. This runs in ...
darthwader's user avatar
0 votes
0 answers
38 views

Video Poker with luck modifier

While grinding for coins on the GTA San Andreas casino poker machines I started to wonder how exactly one might implement a luck modifier to a video poker game without it being completely obvious to ...
TorbenPutkonen's user avatar
1 vote
0 answers
92 views

Generating group permutations: an extended Heap's algorithm in Java

Suppose we have a sequence of sequences <1, 2> <3, 4>. There, we have two groups: <1, 2> and ...
coderodde's user avatar
  • 27.6k
3 votes
2 answers
242 views

Calculate the base 10 log with loops in Java without using Math

I'm looking for a simple way to calculate the logarithm without using java.lang.Math, just out of interest. Here's my try (I adopted some code parts from this ...
Tobias Grothe's user avatar
3 votes
3 answers
185 views

A simple message bus in Java

Now I have this simple message bus in Java. This one is as simplistic as I could get. Code com.github.coderodde.messagebus.AbstractMessageConsumer.java: ...
coderodde's user avatar
  • 27.6k
0 votes
1 answer
39 views

Object build while sequential read user input [closed]

The implementation reads sequentially the user's input changing the type to build according to user choices. There are two main components a conditional structural sharing (...
user avatar
2 votes
2 answers
92 views

Find all line numbers of prefix duplicates with streams

All line indices of lines from a text that begin with the same line prefix should be found. The prefixes and the corresponding line numbers should be returned. Streams and lambdas should be used as ...
Tobias Grothe's user avatar
-1 votes
1 answer
87 views

Peer Bank transfer code issue [closed]

Problem description: Write a method that takes in 2 parameters: A string containing either "A" or "B" indicating the recipient of a bank transfer. An integer array containing the ...
Dirtygears's user avatar
2 votes
4 answers
162 views

Comparison of two excel files ignoring line order

Below is a simple method which compares contents of two excel files ignoring the line order. This method is working as expected. But, one of my peers in their code review mentioned that initializing ...
AutoTester999's user avatar
4 votes
1 answer
73 views

Generic Algorithm X implementation with dancing links (DLX)

This is a generic implementation of Knuth's "Algorithm X" using dancing links. The whole code with a "mandatory" sudoku solver can be found at gitlab. Regarding the scope of the ...
TorbenPutkonen's user avatar
-2 votes
2 answers
78 views

complexity reduction (refacto) [closed]

I'm trying to reduce the complexity of this piece of code following a SonarQube error. I have several similar blocks, and even if I try to extract them into private methods, the Sonar error persists. ...
goujon's user avatar
  • 11
2 votes
1 answer
75 views

A JavaFX canvas - based UI view component for representing data points in three dimensions

I have this pie chart. It encodes data points in three dimensions, which are encoded via sector radius, sector angle, color intensity of the sector. How it looks like? (See here.) Code ...
coderodde's user avatar
  • 27.6k
3 votes
1 answer
108 views

Simple blackjack program in Java

I wrote this blackjack game for my APCSA class (already submitted) and was wondering if anyone had feedback on what parts of it are improperly written. My main concern is the fact that I am printing ...
nohgo's user avatar
  • 31
0 votes
1 answer
63 views

Fetching seats for screening

Each screening has an assigned room and the room has seats. I need to display the seats for the given screening with information if it is free. The way I do it now is that I get the id of the ...
Nofenak's user avatar
  • 39

1
2 3 4 5
218