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
6 views

Better way to write new method base on old method without copy-paste code in java

description: old method I wrote a old method: get data from parameters check it, throw an exception if failed save them into database. e.g. If I have 3 datas, I'll call them in this order step1-...
leaf_yakitori's user avatar
0 votes
0 answers
30 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
  • 11
0 votes
0 answers
44 views

Looping without looping statement

An alternative to loop statements handy when the domain-specific language (DSL) prevails over the programming language technicalities, is implemented with two instances calling each other while ...
user278619's user avatar
0 votes
0 answers
36 views

Stopping a running thread without testing variables

The Thread stop method is deprecated. The recommendation is to stop running threads by updating a variable. Many uses of stop ...
user278561's user avatar
0 votes
0 answers
28 views

Train Dispatcher in Java [closed]

I am developing a simplified train dispatch system as a final assessment for my CS major, first semester. I have a user interface class, with the TrainDispatch instance as a UI class variable. ...
Mikael Stray Frøyshov's user avatar
0 votes
3 answers
94 views

Java - Should I use getter in method?

I have two working solutions, but which one should I use? Which solution is correct? Solution 1: List<Client> myClient = new ArrayList<>(); ...
user avatar
-2 votes
0 answers
38 views

Melhorar jogo de basquete simples [closed]

Neste código, faça com que quando a tecla de espaço for pressionada, a bola deve completar o seu trajeto. Depois que a bola parar de cair, ela deve voltar para a mão do jogador, na sua posição inicial....
Matheus Silva's user avatar
2 votes
3 answers
106 views

Redouble each occurrence of char recursively, and add n

In following of this question, I would like to have a second review. The exercise is to write a recursive method that takes a String and a ...
Tobias Grothe's user avatar
0 votes
0 answers
41 views

Todo application using Spring Boot 3, Dockerized Postgres, Java 17, Maven

I'd like to have code review for backend of todo app. It has 2 main functionalities: Authentication and authorization using Spring Security and JWT token. CRUD for tasks In particular I'd like to ...
J.Olufsen's user avatar
  • 161
2 votes
1 answer
80 views

Double each occurrence of a char recursively

The exercise is to write a recursive method that takes a String and a char parameter and returns a ...
Tobias Grothe's user avatar
1 vote
2 answers
86 views

Domain Driven Desing aggregate for ticket booking

What do you think about this aggregator (DDD) for booking and cancelling tickets? Is it ok, or would you do it differently somehow? ...
Nofenak's user avatar
  • 11
5 votes
9 answers
286 views

In-memory cache class

The following is a simple cache that I have written in java. It uses the LRU replacement policy and also evicts items based on a refresh interval (default 5 secs). Right now, the class is not thread ...
Nithin's user avatar
  • 51
2 votes
1 answer
47 views

Creating Worst-Case Scenario for QuickSort using Middle Pivot in Java

I've implemented a solution to generate the worst-case scenario for QuickSort using the middle pivot strategy in Java. The goal is to rearrange an input array to produce the worst performance during ...
Lydia Yuan's user avatar
2 votes
1 answer
63 views

FieldInspector: an API for deep object comparison and null checking

Here's my FieldInspector. It compares objects by field values and performs deep null checking. What do you think? It works, but I'm not happy with how it looks. I ...
Sergey's user avatar
  • 401
1 vote
1 answer
80 views

Positioning boxes in a box with backtracking in Java

A large cube-shaped box has the dimensions 5x5x5. This box is to be completely filled with smaller boxes. Possible candidates are: ...
Tobias Grothe's user avatar
-1 votes
1 answer
55 views

Handling exceptions of FileInputStream and XSSFWorkbook

Can you tear my code apart with code review comments? Below is a simple method which reads an XLSX file and does some stuff with it. I use FileInputStream and ...
AutoTester999's user avatar
1 vote
2 answers
91 views

Simple service that wraps access to json file

I'm wondering if this is the best way to write the Java code I have written. It works, but looks overly verbose, is it possible to rewrite any of the code to make it more concise? Please ignore the ...
Professor of programming's user avatar
1 vote
0 answers
58 views

Sequentially bidirectional find the indexes of an element into a collection (second thought)

