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

IndexedLinkedList.java - Part 4/4: Other inner classes

I have this indexed, heuristic, succint list data structure that runs all single-element operations in worst-case \$\mathcal{O}(\sqrt{n})\$ time. You can read about it here. Table of Contents: Part 1/...
user avatar
  • 25.3k
0 votes
0 answers
14 views

IndexedLinkedList.java - Part 3/4: Private methods

I have this indexed, heuristic, succint list data structure that runs all single-element operations in worst-case \$\mathcal{O}(\sqrt{n})\$ time. You can read about it here. Table of Contents: Part 1/...
user avatar
  • 25.3k
0 votes
0 answers
16 views

IndexedLinkedList.java - Part 2/4: Public methods

I have this indexed, heuristic, succint list data structure that runs all single-element operations in worst-case \$\mathcal{O}(\sqrt{n})\$ time. You can read about it here. Table of Contents: Part 1/...
user avatar
  • 25.3k
0 votes
0 answers
52 views

IndexedLinkedList.java - Part 1/4: Finger management class

I have this indexed, heuristic, succint list data structure that runs all single-element operations in worst-case \$\mathcal{O}(\sqrt{n})\$ time. You can read about it here. ToC: Part 1/4: this post. ...
user avatar
  • 25.3k
2 votes
1 answer
37 views

Java class to run CompletableFuture<T> instances in batches

This is a utility class for running CompletableFuture<T>s in batches (e.g. to avoid using too much bandwidth making HTTP requests). It seems to work, but I'm ...
user avatar
4 votes
1 answer
384 views

Writing a Java program that outputs a calorie/macronutrient plan for getting in shape over a certain amount of weeks

I am new to programming and was working on a project that calculates an entire "diet plan" as well as a projected weight goal for each week. There are three objects that all have methods ...
user avatar
1 vote
0 answers
35 views

Redis backed cron style scheduler for reliability in clustered environments

I came up empty handed in search of an alternative to Quartz for scheduling Crons in a clustered/distributed environment. Redisson has a scheduler, but it came with its own issues: https://github.com/...
user avatar
  • 11
-2 votes
0 answers
23 views

printing calendar in java using Intellij compiler [closed]

i tried to print a calendar but i dont know how to put the weekdays above the numbers properly code: ...
user avatar
3 votes
1 answer
52 views

Langton's Ant cellular automaton in Java

I made a couple of little games and cellular automata in Java. For every new 'game', I used the same code as a base, except for the game logic of course. With every iteration of me customizing my ...
user avatar
1 vote
0 answers
52 views

JavaFX Spell Checker

I have a functional spell checker here. I'd like another set of eyes on this. Is there any way to reduce the memory footprint of this or improve the performance without sacrificing readability and ...
user avatar
  • 119
0 votes
1 answer
51 views

Correct usage of Java Generics for a simple cache holding objects of any particular type that contain an identifier of any particular type

The Stack Overflow question, I'm trying to create an inMemory database using Collections and generics, presents some code that attempts to use Java Generics for an in-memory cache of objects of any ...
user avatar
0 votes
2 answers
51 views

Function that calculates the least amount of notes a ATM will dispense for a given amount

This is the code currently and it works. Currently have a DB with the type of note and the amount of that note available. This will, later on, remove the amounts of notes from the DB. I am happy with ...
user avatar
1 vote
2 answers
58 views

Parse string using character value for Unicode characters

I added the getCValue method to reduce the cyclomatic complexity, but the cyclomatic complexity still persists. How can I reduce it? Can I change this code using ...
user avatar
2 votes
0 answers
28 views

JavaScript Linter in Java

I wrote a simple Linter that checks for matching opening and closing braces for one line of JavaScript. It utilizes a stack to store opening braces found in the line, then compares the first closing ...
user avatar
1 vote
1 answer
54 views

Do I really need to re-interrupt a thread doing end-of-life tasks on interruption?

Before showing-off the code, here is a bit of an explanation. I have a Spring component that spawns a thread for watching a directory for new files. In this context, I have a method that runs in a ...
user avatar
2 votes
1 answer
41 views

