Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

2
votes
0answers
61 views

Many-readers-one-writer with semaphores and multithreading

I've been looking for a solution to the may readers one writer in Java. I was intrigued by this question posted here and I read the Wikipedia entry about it. So far, I've reached a fine solution, or ...
4
votes
2answers
75 views

Rest Controller in Spring Boot for Rock Paper Scissors REST API

I have created a Spring Boot Microservice for playing Rock Paper Scissrors. I have tried to follow best practices, but still would appreciate some critique on my code. Thanks. ...
2
votes
2answers
51 views

Immutable employee class

I have created an employee object to be immutable. ...
3
votes
1answer
89 views

Java BigInteger implementation

I've written a java application that can handle operations on big integers implemented with array list of digits. I have a difficulty with the way I implemented the divide method, because when the ...
2
votes
1answer
52 views

Pairing unit fractions

(I was suggested to post here from stack overflow so hey guys!) I have been given a problem where fractions between 1/2 - 1/1000 have to be added to create the longest sequence of all unique unit ...
2
votes
1answer
62 views

Transmission Of Messages

I have an assignment to solve this problem. Problem Description Bob the Cat is building a new system, dubbed the Cats Transmission System (CTS). This horribly inefficient system utilises cats to ...
0
votes
0answers
46 views

Median of three partitioning taking more time than standard quicksort in java

I implemented a standard quicksort and I have a project where I need to improve it. I am trying to make quicksort faster by implementing median of 3 partitioning. I copied codes from trusted ...
2
votes
0answers
165 views

Let Them Eat Lists, Eventually (Asynchronous Generic List Consumption with Spring and CompletableFuture)

I want to reduce some repeated code in my Java 1.8/Spring Boot application, and to that end I tried to make a reuseable asynchronous utility module. In essence its an async List.forEach that takes a ...
1
vote
0answers
34 views

Median of 3 partitioning taking more time than quicksort in java

I have a quicksort code in java which I want to improve. The improved code should take less time than the quicksort code. However when using my improved code which implement median of 3 partitioning, ...
1
vote
2answers
55 views

Given an integer k and a string s, find the length of the longest substring that contains at most k distinct characters

Given an integer k and a string s, find the length of the longest substring that contains at most k distinct characters. For example, given s = "abcba" and k = 2, the longest substring with k ...
1
vote
1answer
52 views

Multithreading to allow multiple clients on to a server and client requests handling

I have to create a client-server JavaFX application using MVC which does many operations consisting mainly in messages exchange. I'd like to know if this way to handle client acceptance and client ...
2
votes
2answers
57 views

Class to transform milliseconds to current date

The task Given a variable of type long with the number of milliseconds from January 1, 1970 until a later date (CurrentDate). Build a class for get the year, month, day of year, day of month, hour, ...
1
vote
1answer
44 views

Improving my Java class that prints tabular output

I started learning Java not long ago. Quite often, assignments require me to print output in a table. I had some spare time last week, and I wrote a separate class for printing tables. It is working ...
2
votes
1answer
110 views

Positional change program in Java

I've written a program and it needs a review by skilled programmers. The programs goal is to change 0-s to X and ...
3
votes
1answer
76 views

Organize musicians into rows, with weight and population restrictions

So I just completed this project for my java programming class and was wondering if there was any way I could streamline it to really impress my professor. Here were the instructions, followed by my ...
2
votes
2answers
67 views
8
votes
3answers
101 views

Stack as a Persistent Data Structure Implementation

After reading some articles about immutability, I found out that there are persistent data structures. In the following, I implemented a stack as a persistent data structure. What I like about the ...
5
votes
1answer
46 views

Java program that relaunches itself in OS's terminal application

I wrote a Java program that when its executable .jar is opened manually, it re-opens itself inside the operating system's shell console. The purpose of this is to have a C#-style console application ...
3
votes
2answers
69 views

Graph using adjacency list in Java [closed]

This is the main code. Here I'm joining vertices by edges. ...
1
vote
1answer
68 views

Return the number of unique ways you can climb the staircase

There exists a staircase with N steps, and you can climb up either 1 or 2 steps at a time. Given N, write a function that returns the number of unique ways you can climb the staircase. The order of ...
1
vote
0answers
52 views

Proper separation of behaviour and data structure when the data structure is complex

The code in its full glory, complete with unit tests is here (and some discussion of the issue). I am struggling with how the principle of separating data structures and behaviour applies here. This ...
6
votes
1answer
118 views

Snake Game in Java feedback

I started coding in August 2018, and I was wondering on how I can improve as a programmer. I'm more concerned about coding conventions. Particularly, how can I improve the structure of my code, ...
0
votes
0answers
31 views

PlayFair Cypher in Java

So I am a college student and I am trying to create a GUI that has a file chooser that opens the txt file in a dialog. Then the user chooses a secret code and the program decodes it using the ...
3
votes
1answer
123 views

Java Maze Solver (DFS)

I was asked to create a Java program that will navigate through a series of mazes. I would like to know if this is the optimal way of using a DFS or is there a better way and I am doing something ...
1
vote
2answers
74 views

A simple card game simulator

This is a homework question, and I have written the code but wasn't sure if I had picked the right data structure for this job and minimised time complexity. Can anyone give me some feedback, anything ...
3
votes
1answer
76 views