Embodying the helpful tips from the “Sequentially find the indexes of an element into a collection” previous code review resulted in extending the implementation to bidirectional index lookup, that is ...
user avatar
4 votes
2 answers
132 views

Print the three most occurring chars in Java using streams

The three characters that occurs most in a given string should be printed by using streams/lambdas (functional programming). The order of characters that occur equally often should be preserved. My ...
Tobias Grothe's user avatar
3 votes
1 answer
85 views

Sequentially find the indexes of an element into a collection

Util class to find into a collection the indexes of a given element with multiple occurrences from the first index or relative to a given index. ...
user avatar
1 vote
0 answers
27 views

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

Trying to write a decent answer to Most efficient way to get the largest 3 elements of an array using no comparisons but a procedure for ordering 5 elements descendantly, I came up with something ugly....
greybeard's user avatar
  • 6,104
3 votes
2 answers
112 views

Adhering to Object-Oriented Principles in Fruits and Vegetables Scale Program

I've been working on a project related to a fruit and vegetable scale program for about a month, and I'm relatively new to programming. In this project, I'm trying to adhere to object-oriented ...
Kerem Tazedal's user avatar
1 vote
3 answers
94 views

Another ATMs cash-out (denomination) algorithm in Java

Related to this question and this answer, I would like to have a second review from you on a modified version. The problem I tried to solve Some kind of "Minimum count of numbers required from ...
Tobias Grothe's user avatar
2 votes
2 answers
294 views

Another cash machine with special bill values in Java

Task: An ATM dispenses banknotes with the following values/denominations: {5, 30, 35, 40, 150, 200}. The user should be able to repeatedly enter an amount divisible by 5 without leaving a remainder. ...
Tobias Grothe's user avatar
1 vote
0 answers
49 views

Is this how you do Spring Cloud Gateway?

I'm new to Spring's reactive Gateway. Here's the code that other collaborator and I wrote (the enum is one of my ideas): ...
Sergey's user avatar
  • 401
2 votes
1 answer
39 views

Implementing an improved merge sort that uses insertion sort, with "levels" - Would this work correctly?

We were asked to improve the merge sort algorithm by introducing insertion sort to the code. We have been tasked with doing this by utilising a "levels" logic. Here is the exact description ...
Preatorius's user avatar
2 votes
1 answer
52 views

"2048" game in JavaFX

I wrote my first code in Java and I need constructive criticism and code review. This is an implementation of the well-known "2048" sliding-blocks game. ...
hathor's user avatar
  • 21
4 votes
1 answer
1k views

Determine if it is EU summer time in Java

I wanted to write a utility method for learning purposes to determine if a given date (year, month and day) falls within EU summer time or not, without using any of the Java library methods. Is here ...
Tobias Grothe's user avatar
1 vote
1 answer
135 views

Interview task model implementation(Event Source Java)

I've got a task to implement simple event source and i did: project Events structure ...
verbedt's user avatar
  • 11
0 votes
1 answer
136 views

About self validated Java POJOs

I am currently experimenting with self validating Java beans in order to avoid the creation of objects with invalid states, while keeping the validation knowledge inside the bean. The goals I have in ...
silver_mx's user avatar
  • 109
3 votes
2 answers
261 views

Reduce time complexity to process sub-arrays

For a given integer array of size n, find all possible sub arrays of size k which range from 1 to n. Now find the common item which is also a minimum in all sub-arrays of size k, if no common item is ...
technotigr's user avatar
1 vote
1 answer
86 views

Shrink an array of double elements (uniformly)

Is there a way to avoid the first loop in the method shrink? (if and while...) The utility ...
Tobias Grothe's user avatar
3 votes
1 answer
43 views

Program using java.io that shows the content of a text file and every three lines the program stop reading, waiting to press Enter

I am doing a program in Java your text using java.io that shows the content of a text file and every three lines the program stop reading, waiting to press Enter. I dont know so much about programming,...
polencr_ensayoerror's user avatar
5 votes
2 answers
174 views

Improvements for Java Code of a Fruit and Vegetable Management Application

I have developed a Java application as per a specific assignment, which includes features for adding, searching, and removing fruit and vegetable products. I would like a review of my code in terms of ...
Kerem Tazedal's user avatar
6 votes
1 answer
116 views

