Stack Exchange Network

Stack Exchange network consists of 174 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.

1
vote
0answers
57 views

Java Swing “guess my number” game in Hexagonal architecture

Based on this article, I wrote a small "Guess my number" game in Hexagonal architecture which interacts with a Java Swing GUI adapter. Any feedback is appreciated. Main.java ...
0
votes
1answer
20 views

Simple Android Volley login request

I've made a simple login API request which gets a token as a response. I had to use Toast a few times. Is is possible to make it with only two ...
3
votes
1answer
79 views

Circuit builder that calculates resistance/current/voltage

I am somewhat new to programming. I've written a program that takes user input accepting voltages and resistors, and calculating total resistance/current/voltage in the circuit. I am looking for ways ...
0
votes
0answers
23 views

Spring Component Thread Safe

Recently I refactored an application to start using spring, and after some research, I found out that @Component is not thread safe. The class is this: (It's a converter from xlsx to json string) <...
1
vote
0answers
34 views

Java classes to load configuration data from a JSON file, with Scala tests

I want to implement classes in a project that will support the loading of configuration data from a JSON file. The JSON file is in the following form. Please be as critical as you can be. I'm a junior ...
2
votes
0answers
27 views

Color picker using WritableImage in JavaFX

I am making my own JavaFX color picker just for learning more about JavaFX. I am rendering a color wheel in JavaFX using WritableImage and I have a ...
1
vote
0answers
20 views

Data entry form with item and whole-form validation

I have 5 fields, and a button below: If field value is correct, then hint color, bottom line color and icon color should change. If all fields are correct, then the button color should change. I ...
1
vote
1answer
80 views

Products excluding each element of the array

Given an array of integers, return a new array such that each element at index i of the new array is the product of all the numbers in the original array except the one at i. For example, if our ...
3
votes
2answers
42 views

Find next number whose sum of digits is N

This program takes two numbers M(<10k) and N (<100) and finds the smallest number greater than M whose sum of digits = N. Additionally, as per the question's requirements, it prints the number ...
0
votes
2answers
44 views

Given a list of numbers and a number k, return whether any two numbers from the list add up to k

Given a list of numbers and a number k, return whether any two numbers from the list add up to k. For example, given [10, 15, 3, 7] and k of 17, return true since 10 + 7 is 17. How can i improve the ...
1
vote
1answer
38 views

Performing batch insertion for a single row

I've following code that insert single row in if (rows == 1) { part and inside loop it is batch insert. So I'm thinking to skip single insert and have it in batch ...
1
vote
1answer
23 views

Spring TaskScheduling with HashMap

I am currently developing a Task Scheduler to run different methods at a certain time. In general it is a Spring-boot application an task execution/scheduling is just a very tiny piece of the whole ...
1
vote
0answers
27 views

Applying Observer-Observable pattern to a code and multithreading

I have to: 1) Apply the Observer-Observable pattern to the original code. 2) starting from the original code, I have to suppose that the modification of the array fields (slot machine numbers) ...
1
vote
1answer
32 views

Java exporting filtered objects to CSV

I am exporting a List of virtual servers to a CSV file. The users submits filters and the applications generates FilterDTOs containing a map of the attribute and the corresponding value. The idea was ...
2
votes
1answer
118 views

Implementation of login and registration functions in servlet filter

I'm a newbie in servlet API. I have a test task to create a very simple web app with one home page and an authorization form. The requirement is to use filter somewhere in my app. Given that it's a ...
0
votes
1answer
65 views

Reducing nested if statements [closed]

I have a set of rules as follows: Product One: If either part is acceptable, update both parts Product Two: If either part is acceptable, and one age is > 55, update both parts If either part is ...
-1
votes
1answer
58 views

Retrieving a parser [closed]

In the main method, I have to call a factory to retrieve the Parser and cast it to a child parser to read the different file. How should I improve the code for it to make more sense? Can I avoid ...
0
votes
0answers
45 views

Simple card game with updating GUI

I have coded a simple card game that updates the GUI each second and contains many nodes in game which are used to display game events and animation. People who have tried the game said that their ...
0
votes
0answers
26 views

Android - Notification service to handle background notification

PREMISE: I have zero knowledge of Java and Android development. I put this together in a couple of weeks. The code works. But I look forward to some feedback and to know how I can improve it. ...
1
vote
1answer
43 views

Combine data from a list and map based on criteria

I am using Java 8. I want to build a final list using following data. All objects in basicData list must be added to final list. But if there is a matching object based on matching key from modData ...
0
votes
1answer
53 views

Testing an Assignment class

