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
2
votes
1answer
63 views

Block Bootstrap Estimation in Java - Part 2

The following is my attempt at parallelizing (I learned about parallel computing over the last weekend, so I'm very new to it) and making more efficient the code in my previous question Block ...
3
votes
1answer
75 views

System generated Social Network

In a particular social network friends are automatically allocated to users by the system and users cannot add friends of their choice on their own. There are currently N users on the social network, ...
3
votes
1answer
6k views

Bucket sort implementation

I want to optimize my code for performance and fine-tuned logic. ...
5
votes
1answer
262 views

Getting key-values for set of date ranges by calling different lib methods and using results to create DTOs

I have three methods that I need to call multiple times only varying the date parameter of each. The natural solution to avoid code duplication is to put the three methods in a loop and iterate over ...
0
votes
2answers
112 views

ProjectEuler.net problem #50, Consecutive Prime Sum

I am trying to solve ProjectEuler.net problem #50, Consecutive Prime Sum. Here is the problem: The prime 41, can be written as the sum of six consecutive primes: ...
6
votes
2answers
331 views

Creating and listing a song collection

Songs Class: ...
8
votes
3answers
604 views

log_e approximation

The natural logarithm can be approximated by the following formula: $$ln(x) = 2\sum_{k = 0}^{\infty}\frac{(x-1)^{2k+1}}{(2k+1)(x+1)^{2k+1}}$$ I've implemented this formula using Java. Parameter <...
2
votes
1answer
72 views

LRU Cache Example

Please check the following the LRU cache implementation. Thanks for the valuable comments ...
4
votes
2answers
112 views

Block Bootstrap Estimation using Java

The data are in a file called test.txt, which is available at https://drive.google.com/file/d/1g0ffvH5oP5C4Cp6ciEp_L1Rst6WeTuYG/view?usp=sharing. There are some odd ...
3
votes
2answers
105 views

Code for saving / loading a class object

As I was advised, I broke my code into 2 classes. Could you take a look at the repository class and report what problems this code has ...
3
votes
1answer
58 views

Finding out the indices of common elements in two array lists having duplicate elements

I have two lists which are also having some duplicate elements , i am converting this list to map as key value pair with element index as the value for the key - element List 1 : [1, 2, 3, 4, 5, 6, ...
5
votes
2answers
5k views

Text-Based RPG Dungeon Game in Java

I'm trying to follow as many OO concepts as possible. This project is for my github, as a means to enhance my portfolio for possible internships in the future. Question 1: Is there anything that's ...
9
votes
5answers
10k views

Appending a trailing slash if needed

I like to overcomplicate things, this is fairly simple though but I would like to keep it simpler without lowering readability. Not just to improve my code but also my self. ...
5
votes
3answers
545 views

Using static final Strings for SQL Query in Spring Boot

This is regarding code quality and coding standards with respect to Spring Ecosystem. Here there are two methods: isRecordExists is using a class level static ...
9
votes
3answers
857 views

Refactoring multiple boolean conditions?

I have a Predicate which takes employee object. Predicate<Employee> getPredicate() { return emp -> filter(emp); } Now the filter method is very ...
1
vote
0answers
44 views

Map of objects sharing characteristics [closed]

What I'm trying to achieve From a list of lists of elements (one element can be in multiple lists, but only once in each list), I want to generate a map whose keys are each elements and the values ...
2
votes
1answer
52 views

Parallel SQL queries using completable future

My problem is I'm having a table and 7 child table. I'm fetching details using querying the main table first then querying the child tables one by one sequentially. To improve performance I decided to ...
5
votes
4answers
4k views

Cards shuffling and dealing program

The program interacts between cards and four players among whom cards are to be distributed. The Program do the following function Creates a deck of cards. Shuffle the deck. Shows the deck. Deal ...
3
votes
1answer
131 views

Find shortest path in the matrix for multiple objects

I have the implementation of A* search algorithm that allows to find the shortest path from start to goal. The implementation looks like this ...
2
votes
1answer
71 views

Spring boot loadbyusername

I have the following classes. I wonder if this structure makes sense in any terms especially the usage of the UserDetails class from Spring. Should I use ...
1
vote
0answers
53 views

Defensive Fluent Interface Implementation [closed]

Introduction At this moment in time, I'm in the process of creating some fluent interface, as a result, I've created a DSL style solution for authentication & authorisation. As a result, the ...
0
votes
1answer
44 views

Possible Test Cases in Tester [closed]

I am trying to write a human-readable tester for a functioning program. There are four methods in the class Polynomial: ...
2
votes
1answer
38 views

Reading bytes between two quotes from a stream and decoding it to its appropriate character set [closed]

This is a component for a lexer which operates on a byte input stream that handles reading and decoding the contents of a string contained within double-quotes. The validity of the encoding is handled ...
5
votes
0answers
52 views

Implementation of Gitlab CI + Docker + Spring Boot

i would really appreciate if anyone could invest a bit of time to review what i did. Basically this is first time i do this, and that is reason why i need another set of eyes. I have Spring Boot ...
13
votes
4answers
3k views

Unit testing Video Service class

I wrote my first unit testing code on a service class using Mockito. The code looks like this: ...
4
votes
3answers
192 views

Dijkstra's Algorithm implementation in Java

I am learning graph theory in CS and for practice, I have implemented Djikstra's algorithm in Java. I have created a GraphVertex class that contains information ...
1
vote
2answers
92 views

Adding up dice rolls with constraints

I have written the below code which generates 4 random, whole integer values between 1 and 6 and then saves the sum of the 3 largest values. It generates a total of 6 values this way, displays the ...
2
votes
1answer
48 views

RemoteFile in Java - follow-up

(See the first and initial iteration at RemoteFile in Java.) I have added some new facilities for convenience. Now I have this in mind: com.github.coderodde.utils.io.RemoteFileDownloadListener.java: ...
2
votes
0answers
53 views

RemoteFile in Java

(Also, see the next iteration.) I have this tiny class for downloading files from internet: ...
2
votes
1answer
901 views

My own Queue Implementation in Java

Please review my Queue implementation and let me know if you have any suggestions. I am not returning an exception for any of the methods defined here. As we know ...
0
votes
0answers
52 views

Code for creating a dialog for choosing a date

I have code that creates an AlertDialog to select a date by a user. I ran into a problem that this code began to take up a lot of space. Could you offer ideas on how to shorten this code / put it into ...
5
votes
3answers
1k views

Dollar value of coins and calculating interest compounded annually

I've made this program to do a few integer calculations. Do the methods for converting the numbers look good? Do you have any other basic tips? ...
1
vote
1answer
47 views

Trying to write an equals method for a class containing array of objects [closed]

Im trying to write a College class equals method that compare the content of the arrays of the two objects of college class. So The method will compare the Student[] array in college object to other ...
15
votes
4answers
690 views

Determining if all values in a 2d array conform to specific criteria

I'm writing the following program for a school assignment. The prompt is as follows: A magic square is square grid filled with distinct positive integers such that each cell contains a different ...
11
votes
5answers
3k views

Project Euler #3 in Java

Project Euler #3: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? Here is my solution: ...
5
votes
1answer
107 views

Multithreaded Message Game

Use cases Messaging app between two users. GameMain is for multithreading application refers to SendMessageWrokers.java Only 2 user need to be defined and message app needs to finalize after a ...
1
vote
1answer
68 views

Timer in Java with GUI

I have created a timer with GUI in Java. Here's the code: ...
1
vote
1answer
66 views

Banking application - Optimizing java multi-threading code

I created a simple Bank application to make multiple transactions between multiple accounts. It is working as expected. But I want to know can I make the code more optimized. ...
5
votes
2answers
189 views

Java Kata - String Calculator

I started learning Java recently. Currently I'm trying to improve my spaghetti code by solving different programming puzzles. It would be amazing if someone could give me feedback on the String ...
-2
votes
1answer
46 views

Set backgroud color based around database call [closed]

I have the following method that only checks if a Sqlite database has data, but I don't like how the code looks ...
9
votes
3answers
856 views

Master Mind implementation

I have created a Master Mind BoardSolver. To apply the BoardSolver I have created an app (...
3
votes
1answer
120 views

Knuth-Morris-Pratt algorithm in Java Finding substrings in a matrix

Problem Given two matrices: a pattern p and a text t. Write a program that counts the number of occurrences of ...
9
votes
3answers
772 views

Subclass instance recorder in Java

I've written a relatively small abstract class in Java which keeps track of all instances of it's sublasses. Any class which extends this abstract class will automatically have all its instances ...
5
votes
1answer
796 views

Mirror a stack of Integers

Write a method mirror that accepts a stack of integers as a parameter and replaces the stack contents with itself plus a mirrored version of itself (the same ...
1
vote
1answer
81 views

Best practice to initialize instance variables for a POJO when values are null

I am using Java 8. I haven't found another question that fits mine exactly, and I've come across some conflicting information on best practices with what I'm trying to do. I'm creating a POJO which ...
2
votes
1answer
301 views

First missing positive integer in linear time and constant space

This problem was asked by Stripe. Given an array of integers, find the first missing positive integer in linear time and constant space. In other words, find the lowest positive integer that ...
3
votes
2answers
658 views

TCP Packet design

I'm implementing a client/server app using JSON (as String) via TCP/IP. String --> Packet --> byte[] --> tcp/ip --> byte[] --> Packet --> String ...
6
votes
3answers
1k views

Elegant solution to find a pair of Strings in a List [closed]

I'm new to Java8 and I must find an elegant solution to a problem. The problem goes I have a List of letters (of any size) that could contain any letter such as "A", "B", "C", "D", etc. I must check ...
1
vote
0answers
41 views

Dealing with Future#get and InterruptedException Sonar java:S2142 [closed]

In some legacy code I have inherited, there is a snippet that looks similar to this. ...
4
votes
2answers
103 views

Sudoku solver recursive backtrack in Java

I am implementing recursive backtracking algorithm for sudoku. Below is the code to create board with random filling. I wonder if I can make it better in any terms of readable coding especially ...

1
3 4
5
6 7
201