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
1
vote
1answer
35 views

LRU Cache Example

Please check the following the LRU cache implementation. Thanks for the valuable comments ...
5
votes
2answers
275 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 <...
4
votes
2answers
84 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 ...
-4
votes
0answers
10 views

Display details of a person based on first name [closed]

Imagine I have 10 person in my contact list and I have given all the details of those person in JAVA. But all the details are based on individual person's first name. If I type the first name of ...
3
votes
1answer
45 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, ...
-1
votes
0answers
19 views

Drawing in java swing based on values in an array [closed]

I want to paint rivers based on information stored in a 2D array. Every index has information whether it has water or not (isDry()). How would I go about optimizing my current code? ...
-4
votes
0answers
18 views

How to find max possible wins for 2 player with numbered cards? [closed]

I have the following situation: There are 2 Player Each player has 'X' cards To find: max number of wins of Player 1 possible ...
3
votes
2answers
83 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 ...
4
votes
1answer
281 views

Creating and listing a song collection

Songs Class: ...
0
votes
0answers
29 views

Class Matrix client [closed]

I have yet to finish the client for class Matrix right away but I am having difficulty generating a matrix for client. Any help is appreciated This is what I have for the client ...
8
votes
3answers
812 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
41 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 ...
4
votes
3answers
517 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 ...
-4
votes
0answers
27 views

New on java tried to do something [closed]

I am trying to do some salary calculation and I am struggeling :( ...
0
votes
0answers
43 views

Spring Service and Controller [closed]

I have the following service and controller classes for the template I try to make most optimal. Is there anything lacking or unnecessary? Controller ...
0
votes
2answers
96 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: ...
2
votes
1answer
44 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
1answer
236 views

How to avoid code duplication with single varying parameter while tracking results

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 ...
2
votes
1answer
53 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
48 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 ...
2
votes
1answer
33 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 ...
-1
votes
0answers
37 views

Best way to optimize multiple search on Lists java

Anyone could help me to optimize this block of code, I already did a bit improvement but since I'm really bad with this kind of algorithms this all I've done so far. Much appreciate if you can explain ...
0
votes
1answer
42 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: ...
5
votes
0answers
28 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 ...
-4
votes
0answers
48 views

Given an array and an integer k, find the count of contiguous elements after k swaps

Given above the question of some codility challenge, I tried solution given below. Given solution passed all the given test cases but not passed performance test. Please help me to know where my ...
12
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: ...
2
votes
1answer
41 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: ...
0
votes
0answers
44 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 ...
1
vote
2answers
91 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 ...
1
vote
1answer
44 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 ...
2
votes
0answers
44 views

RemoteFile in Java

(Also, see the next iteration.) I have this tiny class for downloading files from internet: ...
4
votes
3answers
157 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 ...
4
votes
1answer
48 views

Directed Graph With Weights in Java

I am learning graph theory and I have implemented a Directed Graph with weights in Java. My next objective with this class is to learn more about algorithms like Dijkstra, Bellman-Ford, etc. I have ...
14
votes
4answers
644 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 ...
1
vote
1answer
57 views

Timer in Java with GUI

I have created a timer with GUI in Java. Here's the code: ...
1
vote
1answer
54 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. ...
4
votes
1answer
87 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
0answers
159 views

Simple REST web service

I am a young computer science student programming mainly in Java. I wrote a simple RESTful web service using Spring Boot Framework and the DDD architecture pattern. The project is a library ...
-2
votes
1answer
42 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 ...
5
votes
2answers
155 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 ...
9
votes
3answers
762 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 ...
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
33 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. ...
9
votes
3answers
847 views

Master Mind implementation

I have created a Master Mind BoardSolver. To apply the BoardSolver I have created an app (...
5
votes
4answers
478 views

Basic abstract graph implementation in Java

I am trying to write a graph implementation in Java. I would appreciate it if someone can please review the code for me and give constructive feedback. ...
6
votes
1answer
98 views
1
vote
1answer
72 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 ...
4
votes
2answers
99 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 ...
3
votes
3answers
119 views

An in memory Url Shortener in Java

This is a popular question in machine coding rounds. The requirements are to build a URL shortener. There are certain registered users who have the capability to define a URL and an optional time to ...

1
2 3 4 5
198