This is my first programming assignment. This is a second file that is intended to test the setters and getters (both constructors and no-argument constructors). How can I clean this up (curly ...
2
votes
1answer
37 views

Method that Saves user text messaging draft [closed]

I am working on saving the text messaging draft of a user. The flow currently works but I am looking to make this block of code easier to read and smaller. Could anyone help me achieve this? ...
0
votes
0answers
37 views

Inter Thread communication between n thread

The following program takes 3 integer inputs(noOfThreadToBeCreate,fromNo,toNo) and print the Consecutive numbers based on the range using different threads e.g (Thread 1 - Print 1, Thread 2 - print 2, ...
1
vote
1answer
54 views

Developer Assignment - Family Tree

I have an alternative solution for family tree that have been posted some time ago and please forgive the similarity of the task but when i tried to post alternative solution in someone else's post ...
0
votes
1answer
51 views

Class to fill model objects with data from the database

This is a helper class that helps fill models with data obtained from the database. ...
0
votes
1answer
27 views

Android TCP server that maps data to an object and sends it to a service

This is a code for an android thread. This is a tcp server and gets data from socket, maps it to an object and sends that object back to the main service. If there is anything I'm doing wrong or if ...
2
votes
3answers
84 views

Checking if a sequence is almost strictly increasing

The question Given a sequence of integers as an array, determine whether it is possible to obtain a strictly increasing sequence by removing no more than one element from the array. My java ...
3
votes
2answers
59 views

Genesis, an AI that learns as you talk to it

This is a programming challenge I set for myself a while back to create an AI that starts with no knowledge of anything whatsoever, and learns as you talk to it. (It can learn stuff like your name, ...
4
votes
1answer
85 views

Simple Password Vault

I made a simple password vault in Java and I was wondering if anyone had any input on it. The code works fine, I just wanted to know if there are any improvements that could be made. ...
1
vote
0answers
38 views

Bin-packing-problem solution using recursion

I needed to make a freight calculator and had to solve a bin packing problem. I utilized a github package. Basically with the help of my stack overflow question I made a class Method that Splits an ...
2
votes
1answer
42 views

Counts “islands” of 1s in sea of 0s (2d array matrix)

This solution surpassed 100% of submissions for efficiency! My method was to recursively check surrounding values and change any contiguous "land" to "water". Is there a better way to write what I ...
4
votes
3answers
114 views

Abstract classes in Blackjack game [closed]

From what I've read, I should use abstract classes when I want to define behavior for a superclass, and I don't want to instantiate the superclass. So, I'm making a Blackjack game in Java, and I want ...
1
vote
0answers
59 views

Critical section around given key

I would like to know if there is any pre-existing implementation of my solution so I don't have to reinvent the wheel. What I'm trying to create is an utility which allows me to create critical ...
1
vote
1answer
23 views

Getting multiple table schema and returning them, using one helper method

I want to get two distinct sets of schema from a database without having to create multiple Connection/PreparedStatement/...
0
votes
1answer
88 views

java.util.Set extension/implementation

Lately, I was working on some experimental java.util.Set extension, IdSet: ...
1
vote
2answers
80 views

Business rule updater

I'm trying to increase the speed of my application at the moment. My inserting/updating methods were opening every time a new connection which took too much time. I read that it's better to create a ...
0
votes
0answers
39 views

Brute force least adjacent swap anagram transform in Java

In this post, we are given two anagrams, and we wish to compute a shortest sequence of adjacent character swaps. For example, ...
1
vote
1answer
35 views

Simple local cache that checks by date else get from db

I'm looking for feedback on how this can be improved, basically what I'm trying to do is check if the cache has the object else check from the database. I have list of ids, then I separate them based ...
0
votes
1answer
63 views

Efficiently compare 2 lists to replace and order

I have 2 list containing some Objects (Fruit class). I am using a 3rd list to add these elements based on following 2 criteria. I want every object in the 1st list added to 3rd list. But if I have a ...
-1
votes
2answers
70 views

Rotating an array

I would like to know if this is a good solution. This code works but is it efficient enough as i have seen some solutions with \$O(1)\$ time complexity. ...
2
votes
1answer
98 views

Family Relationship Tree

Developer Assignment - Family And Relations Going through the old stuff in his attic, Indiana comes across a chart which looks like a family tree of multiple generations which shows his ...
3
votes
1answer
50 views

Implementation of generic Graph class and Dijkstras

I participate in competitive programming contests, and I found myself implementing and re-implementing graphs constantly. So I decided to create a reusable implementation of a Graph class, and ...
0
votes
1answer
50 views

Breaking a 32-bit value into bytes for an ArrayList

I am very new to Java and its collections and I'm trying to figure out "best" way to populate an ArrayList<Byte> in Java. In particular, I'm trying to take a ...
1
vote
1answer
41 views

Sorting algorithms in Kotlin - Bubble, Insertion, Selection, Merge and Quick sort

Introduction I decided to try Kotlin because of its forgiving nature to long-time Java users. I implemented a few introductory sorting algorithms and would like to have them reviewed, not just to ...
2
votes
2answers
136 views

Given a word, find other words in an array with same length and same characters

I tried solving the problem in the following manner; I am just a beginner and wanted to know my mistakes and a more efficient way with better time complexity (if any). ...
0
votes
1answer
54 views

Counting number of pairs in an integer array

So, I wanted to have the count for number of pairs of same integer there are in an array for which I used a HashMap Input contains two lines: Integer n: Signifies the size of input Input ...
1
vote
1answer
99 views

Solving a multi variable polynomial

For this equation, I need to count possible solutions: $$ a + b^2 + c^3 + d^4 \le S $$ $$0\le a,b,c,d \le S$$ I tried the following approach: ...
0
votes
1answer
63 views

Searching for a sum of any series in array

I'm given this method, and requested to analyze what it does, and minimize its complexity (both time and space). All values are known to be larger than zero. ...
1
vote
1answer
43 views

Simple Binary to Decimal Converter

I just recently began going over number systems again, granted I didn't pay very much attention to it the first time for lack of understanding its importance (I've only been coding for a year and some ...
2
votes
2answers
85 views

Using the stack algorithm for parenthesis matching

I have used Stacks to check for brackets mismatch. (Parentheses matching problem using Stack algorithm) Any suggestions on how to improve the code? I have tried various examples and it works ...