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.

680 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
2
votes
0answers
271 views

Generic Builder in Java needs annotation support

I was thinking about how to minimize the code needed to implement a builder. There is some code that any builder needs to have: Temporary storage of property values Validation of type Null check ...
2
votes
0answers
51 views

Regex to find wildcard imports in Java

Could I get a review on the following regex: ^import[\s\S&&[^\*\n]]*?([\*]{1}\;\s*$) All the details: Years ago a colleague shared a useful little regex ...
2
votes
0answers
295 views

Threadsafe static initialization of ExecutorService

I am trying to create a threadsafe singleton class based on Initialization-on-demand holder idiom . Here is my code ...
2
votes
0answers
94 views

Improved Atkin-Bernstein sieve for generating primes

This is a class from my personal code library, and from a package which deals with integer sequences. It implements an interface ...
2
votes
0answers
4k views

Android Canvas - Draw a line graph with a gradient whose color depends on the y value

I'm looking mostly for feedback on a solution of mine. I want to create a pretty line graph where the color of the line is dependent on the Y value, and a change in color at ...
2
votes
0answers
96 views

Getting the math right for a Hidden Markov Model in Java

In an effort to learn and use hidden markov models, I am writing my own code to implement them. I am using this wiki article to help with my work. I do not wish to resort to pre-written libraries, ...
2
votes
0answers
891 views

Finding a repeated pattern and doing something with the match

I have several implementations of finding a repeated pattern and acting on the matching input if it is found. So I want to find this ...
2
votes
0answers
59 views

Two similar methods to re-create objects and emit events

I have these two methods basically doing the same thing: ...
2
votes
0answers
165 views

Using blocking queue to calculate data stream - Generalized

A followup on my previous question Using blocking queue to calculate data stream. This time suppose we have a list of blocking queues as stated in the following manner: Suppose you have a list of ...
2
votes
0answers
79 views

Computer Algebra System that computes symbolic derivatives

I have a system that parses a mathematical expression String, creates a derivative expression tree, and reconstructs the derived expression into a new ...
2
votes
0answers
67 views

Don't Update Every AI Every Tick

In my game there are AI characters that try to either steal your gold or destroy the walls of your castle. Previously I simply updated them all every second, but with a large number of characters on ...
2
votes
0answers
32 views

Public function that traverses through a tree

So I have this function that lets one traverse through a tree without having to get the root node of the tree. The user basically sends a parameter that is either ...
2
votes
0answers
38 views

DynamicIterable

I have written this DynamicIterable that can be used as a Lazy Iterable, where you give it a Supplier<T> of something and ...
2
votes
0answers
268 views

Follow-up 1: Compare 2 unordered, rooted trees for shape-isomorphism

The previous post can be found here. In the previous post I tried to solve an exercise but found through the answer of Peilonrayz a bug in the code and 2 more while fixing it. These have now been ...
2
votes
0answers
443 views

Extend OnClickListener and animate view in android

I'm working on animation and I want to organize my code in best way I'm new in android and not know too much about this. Here is my code that I'm using to animate ...
2
votes
0answers
134 views

Neo4j traversal algorithm to find dense nodes