An Asynchronously Populated List

I have to implement an interface which returns a List: List<Foo> getAllTheFoos() The ...
user avatar
  • 159
0 votes
4 answers
119 views

Counting initial bits of 0 in Java

I want to count the number of bits set to 0 at the beginning of a byte array. So far the code I have is this: ...
user avatar
  • 9
0 votes
0 answers
30 views

Context and Clean Architecture android

I want to extract this class into a util class or sharedViewModel since it's being used among two or more activities. But also reading about clean architecture I ...
user avatar
1 vote
1 answer
55 views

Implemented Sorting of Map by Value and then by Key in java

So I had this requirement to get the frequency of names appearing in a list and then print the one appearing the most number of times. If there is a clash, print the one which comes first in the ...
user avatar
-1 votes
1 answer
51 views

Nested pojo java class - What could I make better

I need code review. I've used Lombok and jackson. Static statemts look very "ugly" in Root class. I don't know what I should make with that. Is There another way to create nested classes? ...
user avatar
1 vote
2 answers
122 views

TicketManager class in Java

I'm reading the famous Clean Code book of Robert C. Martin so I'm trying to refactor some of my latest code as exercise. I feel like the method getTicket breaks the ...
user avatar
  • 13
-2 votes
1 answer
82 views

A Rough(bad) Example of a Recursive Descent Parser in Java [closed]

I have written a program that parses this code but it doesn't use recursive descent. So I am starting over and need help. Just so everyone is on the same page: Using recursive descent it needs to ...
user avatar
4 votes
3 answers
97 views

Analyzing baby name data in CSV files

