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.

684 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
2
votes
0answers
487 views

Flattening a map into a list of records

In my everyday work I'm trying to move away from traditional iterating over collections to a more Java 8 streams-like behavior. I'm currently working on a project where I have a collection defined as: ...
2
votes
0answers
65 views

Scala code that loops through Java annotations decorating Scala classes

I have code written in Scala that reads annotations decorating other Scala classes. These annotations are written in Java. The sticking point is that annotations don't allow advanced data structures, ...
2
votes
0answers
289 views

Java Crypto library number of padding bytes using PKCS5Padding

I have implemented AES encryption in Java using the following function. What puzzles me is the number of padding bytes added using the PKCS5Padding method. For example, when calling the following ...
2
votes
0answers
720 views

Handling single items using MVVM and Android Architecture Library

What I have done so far Since I would like to rebuild a project using mvvm-pattern with the following requirements to use dagger 2 for di, RXJava for reactive, retrofit for webservices, greendao and ...
2
votes
0answers
231 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
48 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
244 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
82 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
3k 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
91 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
58 views

Two similar methods to re-create objects and emit events

I have these two methods basically doing the same thing: ...
2
votes
0answers
159 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
78 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
238 views

Collision detection method

I think everyone has some code they are embarrassed and not proud of and today I have decided to show mine. I'm not sure how to go about making this more efficient, at the time I was just happy it did ...
2
votes
0answers
64 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
31 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
36 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
242 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
359 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
129 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
448 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
414 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
1k views

BlockingQueue with unique elements in Java

This answer on Stack Overflow includes an implementation for a Java BlockingQueue with unique elements. I changed it and included it in a project: ...
2
votes
0answers
44 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
78 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
99 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
57 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
91 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
95 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
102 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
799 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
347 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
42 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
323 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
40 views

Symmetric decryption with javax.crypto

I'm trying to determine if this code could be a memory hog with huge files. Can anyone tell me if there is anything I can do to make this more memory efficient, or is this how java.crypto works? <...
2
votes
2answers
208 views

URL decode a string but log an error after second exception

I have a method which does URL decoding on the string value passed along with using Charset: ...
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
471 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
41 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
89 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
69 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
7k 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
145 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
127 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 ...