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.

3
votes
1answer
88 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
160 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
61 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 ...
-1
votes
1answer
57 views

How to divide a large method into 2 smaller methods [closed]

I have created a method that is responsible for the creation and the saving of memes. This is a huge mistake because now I need to use 1 of those functionalities (creating) for a different purpose. I ...
3
votes
0answers
32 views

Load all data from cursor

I have a Db table: 'aid' INTEGER, 'tid' INTEGER, Which represents connection between activity and task, so multiple tasks could be connected to one activity ...
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 ...
2
votes
2answers
61 views

A Java Iterable over multiple arrays

GlueArrays is used for iterating over an array of arrays, and it looks like this: Main.java ...
3
votes
1answer
91 views

Java simple game - guess the word

I developed a simple and short java game in which a random word is selected and the user needs to guess it's letters one after another. I'm a java beginner so I'll be glad to hear your thoughts. ...
4
votes
2answers
55 views

Three stage Sudoku puzzle generator

This was my first time attempting a project like this, so I figured it would improve readability, and would also just be nice If I allowed each stage to be visualized. Also, this only generates them, ...
0
votes
1answer
52 views

Time complexity of radix sort

I read time complexity of radix sort is O(wn) or O(n log n), if all n numbers are distinct. After implementation it look to me as if I have implemented radix sort which has time complexity of O(n ^2). ...
2
votes
1answer
52 views

Android Java Unit Testing model class

I'm trying to get familiar with unit testing. I never implement TDD previously, but I believe it's the best way to write software. So, here I'm trying to test my ...
2
votes
0answers
25 views

Sharing File (Content) without saving it before

I have a listview of PrivateFile objects which contain the fileId (int), fileName (String) ...
1
vote
0answers
26 views

A JavaFX for generating beeping sound on Windows via JNI

This is my practice program: a simple dialog box using which a user may specify a frequency of a sinus audio signal, and play it via pressing a button. It contains a GUI: App.java ...
3
votes
1answer
64 views

Program which accepts grades and prints grade distribution

I'm doing the MOOC Java course (CTRL+F "distribution"): The input of the program is a set of exam scores of a course. Each score is an integer. When -1 is entered, the program stops asking for ...
0
votes
2answers
109 views

Print diamond shape in Java

I'm printing a diamond shape in Java. It's working fine, but is there a way to re-write this code to make it faster? ...
2
votes
2answers
79 views

Minesweeper game in Java using Swing GUI

I created a Java Swing Minesweeper, for which I would like some feedback. Note : I'm just in high school so please excuse any 'dumb' ways I may have coded certain segments. Any tips or books on how ...
3
votes
2answers
79 views

java Thread-safe LRUCache implementation

What is best way to implement thread-safe LRUCache in java? Please review this one. Is there any better approach which can be taken here? ...
2
votes
1answer
87 views

Simple pattern matching between two string inputs using Java (Google interview challenge)

The interview question is: Write a function isMatch (without using java.util.Regex) that takes two strings as arguments: ...
0
votes
0answers
50 views

Basic Connect Four Game [Follow Up 1]

Here is an updated version of a basic connect four game I had posted previously. Changes include: an overhauled validator, simplifying the process by knowing where the last move was made Utilized an ...
1
vote
0answers
66 views

Java Android Sudoku solver

