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.

-1
votes
0answers
6 views

LeetCode 773. Sliding Puzzle - DFS Logic

I tried to solve the LeetCode Sliding Logic Puzzle using BFS and DFS. My BFS solution worked, but my DFS solution did not ... and I cannot figure out why. Here is the original question: https://...
4
votes
2answers
736 views

Compiling and throwing simple dynamic exceptions at runtime for JVM

I've been using my Dynamic Exception with C# for quite some time already and it saved me a lot of time. This means, I don't have to create a new exception ...
2
votes
2answers
242 views

Java converter from Arabic to Roman Numerals

I am learning Java and would like to get feedback on the code I wrote. I have written an implementation of an algorithm (found here) for converting any decimal Arabic number to Roman numeral string. ...
0
votes
0answers
8 views

What is the classes in MapReduce check for stragglers and speculate tasks? [on hold]

From my limited knowledge of Hadoop, I understand that the TaskTracker is in charge of Map and Reduce tasks. I am attempting to modify the decision to speculate slow reduce tasks by (1) checking for ...
1
vote
1answer
49 views
4
votes
3answers
8k views

Inserting 100000 records to MySQL takes too much time

I'm using spring boot, hibernate any MySQL for reading 100000 records from csv file and write the same to the database. I'm doing the batch insert where the data is committed at intervals equal to ...
4
votes
1answer
174 views

Lazy Loading a Bioinformatic SAM record

I'm currently writing an API to work with Bioinformatic SAM records. Here's an example of one: ...
2
votes
1answer
116 views

Helper class for Fragments management

A Helper class for Fragment Management. The FragmentsManager class has methods to add and replace fragments. The replace method checks if the given fragment is present in backstack or not and if the ...
1
vote
2answers
84 views

Typed properties in Java

I tried to build a "typed" property system in Java and this is what I came up with: first the class Properties that any class can use as an attribute (demo code in the end). ...
-5
votes
3answers
2k views

Finding the longest Collatz Sequence

Inspired by Project Euler 14: Longest Collatz Sequence "Which starting number, under one million, produces the longest Collatz Sequence chain?" I wrote the following Java code: ...
0
votes
1answer
48 views

Design a sustainable home tracker and calibrater for power, water, gas to minimize the expense

Problem Statement Following are the various scenarios to be considered Track energy - Track consumption of water, gas and electricity. We should be able extend to capture other type of ...
-2
votes
0answers
20 views

Writing classes to withstand future business logic changes [on hold]

I have a processor class AbstractProcessor and multiple concrete classes of the same which gets called in order of the business logic. ...
4
votes
2answers
54 views

Configuring an editor for various languages using Factory Method Pattern

I need to know if my code is a valid implementation of the factory method pattern. Also, if the Configuration and Editor were interfaces would this still be a valid implementation of the Factory ...
-2
votes
0answers
16 views

inputMismatchException [on hold]

im designing a class that stores the name of three runners and time it took to finish the race. this class has methods that return the name of the runner in 1st, 2nd and 3rd place ...
2
votes
1answer
1k views

Accessing Adapter data from ViewHolder

In my Android app, I need to disable a button in Layout if the api return status as 0. I get this status in the Adapter and based on it, I have disabled the button in ViewHolder which is inflating the ...
0
votes
0answers
17 views

Select a value other then currently selected drop down value

Scenario:Select a any other value other then currently selected from a drop down. Please help/review the code and tell me whether this is a efficient solution? ...
1
vote
1answer
73 views

ROW (Race of work) simulation

I wrote a ROW (Race of work) simulation, the idea contains a mathematical bug and, I asked a question about it here. I would also like to make this code more readable and, this is why I am sharing it ...
1
vote
5answers
2k views

Exception handling calculate power

I've to create a class MyCalculator which consists of a single method long power(int, int). This method takes two integers, and, as parameters and finds Math.pow(n,p). - If either n or p is negative, ...
3
votes
1answer
141 views

Java console banking

So I wanted to write a basic console based banking app to practice my skills. It makes use of BigDecimal to ensure accuracy. Here is the MVP I plan to enhance it with all banking features soon. I ...
2
votes
0answers
169 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 ...
5
votes
4answers
2k views

LeetCode “Jewels and Stones”: counting certain characters in a string

LeetCode "Jewels and Stones" You're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. ...
-4
votes
0answers
41 views

Why is return nothing?What is mean? [on hold]

public void tableMousePress(MouseEvent e) { if (tablePositions.size() == 0) return; }
5
votes
1answer
51 views

JavaFX Connect Four AI

I made a Connect Four AI with minimax algorithm. It's my first bigger JavaFX project. Any help for improvements would be really appreciated. Board: ...
0
votes
1answer
1k views

Java MongoDB client as a singleton

Is below code a valid Singleton design pattern for Mongodb in Java? Please suggest any improvements. ...
1
vote
4answers
102 views

Find the thousandth integer without the digits 3, 4, and 7

I have to find the thousandth number (excluding numbers 3, 4, 7) but it's taking a long time, about 9 seconds. I'd like to find out how to improve performance. ...
1
vote
1answer
91 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 ...
2
votes
1answer
295 views

