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
4 votes
2 answers
267 views

Multiplayer queue optimisation

I currently have code that is working but I think it can be optimised. The code waits until a player joins and adds the player to a BlockingQueue if there is not already a Player waiting then it ...
Lee's user avatar
  • 43
0 votes
1 answer
127 views

First try at Java annotations and using them to change instance values

I was curious on how annotations are used during runtime, so after some googling I gave it a try, but kinda have the feeling that is not the proper way as I still have to call the annotation helper on ...
Alex.B's user avatar
  • 53
0 votes
1 answer
71 views

How can I refactor getAll() method for the service business logic? [closed]

I'm working with the following project, where I have business-logic as: ...
invzbl3's user avatar
  • 121
3 votes
1 answer
93 views

Company management app: Extracting data with JDBC and java.sql

I'm currently working on a company management system as a university project, and I have to get my hands in java.sql. I have come to struggle with extracting a ...
Thomas Herondale's user avatar
4 votes
2 answers
241 views

Designing a basic Binary Expression Tree structure

Preface I need to generate some algebraic expressions for math testing in elementary school. The test should generate a list of expressions compiled according to certain rules and check the ...
chptr-one's user avatar
  • 495
-2 votes
1 answer
316 views

Number Plate Generation Program

I wrote a number plate generation program. The program generates number plates for a car registered with a specific Memory Tag and on a specific date. Number plates use the following format: (2 letter ...
kmvfkmfv's user avatar
1 vote
0 answers
163 views

Restaurant Management follows MVC pattern

I am writing the Restaurant Management homework which must be following the MVC pattern. My Menu model has two parts: Drink menu and Food menu. With Food menu, it separates into three different types ...
David Moore's user avatar
3 votes
1 answer
153 views

An encryption/decryption program with two different algorithms, Caesar Cipher and a Unicode Cipher

This project was part of the JetBrains Academy Java course. The project was about implementing an Encryption program that uses either a simple Caesar Cipher (or) a Unicode Cipher depending on the ...
booma vijay's user avatar
1 vote
2 answers
92 views

Having a separate validation util for common checks

I am working on a project where I see the following methods wrapped in a Util class ...
srk's user avatar
  • 608
4 votes
1 answer
205 views

Find largest number of collinear points

The following is my submission for LeetCode's Max Points on a Line: Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane, return the maximum number of points that ...
Matt's user avatar
  • 141
1 vote
3 answers
74 views

FileIO lines to String Converter

I think I made a good FileIO object because I can simply copy-paste whenever I need, however I wonder How I can improve my code. This code takes file path of the target file and turns every line to ...
ekan123's user avatar
  • 13
0 votes
2 answers
286 views

Functional Style if/else in java

I would like to ask the opinion for experts out there. The following code snippet was written by a colleague of mine who is very fond of functional style in Java. ...
office.aizaz's user avatar
6 votes
4 answers
7k views

Printing a Hollow Butterfly pattern

I am a beginner to Java and have studied up to loops only. After loops lecture above pattern was given to print as homework. I have successfully managed to print this pattern with following code: <...
Strange Alchemist's user avatar
1 vote
1 answer
91 views

Take meal orders from breakfast, lunch and dinner menus

I have an exercise requires me to write a service to management menu. The requirement like this: Food menu includes: breakfast menu, lunch menu, dinner menu. The three menu haves list menu item( name, ...
David Moore's user avatar
1 vote
3 answers
628 views

Refactoring count Lines of Java code

My task is: In this challenge, write a function CountLOC.count to count the lines of code in a Java source file. A line of code is defined as any line in the source which contains at least one ...
invzbl3's user avatar
  • 121
1 vote
2 answers
109 views

Circular list vs. doubly-linked list: which is faster?

In this post, I will compare performance of a circular list and a conventional list with head/tail -references: ...
coderodde's user avatar
  • 27.6k
2 votes
0 answers
570 views

Space invaders in java swing

I am not really proud of the final project design. Whenever I try following MVC I get lost and in the end a lot of code doesnt end up where it should be. I am also wondering if am I overusing private ...
Ivica's user avatar
  • 75
6 votes
1 answer
261 views

Speeding up recursive iteration over array in Java

I have a function that needs to compute a system response y in response to an input time series defined by x. In practice, ...
Matt Summersgill's user avatar
4 votes
2 answers
231 views

Robust input for lottery tickets

I've made a method that provides a robust way for a user to fill out a lottery ticket. During this process I found out that Java also provides syntax for labels. That was very astounding for me. But I ...
Dexter Thorn's user avatar
  • 2,164
2 votes
2 answers
106 views

Get objects from list based on object's field

I have a method which takes List<Document> documents as parameters. I created unit test for it: ...
Michu93's user avatar
  • 145
3 votes
1 answer
146 views

A mutex that can detect certain types of programming error

This mutex prevents concurrent access to a target resource. One key requirement is the ability to be acquired in a (scheduler) thread and released in a different (worker) thread. Unfortunately this ...
Raffaele's user avatar
  • 131
2 votes
1 answer
94 views

Multidimensional array in Java

I have this multidimensional array that generalizes vectors and matrices: com.github.coderodde.util.MultidimensionalArray.java: ...
coderodde's user avatar
  • 27.6k
3 votes
2 answers
367 views

Implementation of a market that matches bids to offers

This is my task: Each line in the file can be one of the following: Updates to the limit order book in the following format: ...
Данил Денк's user avatar
1 vote
1 answer
1k views

How to transform the CompletableFuture response

Context: I have a client app which consumes an API. I want to call this API is async way (using java.net.http.HttpClient) and once I receive this data then I want ...
Learner's user avatar
  • 11
2 votes
3 answers
1k views

Multiplication table with plenty of comments

First time doing program documentation, how is it? Any thing that was done good or poorly? What can I work on to make it better if need be? ...
Hunter Treleaven's user avatar
1 vote
0 answers
127 views

Tic tac toe java swing

I am new to swing and GUIS in general. I am not sure how to structure projects with gui so help me fix mistakes I have done in this project Main: ...
Ivica's user avatar
  • 75
2 votes
1 answer
148 views

Rolling my own PRNG in Java

I have this pseudorandom number generator: ...
coderodde's user avatar
  • 27.6k
1 vote
1 answer
193 views

Simulating a toilet seat usage in Java - follow-up

(See the previous iteration.) This time, I removed the stuff I don't need in my demo runner. Also, I consolidated some code that seemed DRY to me. Simulation rules When a female arrives, she ensures ...
coderodde's user avatar
  • 27.6k
2 votes
2 answers
124 views

Simulating a toilet seat usage in Java

(See also the next iteration.) I have this small simulation program simulating a toilet seat. The toilet seat may be in two positions: up or down. If a male arrives to the toilet to urinate, and ...
coderodde's user avatar
  • 27.6k
2 votes
1 answer
85 views

Build a message string depending on the type of signature of an invoice

The following method was meant to build a message depending on the type of signature of an invoice. It contains some if-else statements and code duplication. The original method : ...
l0r3nz4cc10's user avatar
1 vote
1 answer
52 views

Comparing a weak fluent API with a strong fluent API in Java [closed]

I have this simple POJO: ...
coderodde's user avatar
  • 27.6k
0 votes
1 answer
55 views

When to use IllegalStateException [closed]

I am implementing an API that implements an interface, but I do not need to implement all methods. In that case, is it better to just return null or throw an IllegalStateException because it if not ...
Neslihan Bozer's user avatar
1 vote
0 answers
45 views

Attributing code licensed under Creative Commons from Stack Overflow in Javadoc

The title is pretty clear. I have a code snippet I took from Stack Overflow that's licensed under Creative Commons and I want to attribute it properly. My understanding is with Creative Commons you ...
Captain Man's user avatar
1 vote
3 answers
149 views

Caesar cipher - Encode text from external file using HashMap Java

This is one of my school assignments and I just wanted to ask if there are some obvious mistakes or things I could maybe improve in this code. Thank you for any suggestions. ...
Almezj's user avatar
  • 11
4 votes
2 answers
935 views

Traffic simulation GUI: an exercise in concurrent programming using threads

To avoid a code dump I have removed most of the code and left the first few lines of constructors and methods and anything relevant. Full code at the bottom. The purpose of this code is to use threads ...
Corey Hodges's user avatar
2 votes
2 answers
158 views

Duplicate code in spring controllers

...
user9132502's user avatar
2 votes
1 answer
238 views

Sorting visualizer using Java Swing

I programmed a little sorting visualizer a while back and I have been meaning to get some feedback on the overall implementation and on what I could do better to have cleaner code or a "best ...
morloq's user avatar
  • 119
0 votes
2 answers
95 views

Java spring controller method to trigger e-mail verification procedure [closed]

For readability sake, is it better to use optionals or write my code in an iterative manner? Here's a route I'm working on, does this look readable do you? ...
user9132502's user avatar
0 votes
0 answers
51 views

Copy AWS S3 objects into DB

I have written a code which fetched the S3 objects from AWS s3 using S3 sdk and stores the same in our DB, the only problem is the task is repeated for three different services, the only thing is ...
jack's user avatar
  • 11
2 votes
1 answer
172 views

An evolutionary algorithm written in Java to crack an XOR cipher

Alright. So TryHackme is a website that tries to teach hacking with hands on labs. They have a room called JVM Reverse Engineering where the user gets to reverse engineer Java apps, and in particular ...
Aleksey's user avatar
  • 173
2 votes
2 answers
539 views

Parse a text file, and map to an out-of-scope POJO

I need to parse a file, with a standard formatting: ...
Maxime's user avatar
  • 123
1 vote
1 answer
95 views

Selection algorithms (order statistic) in Java: linear time vs. sorting selector vs. Quickselect

This post is about computing order statistics: given an array \$A\$ (not necessarily sorted), find the \$k\$th smallest array component. The entire repository is here. ...
coderodde's user avatar
  • 27.6k
2 votes
0 answers
130 views

Followup: Use backtracking to put as many ships on a battleship-board as possible

I created a simple battleship game and wanted to be able to place as many ships on my board as possible. The logic to place the ships uses some kind of backtracking to find a correct placement. ...
apocs's user avatar
  • 127
3 votes
3 answers
538 views

Longest substring without repeating characters

I have the following O(N) code submitted: ...
Tan Yu Hau Sean's user avatar
4 votes
3 answers
622 views

Immutable matrix class with mathematical methods

This was a homework assignment for a data structures course. The goal was to implement a given interface and the assignment was auto-graded by a system that ran some validation tests. Sadly I did not ...
Nifim's user avatar
  • 197
2 votes
3 answers
126 views

Standard fizz (3) buzz (5)

Is there a possibility to refactor this method and make it clean and respect solid principles. ...
Reda Taha's user avatar
4 votes
0 answers
3k views

Reactive JWT authentication using Spring webflux

Greeting to all senior devs here. I'm trying to create a project for my small business. There are not many tutorial on how to create Reactive JWT authentication with Spring webflux. So I'm a bit ...
Patrick's user avatar
  • 331
1 vote
1 answer
107 views

Class that wraps a collection and tracks if its elements were visited

The VisitedCollection is a collection wrapper for setting and tracking if elements were visited (removed in terms of the wrapper) I have concerns regarding: should ...
triclosan's user avatar
  • 254
0 votes
1 answer
443 views

Compute the goals scored by football teams in their matches in a season, from json data

Please look at the Java Stream methods in the for each loop. This method totals the score for when the your desired team is playing during the football season - input param teamKey - it is either ...
user2102346's user avatar
2 votes
1 answer
418 views

Simple Java Solitaire / Patience card game

I made a simple Patience/Solitaire card game. The cards don't use images but JLabels and JPanels. The game is finished when all cards are on their suit piles. Card movement: mousePressed : card -> ...
Si Vafo's user avatar
  • 53

1
3 4
5
6 7
218