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
4 answers
1k views

Quick Sort Done Lucidly

I've been away from Programming and the Tech Industry for sometime. I thought I'd look at and try some of the older basic stuff. I bushed up to QuickSort and found most existing implementations of it, ...
Amal Krishnan's user avatar
2 votes
1 answer
104 views

Interest/Discount rate and loan calculator java

I'm currently learning Java at home with YouTube tutorials. I took a short break from the course to make a small project for calculating costs of loan. It's not economically accurate - I followed ...
Koros's user avatar
  • 23
3 votes
1 answer
67 views

Optimize Island Counter program

I am doing some assignments on my own and one of them is about a Island Counting program, I have come up with a working program but the problem is its very slow. When running test on for example maps ...
phuck's user avatar
  • 33
1 vote
1 answer
135 views

A vanilla Hibernate app (no Spring)

I finished my web project a while ago and decided to revisit one my first Java projects – the first project that had anything to do with databases. It looked pretty messy to my more experienced eye. ...
Sergey's user avatar
  • 481
1 vote
1 answer
175 views

Creates all possible permutations of a string and its substrings

I want to improve this code to efficiently create all possible permutations/combinations of a string. For example, if I have the string "abc", the result would be the list [ab, ac, ba, bc, ...
themightye's user avatar
2 votes
1 answer
51 views

Parsing one UserData type to a preview

I am currently developing a web app and am using Spring as a Backend. I have some user data that is provided by one of our services and I need to display it in my frontend. The subject of the code ...
monamona's user avatar
  • 425
2 votes
0 answers
151 views

Java Project Reactor/WebFlux token service

I'm trying to achieve a thread-safe reactive token service. The point is that all subscribers must wait until the token is received or updated (when expired). It works, but I want a second opinion ...
John Goode's user avatar
0 votes
1 answer
83 views

Retrieve data from an XML file in Java

few months back I did a code test for a company and I quickly managed to solve it within 5-10 minutes. But, I got rejected because it wasnt "good enough". What is good enough? they said its ...
Con101's user avatar
  • 3
-3 votes
1 answer
165 views

How do I ensure my Java method never returns null? [closed]

I've been reading Uncle Bob's Clean Code and have read many articles on the use of Optionals whenever you are faced with returning a null in a Java method. I'm currently refactoring my code and I ...
Mark's user avatar
  • 105
0 votes
1 answer
119 views

Code that checks whether there is a holiday by calling another microservice

I call another microservice to check whether there is any holiday on any particular day. This will then add a comment in the db if the rest call doesn't fetch an empty list(a list of size 1). Here is ...
diaop's user avatar
  • 9
3 votes
0 answers
114 views

MVVM signing in using firebase

I'm new to MVVM architecture. I want to have authentication with email + password, google and Facebook. I'm not sure if there should be separate view models for each authentication way: ...
Edziu Kowalski's user avatar
2 votes
0 answers
48 views

Print columns of text without hard coding the width (attempt 6 - pivot edition)

If you'd like to pivot this: ...
candied_orange's user avatar
6 votes
1 answer
430 views

Crossword puzzle app

I was hoping someone could give me any tips or advice on this program I wrote for my high school class. The point of the program is to create a workable crossword puzzle in the console. If it works ...
Sean Riley's user avatar
2 votes
1 answer
562 views

The right way to implement multiple commands in a Telegram bot

I started coding two months ago and as my first project I wrote a Telegram bot in Java. The purpose of the bot is to perform various tasks related to the Yugioh TCG (such as searching for cards in a ...
smnprn's user avatar
  • 21
4 votes
0 answers
78 views

Print columns of text without hard coding the width (attempt 5)

If you'd like to print this: ...
candied_orange's user avatar
1 vote
1 answer
112 views

Queue-mergesort: a mergesort that does optimal number of comparisons in the worst case in Java

Here is the code for queue-mergesort by Mordecai J. Golin and Robert Sedgewick: com.github.coderodde.util.QueueMergesort.java: ...
coderodde's user avatar
  • 27.6k
4 votes
2 answers
257 views

Multithreaded Conway's Game of Life implementation written in C and Java using JNI

I had some multithreading C programming experience from school last year but I wanted a bit more so I tried to program a Conway's Game of Life implementation from scratch. Code is mainly written in C ...
Shmuel Newmark's user avatar
5 votes
1 answer
188 views

A simple probabilistic AI for generating random sentences in Java

Motivation I have this repository. It contains a program that analyzes an input text file and builds a word graph: in the graph, each node represents a word in the analyzed text. Now, if there are two ...
coderodde's user avatar
  • 27.6k
3 votes
3 answers
140 views

IPv4 filter in Java

I have a simple class for representing IPv4-addresses via int values, and a simple IP-address filter that works like a set of IPv4-addresses. ...
coderodde's user avatar
  • 27.6k
3 votes
1 answer
436 views

Calculator (Java/Beginner)

I finished my first calculator using Java! I try to apply Object-Oriented Programming! I'll add my gitHub link if you're suited to viewing code on gitHub. Here is a link to my GitHub Calculator ...
dddleo's user avatar
  • 33
2 votes
3 answers
502 views

Recursive palindrome check

I'm trying to solve this which basically calls for a recursive palindrome check with some minor extra steps (Special characters and whitespace can be ignored). The test inputs' length can be 100000 ...
Yamin's user avatar
  • 125
0 votes
3 answers
225 views

Print columns of text without hard coding the width (attempt 4)

If you'd like to print this: One Two Three Four 1 2 3 4 using this: ...
candied_orange's user avatar
0 votes
0 answers
71 views

Print columns of text without hard coding the width (attempt 3)

If you'd like to print this: One Two Three Four 1 2 3 4 using this: ...
candied_orange's user avatar
4 votes
1 answer
261 views

Print columns of text without hard coding the width (attempt 2)

If you'd like to print this: One Two Three Four 1 2 3 4 using this: ...
candied_orange's user avatar
5 votes
2 answers
609 views

Recipe search exercise

I'm currently following Java moocfi Helsinki course. This is my current assignment : In this exercise we are going to create a program that allows for searching for recipes based on their name, ...
FakiB's user avatar
  • 51
3 votes
1 answer
113 views

Print columns of text without hard coding the width

If you'd like to print this: One Two Three Four 1 2 3 4 using this: ...
candied_orange's user avatar
3 votes
1 answer
227 views

My First Java Battleship Simulator (single array, single ship)

I'm new to this community and also to Java programming! I recently picked up "Head First Java" and I did my Battleship project. If you could kindly, give me feedback on the code? ...
java_grindr's user avatar
5 votes
2 answers
276 views

Select the type of triangle based on the input

I am trying to see if there is a way to improve my code this program ask for 3 number and calculate the what type of triangle it is ...
L1avZh's user avatar
  • 53
2 votes
0 answers
117 views

Testing CRUD ops with some special cases using Cucumber

Question Using Cucumber and Java17, I refactored functional tests for a basic CRUD app as I found the previous tests using special variables for different test scenarios and I felt they were brittle ...
Ahmed Tawfik's user avatar
1 vote
1 answer
99 views

Greedy approximate algorithm for metric TSP in Java

I have a repository that provides three metric TSP solvers: Brute-force solver, Genetic solver, Greedy approximate solver; solver 3 is the subject matter of this post. The typical output is: ...
coderodde's user avatar
  • 27.6k
2 votes
1 answer
144 views

Java program for complex math utilities

I've got 2 Java programs, with the aim of solving some matrix math that involves complex numbers (an EE problem). Both programs have main functions, the one with all the complex math operations has a ...
Aloy's user avatar
  • 21
1 vote
3 answers
90 views

Extensible error code infrastructure

I was answering a question, Java Exception Error Enumerations Anti-pattern, on Software Engineering Stack Exchange and found myself writing up a fair bit of code. It could use a code review so I'm ...
candied_orange's user avatar
0 votes
0 answers
41 views

Fee Challan as a practice in Java Swing,

I have made three classes and I have put all the UI code in a different class and used method for labels, text fields etc so it does not mix up. Please look into this code and tell me is it good ...
touqeer's user avatar
  • 101
8 votes
1 answer
156 views

Java code for generating 16bit DMX values using sine and cosine

This is my try, based on good inputs from different places. I ended up saving the DMX-values in two arrays (one for sine and one for cosine) as I guess that will make stuff easier later on when I want ...
droid's user avatar
  • 183
2 votes
2 answers
158 views

Reversing in between a linked list

I have written code for this leetcode problem :- Given the head of a singly linked list and two integers left and right where left <= right, reverse the nodes of the list from position left to ...
Strange Alchemist's user avatar
7 votes
2 answers
2k views

Shell script to compile Java

...
user16217248's user avatar
1 vote
0 answers
118 views

Making Robert Tarjan's offline LCA algorithm run (much) faster (Java)

I have produced this GitHub repository that compares the performance of: Robert Tarjan's off-line lowest common ancestors algorithm, An improvement of the above algorithm. Typical demo program ...
coderodde's user avatar
  • 27.6k
5 votes
1 answer
729 views

Merge multiple map with java stream api

I am trying to merge multiple map with Java stream API. The reqiurements like ... this method can receive multiple map, does not care hot many of it support 2 merge method: intersection, union if key ...
Juneyoung Oh's user avatar
0 votes
0 answers
106 views

An extended simple, funny, easy linked stack of lists in Java

This post is the continuation of A simple, funny, easy linked stack of lists in Java. What's new: Now I have varargs for pushing/linking multiple values per call. Provided the unit tests. ...
coderodde's user avatar
  • 27.6k
4 votes
1 answer
290 views

Hangman game, with secret word provided by user

I recently started learning programming and in particular Java. I wrote this small hangman game which takes the input for the secret word from the user. It all works as intended; I would like to know ...
ANTONIO ALTAVILLA's user avatar
2 votes
2 answers
180 views

Quick Sort Program

Quick sort is a sorting algorithm in which we select any random element as pivot from the array and we do the partition of the array around that pivot. Basically we place all the elements smaller than ...
Strange Alchemist's user avatar
3 votes
0 answers
247 views

JavaFX dialog for numeric typed data input

I have this small subclass of JavaFX's javafx.scene.control.Dialog that requires the enum specifying the data type of the input data: ...
coderodde's user avatar
  • 27.6k
-2 votes
1 answer
105 views

Default food property wording when translation not available

I have food table having number of foods, each food can have specific properties in multiple languages (en, es) like name, description etc. But it is not sure if all of the properties are always ...
Ketan Upase's user avatar
2 votes
1 answer
58 views

Merge Sort with Minimum Sufficient Variables, Verbosity and better Space Complexity

The majority of merge sort implementations searched online are provided with unnecessary variables and code lines. Here is an attempt to reduce that. However, does passing back the subArray as return ...
Thomas Mathew's user avatar
1 vote
1 answer
145 views

Interconnect Recipe and Notes

I'm currently working through a tutorial. The project is a recipe website. One of the lessons to "save some lines of code" and use bidirectional setters for bidirectional relations of ...
Benjamin Basmaci's user avatar
0 votes
1 answer
71 views

Implement code to monitor file delete action

I have this Java code which I want to use to monitor file changes into directory: ...
Peter Penzov's user avatar
3 votes
2 answers
105 views

Spring boot shop application with error handling

I'm writing a simple online shop using spring boot, for learning purposes. Right now I have purchasing-service and a product-service. The purchasing-service makes requests to the product-service via ...
Eoin's user avatar
  • 263
0 votes
1 answer
100 views

Printing Permutations

Following is a leetcode problem: Given an array nums of distinct integers, return all the possible permutations. You can return all the possible permutations. You can return the answer in any order. ...
Strange Alchemist's user avatar
0 votes
1 answer
63 views

Delayed, concurrent event stack in Java - follow-up

I have slightly refactored the Delayed, concurrent event stack in Java. Now it looks like this: DelayedEventStack.java ...
coderodde's user avatar
  • 27.6k
0 votes
3 answers
195 views

Delayed, concurrent event stack in Java

(See the next iteration: Delayed, concurrent event stack in Java - follow-up ) Motivation I was confronted with a task of having "message events" for a GUI program. The use case is as ...
coderodde's user avatar
  • 27.6k