Find out how many laptops Molly can buy based on available money, array of quantities and array of costs

Problem description: Molly wants to purchase laptops for her school. Find out how many laptops she can purchase by comparing the vendors available. Each vendor sells the laptops in batches, with ...
2
votes
1answer
50 views

Java Pi Calculation using an Averaged-Leibniz formula

While trying to discover a way to calculate the digits of Pi faster with the Leibniz formula for Pi, I noticed that, if I took two consecuent numbers in the series, and calculate their average, I ...
4
votes
1answer
62 views

Given a query string s and a set of all possible query strings, return all strings in the set that have s as a prefix

Implement an autocomplete system. That is, given a query string s and a set of all possible query strings, return all strings in the set that have s as a prefix. For example, given the query ...
1
vote
0answers
37 views

AST Visitor Pattern in Java

I am trying to make a simple expression evaluator in Java using Jacc (a parser generator). I am done with the AST creation and now need to create an evaluator. For this I made a simple test to try to ...
0
votes
0answers
40 views

gRPC Java client with TLS Mutual authentication

I'm not a Java developer but I'm trying to put together a quick start snippet to help Java users consume our service using code generated from .proto service definitions. I've cobbled together some ...
-3
votes
1answer
55 views

Code creates huge Text File [closed]

A Java program that writes each digit on a new line, from 1 to max integer. We should end up with 2.4 Billion lines. After looping to near the maximum integer, the text file becomes really huge. Like ...
2
votes
0answers
54 views

Firebase login/registration process for a dating app

I am developing another bigger project, I want to try a simple DatingApp and currently I try to develop a Login and Registration Form. There is no special register / login button, the code will later ...
1
vote
1answer
85 views

Java concurrency exercise, implementing transfer of amount from one account to another

This is in continuation with my synchronized implementation of a bank account in Java. I am trying to implement bank accounts repository and method to transfer money from one account to another. My ...
6
votes
2answers
101 views

Implementation of a simple hash function

This is my implementation of a hash function described below. The (compiled) program can be run as follows: $ java Hash1 < input.txt The program reads a text ...
1
vote
1answer
113 views

Command pattern for simple text editor

I was asked to code a TextPad with following functionality: display() – to display the entire content display(n, m) – to ...
7
votes
2answers
790 views

Synchronized implementation of a bank account in Java

I am trying to implement a bank account with Java in a thread safe way. My code looks like: ...
0
votes
0answers
59 views

Brute-force cracker for hashed passwords

I want to crack the password hash. This is my data which I want to display the username and the passwords. This is my code ...
3
votes
1answer
43 views

GreetingCard problem with Coordinates

This is a practice problem on Kattis I have exceeded the time limit for the 5th out of 11 test case. Can anyone inspire me what could be done to optimize the code? Problem Description Quido plans ...
12
votes
2answers
673 views

Calculate the frequency of characters in a string

I wrote this program to check the number of times that each letter appears in a string input by the user. It works fine, but is there a more efficient or alternative solution of going about this task ...
0
votes
1answer
38 views

Allocate Resource Effectively [closed]

I have module called printer allocator (PrinterAllocator) which will allocate the next available printer to the requester. ...
5
votes
1answer
80 views

Phonebook using a trie

I implemented a PhoneBook utilizing a Trie data structure. Could I ask you to evaluate it? Did I apply Trie correctly for such ...
4
votes
1answer
73 views

Simple HangMan game Implemented in Java

This simple implementation of the HangMan game in Java is a side project, unlike the usual programs I write which are either school assignments or problems on coding websites. It feels great to have ...
7
votes
1answer
59 views

Validating user input

I've written the below code to validate user input but I feel it's quite excessive for what seems to be a simple operation. I want to only accept non-negative integers or doubles as an input. This ...
1
vote
1answer
25 views

Select depart date, 5 days from today and return date, 6 days from today in Selenium

I am automating a scenario of flight booking on Cleartrip.com(https://www.cleartrip.com/flights) in which I have to enter depart date, 5 days from today and return date, 6 days from today. I have ...
2
votes
1answer
63 views

Getting the current timestamp and compute the timestamp difference in minutes

I have this code to get the current Timestamp and compute the last timestamp's difference with the current timestamp in minutes. I'm wondering if this can be optimized further for production. ...
1
vote
2answers
67 views

Permutation and subsequences of string

I have an assignment to solve this problem. I’m not too sure how permutate works by tracing, just tried on inspiration and it works. This code runs on all provided test cases, but I’m just trying to ...
3
votes
1answer
86 views

Ranking Score System

I have an assignment to solve this problem. There are a total of 12 test case files, 1 of which that I have failed due to exceeding limit on the script. Question Description Bob has somehow ...
1
vote
1answer
24 views

Debugging aid for collecting objects from everywhere into a single scope

Today I faced a difficult problem where I needed to step through several totally unrelated classes, and I suspected (among others) an object aliasing problem somewhere deep in the framework layers. ...
8
votes
1answer
159 views

Recursive parser from Binary to JSON output

Background I got this interview test and got declined due to not meeting their expectations, but never got a reason on what was bad and how they solved it. I want to improve and learn something out ...
1
vote
1answer
59 views

JavaFX Exercise Application

This is a pre version of my program. This program is about solving exercises. Because this is one of my first graphical applications, I want to know, what can be improved. To this point I usually ...