I am trying to get familiar with traversals algorithms implementations in Neo4j and to practice I am implementing classic graph algorithms (not judging if is the best approach or not, just for the ...
2
votes
0answers
479 views

JavaFX Kings Game

I am working with javafx making a simple Kings game. I am currently in a Java course at school and this is just a side project I am looking to get some feedback on. Main.java ...
2
votes
0answers
486 views

N-dimensional array generic methods

I asked a similar question yesterday and got a brilliant answer, but unsure how I could adapt these methods. The methods perform a BFS on a state and then store the values in a multi-dimensional ...
2
votes
0answers
46 views

GIF Animation in JME3

I made the following class to handle 2D animation through GIF images. This is made using JME 3.1, Java 8 and this GIF library. Is what I'm doing optimal? Are there already other available libraries or ...
2
votes
0answers
79 views

JFileChooser selecting a file

My code is working fine to save a file with FileChoser. But how can I make it accurate and perfect when a user doesn't select an absolute path for a file and closes it abruptly? ...
2
votes
0answers
105 views

Pushdown-stack: Test if a pop order is legal or not

I'm currently working through "Algorithms in java" by Robert Sedgewick (3rd edition, in german) on my own and am trying to solve one of the exercises there. The exercise asks to develop and ...
2
votes
0answers
2k views

Create HTML table in a Java Servlet

Using a java servlet, I've been doing the same approach to building or updating HTML. I create the basic table on the HTML page, then call for the body from the servlet with ajax. As an example: ...
2
votes
0answers
59 views

Android app to let users complete tasks for cash

I am doing an android side project, and I was wondering if I could have my code reviewed to get feedback on improving its efficiency and overall elegance. Particular classes to focus on would be ...
2
votes
0answers
104 views

ByteUnit class to convert across size units

Based on java.util.concurrent.TimeUnit class I wrote similar class to convert size units: ...
2
votes
0answers
99 views

With 2 sets of strings, find a string that can be constructed from either set

Given the following sets of strings: are yo you u how nhoware alan arala dear de I need to find a sequence that can be constructed by concatenating the strings ...
2
votes
0answers
138 views

Spellchecker program is having issues due to vowel checking method

This program takes in a list of 275k or so words from '/usr/share/dict/words' and loads them into HashSet. It then takes in a list of 1000 words (taken from the dictionary and are scrambled (vowel ...
2
votes
0answers
852 views

KMP string-matching algorithm implementation

This is Knuth-Morris-Prat algorithm implementation to check if a pattern is present in a larger text, and if it does the algorithm returns the start index of that pattern, else -1. It starts off by ...
2
votes
0answers
46 views

Asynchronous service that publishes a possibly infinite amount of events

I want to implement a service that fetches eyetracking events and publishes them to all subscribers of the stream. The whole thing is supposed to run asynchronously, so it doesn't block the UI thread. ...
2
votes
0answers
374 views

Setting preference summary

I'm taking and Android course and I would like to refactor the code for one of the exercises. The complete solution done by tutors is here. When I was doing this exercise by myself I was annoyed by ...
2
votes
0answers
37 views

Counting items that have a matching attribute

Here is my code which is going to through multiple for loops to get the matching product attribute. I have single product with attributes trying to find out the ...
2
votes
0answers
50 views

Modeling a control polygon for a piecewise spline curve

Aim I'm modeling a control polygon for a piecewise spline curve. Each sub-spline is defined by a location the spline must pass through, as well as a forward tangent, and a backwards tangent. The ...
2
votes
0answers
37 views

Class which encapsulates related socket streams

I have a class which encapsulates stream related objects, and I have provided the method API for doing basic manipulation on the stream read/write/close, but is this a good approach? The only benefit ...
2
votes
0answers
370 views

Concurrent ObjectPool using ConcurrentLinkedQueue

Main ObjectPool Class: It uses atomic operations and a concurrent linked queue to achieve the best performance compared to Apache commons pool. I want to make sure there are no concurrency issues even ...
2
votes
0answers
762 views

Inserting large datasets into SQLite db becomes very slow over time

I'm using the program below to insert values from very large .csv files (~2.5 million lines) into an SQLite DB. It starts very fast, but begins to slow over time, before eventually hanging ...
2
votes
0answers
3k views

Sending ACK/NACK for packets

The code is working perfectly. I'm little bit sure this is a packet what I am sending from client to server in streams. Is this packet? Am I sending in a right way? Another thing is that I am sending ...
2
votes
0answers
564 views

JSON schema using Java objects

I have this JSON schema: ...
2
votes
0answers
4k views

Simple API testing framework for testing of SOAP xml requests

I have a need to try to automate the testing of a large Web Service with an XML API interface. The framework takes the form of a Mavenised Java project. The usual maxims apply: must be highly ...
2
votes
0answers
44 views

PopupMenu implementation that hacks inflating a @MenuRes

Summary Usage will ask for a Context and a @MenuRes and then use the ...
2
votes
0answers
2k views

Download a PDF and submit it as a print job

I have following Java code, which is to print PDF, but in a busy location this code is taking about 20 to 30 second delay before submitting to the hardware. get the PDF file via the network download ...
2
votes
0answers
116 views

Hangman — with a surfeit of for loops

How can I improve this code so I do not use so many for loops in this? ...
2
votes
0answers
70 views

Refactoring App launch sequence using reactive programming

In the SplashActivity of my Android Application, the following sequence of events occur: Check if Google Play Services is installed If Google Play Services are ...
2
votes
0answers
8k views

Send a volley request in the background every 10 seconds to a server

I created a class called HomeService that extends the android.app.Service. I then declared and implemented a class called BackgroundService which extends Thread. In the run method of the class I call ...
2
votes
0answers
151 views

Implementing FusedLocationProvider for more than one Activity in Android

I am trying to implement Google Maps in Android. I am also trying to learn different design patterns. I want to use location in more than one Activity hence I have used a class named 'GoogleLocation' ...
2
votes
0answers
50 views

Java interface to C library - Refactoring to singleton usage

I am currently writing a Java interface to a C library. It mostly just delegates calls and adds a object oriented layer on top of it to make integration into a regular Java program more natural. The ...
2
votes
0answers
132 views

Safest Connection pool in Java

I have read the code reviews on this website: this one and this one So creating the pool in itself might not be that difficult, I'm more worried about the client closing the connection or the ...
2
votes
0answers
8k views

Switching between two JavaFX stages

Basically, I made a function which switches between stages (see the Switch class below). The way I call it is seen in the Controller below. I wanted to ask if this ...
2
votes
0answers
2k views

Prim's MST Java implementation

Can someone review this code, just have look if it's logically correct or If you may point me to a more simple and minimalist program ...
2
votes
0answers
202 views

Checking authentication status by looking for a cookie

I'm an Android newbie. I have this function in my code: ...
2
votes
0answers
2k views

Handling Firebase's asynchronous calls Android

I have written a helper class to manage callbacks from Firebase's asynchronous calls. Can this be implemented in a better way? ...
2
votes
0answers
1k views

HashMap with binary search tree for chaining

My friend was asked to implement a hashtable with a binary search tree. I tried practicing it myself, and it turned out to be very verbose. I need suggestions to clean this up! ...

1
3 4
5
6 7
14