I made a simple and non recursive Android Java Sudoku solver implementing Algorithm X with links inspired from dancing links. The code is on Github (start with the Solver class and the ...
2
votes
1answer
50 views

Java homework exercises working with 2D arrays

For an assignment to study up on an incoming exam, I have to make these little functions. These are review style functions that make sure we know the algorithms and code necessary to do well on the ...
0
votes
1answer
40 views

Stopping a running thread

I am trying to stop an executing runnable instance after the run method has been called. I have come up with the below approach ...
0
votes
1answer
27 views

Spring Boot methods to add and remove relationships

I have a Spring Boot application and I wrote a piece of code to manage relationships between two entities. The code consists mostly in these two methods: ...
-2
votes
1answer
76 views

Java car program [closed]

I have to write a class that implements a class Car with the properties. A car has a certain fuel efficiency and a certain amount a fuel in the gas tank. The ...
0
votes
1answer
100 views

Counting the number of ways to decode a string

I am working on problem where I need to decode a string.. A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... ...
3
votes
1answer
34 views

Optimizing splay tree

I wrote an splay search tree using the algorithm description and debug and now I want to find out how I can optimize it, maybe I have some obvious errors and I will be glad if someone shows them to me....
5
votes
3answers
111 views

Confuse a text without making it unreadable

Scientists have found that a text can still be read even if only the first and last letter of a word are in their right place. The remaining characters within the word can be arranged randomly. ...
0
votes
1answer
134 views

XMLGregorianCalendar to LocalDateTime

From some generated code I get a javax.xml.datatype.XMLGregorianCalendar and I want to convert it to a LocalDateTime without any ...
5
votes
2answers
556 views

Predict mars robot position

Description A robot lands on Mars, which happens to be a cartesian grid; assuming that we hand the robot these instructions, such as LFFFRFFFRRFFF, where "L" is a "turn 90 degrees left", "R" is a "...
10
votes
3answers
2k views

Finding the number of integers that are a square and a cube at the same time

I have written some code that takes two integers and returns the numbers of numbers that are both a square and a cube. I would like to know if there is a more efficient way to write this. I have only ...
3
votes
3answers
119 views

Writing a calculator in idiomatic Java

I just dipped my toes in Java today (coming from C++) and made a few things to learn it. The standard stuff like Atari Breakout, Tic Tac Toe and this calculator. This has been done so many times ...
3
votes
1answer
111 views

Implementation of Multiparental Sorting Crossover

I implemented the Multiparental Sorting Crossover as described here in section 4.2. The (compiled) program can be run as follows: $ java MPSX input.txt where ...
1
vote
1answer
39 views

HackerRank Left rotation code using Java 8

I tried to solve this Left Rotation problem on HackerRank. My code works out for most test cases, but for some it doesn't, probably because they have large number of data. So there seems to be some ...
2
votes
1answer
84 views

Skyscraper puzzle solver in Java [closed]

For an assignment, I have created a solver for the Skyscraper Puzzle: Each puzzle consists of an N×N grid with some clues along its sides. The object is to place a skyscraper in each square, with a ...
2
votes
3answers
65 views

Display command-line Hangman

This code is part of my Hangman game. One of my minor issues is how to properly print out the hangman. Could you please give me hints on how to make the code less hardcoded? This code is so redundant,...
0
votes
1answer
49 views

FollowUp CommandLineInterpreter (CommandLineInteraction)

I wrote an command line interpreter (CLI) in Java and got some real helpful hints on how to improve. The cli is responsible to pick up the users input (via keyboard aka command line) into any app ...
1
vote
0answers
27 views

Socket sending/receiving data

I am a beginner in Android and this is my first big project in it. I am trying to communicate with an STM Discovery board using an ESP01 module. Below is the client connection class ...
1
vote
1answer
50 views

Optimize Multiple Insert SQLite Coming From MySQL

I'm currently developing an app that requires sending and receiving of data from android studio going to MySQL and then data coming from MySQL will be saved from the SQLite. I need advice on how to ...
4
votes
1answer
76 views

Code to replace list of integers with nearest bigger element

The original question was in the context of an array, but I just used a list without changing the length for easier debugging purposes of toString(). Given an ...
3
votes
1answer
69 views

Sending and receiving of JSON data to and from Android Studio

I'm currently developing an app that requires sending and receiving of data from android studio going to MySQL and then data coming from MySQL will be saved from the SQLite. I need advice on how to ...
1
vote
0answers
32 views

Consumer Producer problem solution using JDBI, MySQL, HikariCP

The app suppose to solve a subset of Producer–consumer problem. One producer, one consumer thread and buffer. The idea of the app to handle correctly database downtimes. The solution is to keep ...
-2
votes
1answer
23 views

List of abstract object that requires instanceof and casting [closed]

I Have a class which calls a method, that will convert an excel file, and each sheet will be a DTO, and returns a list containing those DTOs ...
2
votes
2answers
93 views

Given a list of integers, write a function that returns the largest sum of non-adjacent numbers? Numbers can be 0 or negative

Given a list of integers, write a function that returns the largest sum of non-adjacent numbers. Numbers can be 0 or negative. For example, [2, 4, 6, 2, 5] should return 13, since we pick 2, 6, ...
1
vote
1answer
58 views

Parsing a string to a java LocalTime

I have a method that can take in a time string in one of the following formats: HHmmss - e.g. 073055 = 07:30:55 ...
1
vote
1answer
97 views

Java CommandLine Interface implementation

I write a lot of mini apps. Each app has its own InputHandler for input from the keyboard. It's time to make a lib for that purpose - a ...
2
votes
1answer
51 views

Dynamically Generating XML Deserialization Classes / Code: Part I, Reading

I'm building an IntelliJ Plugin which will allow a person to select an XML file (and even a snippet of XML in the file, if they like) and, using a really brief GUI, generate classes / code in one of a ...
3
votes
2answers
77 views

Longest common subsequence solution

I've seen this today on a mock interview and wanted to give it a try. I'd love to hear some feedback from you guys. This is my second attempt at the problem, initially I had a mess of ...
2
votes
0answers
36 views

Add up values from one field for multiple months

I have data as follows: Payment Date 11/01/18 01/01/2019 11/01/09 11/01/20 Total Amount 4536.87 4654.98 4698.63 4687.69 I need to add up all of the ...