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
1 answer
40 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
0 votes
0 answers
37 views

dataset anonymizing algorithm implementation with Spark

I am trying to implement the following algorithm in Spark / Java: https://en.wikipedia.org/wiki/K-anonymity. My code class is the following: ...
user avatar
2 votes
0 answers
24 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
51 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
37 views

An Asynchronously Populated List

I have to implement an interface which returns a List: List<Foo> getAllTheFoos() The ...
user avatar
  • 149
-1 votes
0 answers
56 views

Calculate board positions after each move in tic tac toe

In a game of tic tac toe I am trying to calculate all board positions after every move. We make the following assumptions. X always goes first and is designated with a 1. O goes second and is ...
user avatar
  • 253
0 votes
3 answers
103 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
52 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
47 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
112 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
94 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
73 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
127 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
90 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
134 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
76 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
267 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
177 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
116 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
25 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
422 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
63 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
41 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
125 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
29 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
82 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
2 votes
1 answer
103 views

Basic Ticket booking code with Unit tests

I am going to run a session for a few other developers who are new to Junit, mocking, etc. I have designed a very simple application with classes and tests to demonstrate how to do unit testing. ...
user avatar
3 votes
1 answer
72 views

Quiz to help practice mental arithmetic

I made a tool that would help in practicing and increasing the speed of Mental Arithmetic, below is the code that I wrote in java. Please suggest if there are any improvements that I can make or any ...
user avatar
  • 31
2 votes
2 answers
78 views

A Union Data Type

Introduction I'm trying to get familiar with functional programming by implementing some functional concepts. One of these concepts that I've attempted to implement below is a ...
user avatar
  • 1,825
2 votes
3 answers
87 views

Find prime numbers

I wanted to create a program that lists all prime numbers to a given upper bound and that will also provide the amount of primes in the set. After many hours of trial and error I was able to solve it. ...
user avatar
  • 21
-3 votes
1 answer
273 views

Choose a word randomly from input, without storage [closed]

It is a practice assignment (optional). The question is asking to "Write a program RandomWord.java that reads a sequence of words from standard input and prints one of those words uniformly at ...
user avatar
  • 95
3 votes
2 answers
154 views

Blackjack implementation - Java

I have inspired from the recent blackjack question here and decide to code for simple blackjack console application Please review and let me know What can improve on the code? Rules for the ...
user avatar
0 votes
1 answer
46 views

custom button class for android game engine

I'm a self-taught programmer and I haven't really followed industry-standard coding classes. I'm currently coding my own game engine for android, though and I was wondering if my coding style could ...
user avatar
  • 3
0 votes
1 answer
51 views

Given a matrix return true if it contains the Identity matrix (by recursion)

I need to write recursive static method with given 3 parameters the method will return true if the sub matrix with the size of (int size) which the left corner is mat[x][x] is the identity matrix ...
user avatar
3 votes
1 answer
74 views

Highly divisible triangular number

Highly divisible triangular number, my solution My solution of challenge from Project Euler takes too much time to execute. Although on lower numbers it works fine. Anyone could look up to my code and ...
user avatar
  • 31
1 vote
1 answer
96 views

Collect and combine results of async calls returning completable futures in Java in a cleaner way?

I need an abstract way to implement this below functionality because in my code I have to use it in multiple places with different REST endpoints. If I ignore it will cause code duplication. Please ...
user avatar

1
2 3 4 5
217