First time using code review. I am still a student so there will be a lot to be desired. Basically as part of the homework we are told what methods to create (Method names are given with their ...
user avatar
1 vote
1 answer
47 views

Counting the array spots visited by binary searches (Java)

So the idea was to find out how many times each array component is considered by binary search when we search all possible needles for the haystack: ...
user avatar
  • 25.3k
3 votes
1 answer
75 views

Practicing with array

The class "post" only has simple methods like getters for the ID(long) and number of likes(long). Is how I wrote my method below accomplishing anything? Is it doing what I want it to do? I ...
user avatar
  • 33
3 votes
1 answer
147 views

Codewars - How many pages in a book?

Problem Statement Every book has n pages with 1 to n pages. The summary is made by adding ...
user avatar
2 votes
2 answers
94 views

Input validation that verifies a boolean assignment using a Boolean object

Taking online college course and I'm new to Java. We just learned about input validation. I've used input validation pretty comfortably for strings, ints, and whatnot. But I had to validate a boolean ...
user avatar
2 votes
1 answer
69 views

Java - Breaking a large 1-D array into a 2-D array

Java's largest array length is 2^31 – 8 = 2,147,483,639, which is an int consisting of 32-bits. In the case where we want to store more elements, we are better off ...
user avatar
2 votes
2 answers
136 views

Much more efficient trisexual genetic algorithm for TSP in Java

(The entire project lives there.) This time, I have made the previous version of the GA for TSP run faster by around the factor of 6+. The idea is to cache the tour costs with the actual tour objects ...
user avatar
  • 25.3k
2 votes
0 answers
64 views

Genetic trisexual algorithm for TSP in Java [duplicate]

(A more efficient version of the GA.) This is my the very first take ever on GA: GeneticTSPSolverV1.java: ...
user avatar
  • 25.3k
3 votes
1 answer
96 views

Processing a binary file with buffer length tags

I am trying to process a very large binary file using MappedByteBuffer from java.nio package. This is how the data looks like in the file: ...
user avatar
  • 33
0 votes
1 answer
108 views

Code cleanup for a Java project that creates a database containing members of a club

This question is related to my first post on this forum. Since the rules are not to make the questions too broad, I thought I'd create a new question. I'm not experiencing any issues with this piece ...
user avatar
  • 1
9 votes
6 answers
3k views

Conway's Game of Life Object oriented implementation in Java

I have designed Conway's Game of Life in Java, the solution follows Object Oriented design and paradigm, please review and let me know the feedback Class Cell Cell ...
user avatar
3 votes
1 answer
79 views

ATM Console Program with Java

I am a freshman Computer Engineering student. Variable names are pretty straightforward; I believe it would be easy to understand. Program explanation: First you have to create an account and deposit ...
user avatar
3 votes
3 answers
268 views

Bi directional full relation between classes + small working tasks

I did this the way I could (I mean this way I find it okay for my knowledge and of course the most important output is the correct one , but as I know it is also important that the code looks clean ...
user avatar
5 votes
2 answers
210 views

Truth or dare program in java

I wrote this code in Java as a "Truth or Dare" game where if you type "truth" or "dare", it will pick a random number from the switch and then output the truth question ...
user avatar
0 votes
2 answers
117 views

Searchable database with Java and SQL

What does the code do? Albeit unfinished (it does work, it's just not complete yet), the code creates a database (members.db) where telephone numbers, IDs, and ...
user avatar
  • 119
2 votes
1 answer
79 views

Stream Partitioner

Discussion I've been trying to increase my knowledge of Java Streams and for practice, I devised up the requirement of partitioning a Stream of values into a ...
user avatar
  • 1,825
2 votes
0 answers
48 views

Simple Merkle Tree

Discussion I just started learning about Merkle Trees and wanted to get some practice by attempting to implement a very simple Merkle Tree. The constructor for the tree takes some type of hash ...
user avatar
  • 1,825
1 vote
1 answer
45 views

Genetic TSP in Java with graph expansion

This post presents my take on TSP (travelling salesman problem). The idea is to: Take an input node i, Compute the entire graph ...
user avatar
  • 25.3k
1 vote
2 answers
60 views

Function to read a file until next token

I've got this function which reads an entry until the next starting Token determined through a function, as the nature of the token is flexible. Usage: ...
user avatar
  • 449
0 votes
0 answers
29 views

Simple project of Spring-RestController

I'm learning how to build a project from a scratch by using Spring Rest Controller but I need to get a feedback to learn from my mistakes or overengineering parts. This is my controller; ...
user avatar
3 votes
5 answers
423 views

Frame Strings that contain newlines

I have an application where I need to highlight some information that is printed to the console, so I wrote some static library methods which do that. I tested for bugs. Is my code clean and ...
user avatar
  • 2,006
1 vote
1 answer
66 views

Simple Hash Ring Implementation

Introduction I have been reading about Consistent Hashing and in an attempt to better understand the concept, I wanted to implement a simple hash ring. I did not implement the concept of virtual nodes ...
user avatar
  • 1,825
1 vote
1 answer
62 views

Console-based number guessing game

I received feedback that my code was convoluted and written with very bad practices. Our tutor said explicitly that I should never write the code like that. I'm just trying to wrap my head around the ...
user avatar
  • 11
1 vote
1 answer
44 views

Group a list of objects by property and remove the first value from each group

I have a list of Students and I want group this list by the property NAME, to sort each group ASC by the property ...
user avatar
  • 153
1 vote
1 answer
43 views

Comparing two general LCA algorithms in Java

Now I have two algorithms solving a problem: given a general (multi-way) tree, and any array of node names, find the the node that is the deepest common ancestor. ...
user avatar
  • 25.3k
2 votes
1 answer
134 views

Java implementation of Employee class hierarchy

We were tasked to do this assignment where there is the base class employee and two derived class part-time and full-time employees. Here is what I came up with: ...
user avatar
0 votes
0 answers
31 views

General (multiple nodes) LCA queries in Java

I have an algorithm for computing multiple node LCAs (lowest common ancestor): TreeNode.java: ...
user avatar
  • 25.3k
1 vote
1 answer
84 views

Java implementation of Yahtzee

I'm trying to implement the game of Yahtzee in java. This is for a project at my university so I tried to be as clean and to use the best code practices as possible. The part in particular that I ...
user avatar

1
2 3 4 5
217