Simple Java OOP calculator with GUI

I'm learning Java and I've tried to write my own calculator with GUi based on this post. Here is the repo: https://github.com/MurDaD/java-calculator Could someone check my code and tell me how to ...
2
votes
1answer
80 views

Implement Queue using fixed size array

I came across below interview question and I am working on it: Build a queue class with the enqueue and dequeue methods. The queue can store an UNLIMITED number of elements but you are limited to ...
1
vote
1answer
1k views

Java API token expiration handler

I want to implement a utility class which manage tokens generated by any API. The idea is simple: It should store the current token value. The token should be initialized just before first use ...
4
votes
3answers
438 views

Organizational Tool GUI with Java Swing (and GridBagLayout)

My first 'large' project is to create an organizational tool. Right now, it's pretty basic, but nevertheless functional in terms of the intent of the current release (v0.3.0). My main question is: '...
0
votes
1answer
20 views

PreparedStatement for closable recordset and connection

Following approach uses more Functional approach (non OOP), each method is passed DataSource as dependency. I've written this piece and I'm wondering if there's something that can be improved. I wish ...
1
vote
0answers
32 views

Java local service with sockets

My goal was to create a Java service on Windows that runs locally and communicates with local programs using JSON. The service should be reliable and robust. The service runs a ServerSocket and ...
3
votes
1answer
199 views

Updating the icon of every JLabel in a JLabel ArrayList

I want to update every icon of a JLabel ArrayList, to its own individual icon based off of an outside ...
1
vote
1answer
126 views

Optimising multiple streams to single loop

I am trying to find the best way to optimise the converters below to first follow the flow I call convertAndGroupForUpdate, which triggers the conversions and ...
8
votes
3answers
1k views

Reorder a list of courses, given their prerequisites

I recently graduated from college and applied for a position with a company. I was sent a coding exercise as part of the process. After completing the exercise and submitting it I was told that the ...
0
votes
1answer
3k views

Generating unique alphanumeric ID's of a fixed length

I am needing to generate unique id's for users. The 'unique' part is the problem for me. The 13 character id's which have a format of the following: 0 + random int with range of 1-9 + random letter ...
2
votes
1answer
157 views

External polyphase merge sort

For comparison with other external sorting algorithms, I have implemented external polyphase merge sort, purported to be useful to sort large files that do not fit into main memory. More theoretical ...
-3
votes
0answers
43 views

What's the complexity of the algorithm to find median of 2 sorted arrays [migrated]

There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be \$O(log(𝑚+𝑛))\$ Here is the code that I ...
1
vote
1answer
92 views

Read in a file, check that it meets certain criteria

This was my original posting: Check that a data file contains the expected number of rows and columns of integers I updated the code. Still what could I improve on? Another question I have is how ...
5
votes
4answers
12k views

Find the binary gap of a number N

For example, number 9 has binary representation 1001 and contains a binary gap of length 2. The number 529 has binary representation 1000010001 and contains two binary gaps: one of length 4 and one of ...
0
votes
1answer
60 views

Combinational string search using Java

I wrote a program that receives 2 strings (Input and Search) in the Search string. The sign '+' indicates that if the substring before the '+' exists in the Input string. (The search string cannot ...
0
votes
1answer
37 views

Making Anagram Problem Implementation

Problem Statement Alice is taking a cryptography class and finding anagrams to be very useful. We consider two strings to be anagrams of each other if the first string's letters can be rearranged ...
1
vote
0answers
19 views

Implement search for JPA and Spring

I'm trying to implement properly search functionality for database table. I tried this approach: Controller: ...
3
votes
0answers
69 views

Java game: select numbered tiles to form a goal sum

This is a homework project (Soft. Eng.) which I have completed. My teacher gave me a 91, but I am unhappy with this grade because my code is quite messy. (Please excuse incomplete Javadoc, the code is ...
-2
votes
1answer
35 views

Search customer by ID not printing [closed]

I dont know why my code is not working at all. In my Eclipse there's no errors shown at all. I want to use the id to print the name of my customers, and that's my goal ...
-3
votes
0answers
25 views

Trying to output a game [closed]

I need help with the area I think I highlighted with arrows (static void updateTeam & processUpdate) Suppose to output a game where you type in a team and it will out put win, loss, and ties. ...
-3
votes
0answers
19 views

Tictactoe minmax recursion causing confusion [closed]

I read a number of tic tac toe examples using the minmax algorithm but haven't found a good one that really explains what's going on. I've written one that works but need help understanding a small ...
1
vote
1answer
50 views

MinMax Problem Implementation

Problem Statement: You will be given a list of integers, arr, and a single integer k. You must create an array of length k from elements of arr such that its unfairness is minimized. Call ...
3
votes
1answer
194 views

Converting Reverse Polish to Infix Notation in Java

I am trying to solve a programming challange that involves converting reverse polish notation to infix notation. For example: 1 3 + 2 4 5 - + / would be: ((1+3)/(2+(4-5))) My solution so far does work,...
0
votes
1answer
834 views

Print odd and even numbers using two threads in Java

I was asked below question in an interview where I need to print out even and odd numbers using two threads so I came up with below code one without synchronization and other with synchronization. <...