One or more planets to line up with the earth a certain amount of times

I have attempted the below question, however my solution is too slow (i.e. It does not fit the 2 second time constrain for java). How can the solution be optimised? While at IOI 2020 in Singapore, ...
Zareef Akoodie's user avatar
2 votes
2 answers
122 views

Thread-safe coordinate holder

I have been given a task to create a thread-safe RobotCluster class. The idea is that there's a set of robots operating on multiple threads and they each submit the ...
Bula's user avatar
  • 379
1 vote
2 answers
82 views

Verification job with multiple type of batch verifiers

I have a use case where a verification batch job (non-generic) verifies domains based on its input e.g domain_type, batch_pointer etc. The verification handles it based on the domain type which uses ...
user3239193's user avatar
1 vote
1 answer
120 views

Business logic verification template

I have a use case of template design pattern with generics as mentioned below. I have AbstractVerificationHandler that provides template for verification business ...
user3239193's user avatar
3 votes
2 answers
167 views

Add offset to all filenames

From all the files in a directory, the method shiftFilenamesOffset is to increment the numeric part (int) of the alphanumeric filename by offset each time, and ...
Tobias Grothe's user avatar
3 votes
1 answer
90 views

Performance of this BCrypt lossless compressor

The following code compresses a 60-byte BCrypt MCF into 40 bytes. Does anyone see room for performance or other optimizations? For example, I should replace Guava's ...
Oliver's user avatar
  • 93
2 votes
1 answer
134 views

Find character at given index in a sorted sub strings [closed]

For a given string say dbac the possible substrings are [d,db,dba,dbac,b,ba,bac,a,ac,c]. Sort them and concatenate to a string: ...
technotigr's user avatar
2 votes
2 answers
177 views

Java Tic-Tac-Toe Game Implementation - Seeking Feedback and Best Practices

I have recently developed a Java program for a simple Tic-Tac-Toe game and would like to request a code review to improve its quality and learn from experienced developers. Below is the code for my ...
drunk mado's user avatar
0 votes
0 answers
65 views

A Java program interfacing with Gnuplot for generating triangle wave plots

Intro I have this repository. Given this command ...
coderodde's user avatar
  • 27k
1 vote
1 answer
83 views

Mapping composition in Java - v2

This post is the continuation of Mapping composition in Java. This time, I: Disallowed the null values as the range value. Simplified the ...
coderodde's user avatar
  • 27k
1 vote
2 answers
52 views

Spring Boot REST API for moving toy robot in 5*5 grid [closed]

I have designed and coded REST APIs to move the toy robot in 5*5 grid. Please let me know any feedback on improvements, etc Complete Code here: https://github.com/pkkht/RobotRESTApp ...
Hariharan's user avatar
0 votes
1 answer
184 views

Spring Boot Azure Service Bus Listener

I would greatly appreciate your feedback and review of our Spring Boot Azure Service Bus listener implementation. Your insights and suggestions will help us ensure its efficiency and reliability. ...
Siyamcela Nxuseka's user avatar
2 votes
2 answers
134 views

Counting duplicate elements in two sorted arrays

I've been working on an assignment that involves optimizing a duplicate finding algorithm for sorted arrays, and I'd like to get your thoughts on the implementation. Here's the code I've come up with: ...
Bryan C's user avatar
  • 21
0 votes
0 answers
131 views

Chain of Responsibility in the game of Hangman

I tried to do the Hangman Refactoring Kata for the piece of code over here - https://www.youtube.com/watch?v=-0MeoFTj6DU This is how the initial code looks like after first set of refactorings (i.e. ...
yadav_vi's user avatar
  • 486
0 votes
1 answer
58 views

DDD Aggregate for seat booking in cinema - is my model correct?

I created a DDD aggregate for booking seats in cinema. Is it corect or it should be model in other way? Business rules: 1.Seat can be booked at least 1h before screening 2.Screening can has only 1 ...
Nofenak's user avatar
  • 11
1 vote
1 answer
124 views

blog RESTFUL api with posts and comments

I built RESTFUL api for a blog using java and spring boot(without a frontend). What it does the code manages all the http methods on a post inside the blog and comments on that post. the post consists ...
Ellie's user avatar
  • 347

1
2 3 4 5
217