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.

674 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
3
votes
0answers
50 views

LinkedList of Nodes at each level - optimalization

That's already known problem: to return an array of linked lists that contain values of elements at each level. Eg for tree with depth n there should be n linked lists. I wrote the solution: ...
3
votes
0answers
369 views

NBP currency application

I have a small program in Java with GUI, which is showing NBP currency data in specified tabs. It downloads data from www.nbp.pl using XML format and saving it into Apache Derby database using ...
3
votes
0answers
186 views

Animation for android ImageViews acting as game pieces

My question is about how to achieve a well-performing animation for a set of ImageViews, so that the foreground fades away and the background stays the same. ...
3
votes
0answers
257 views

Manhattan/Tchebyshev Distance - O(n^3) Solution

This is a variant of the Manhattan Distance problem. The input is a 2D matrix of boolean with the true cells representing location of an ATMs(or anything for that ...
3
votes
0answers
660 views

Comparing linear time strongly connected component algorithms in Java

So I have implemented three linear time (\$\mathcal{O}(V + E)\$) algorithms for finding strongly connected components of a (directed) graph. A strongly connected component is just a maximal subset of ...
3
votes
0answers
98 views

Getting contacts from phone is taking too much time

I am working on an instant chat messaging application. I am getting contacts from phone and displayed them in list view of an activity, but it is taking 25-30 seconds using the following code: 1. On ...
3
votes
0answers
628 views

Shape inheritance hierarchy

I have managed to build an inheritance hierarchy for shape class object and I am wondering if there is a better solution to combine the following 2 hierarchies. To begin, I have a 4 shapes classes ...
3
votes
0answers
766 views

Expression parser using Shunting-yard algorithm

I've been working on a expression parser which will be part of another project (some sort of DSL). This parser basically uses the Shunting-yard algorithm, except for the case of parenthesis: here it ...
3
votes
0answers
147 views

An iterator returning all possible solutions to n-queen problem in Java

(See the next iteration.) Given a positive integer \$n\$, I have an iterator that returns all possible solutions to \$n\$-queens problem one by one: QueenIterableV1.java: ...
3
votes
0answers
68 views

Adaptive counting sort for integer arrays in Java - follow-up

I have refactored this. Once again, the running time can be anything between \$\Omega(n)\$ and \$\mathcal{O}(n^2)\$, yet it adapts to "smoothness" of the input array. ...
3
votes
0answers
123 views

Implementing a long-running entity lock

Requirement I have an entity named ImportData which can be processed once in order to extract data from a file fed to the application. I need to make sure that, ...
3
votes
0answers
301 views

JSP evaluation of Parameters

I was never really sure what the cleanest way would be to use JSP-Pages for receiving sent parameters. It's common knowledge to use as little JSP as possible - yet as some things have to be done there,...
3
votes
0answers
352 views

Stylishly saving source

Simple tool to save a web page's source. A result of trying to learn and apply an MVC approach. The FXML is generated via Scene Builder, but included for completion. I welcome any general feedback on ...
3
votes
0answers
997 views

Uploading an image to Imgur

I have made a class what uploads an image to imgur (a service with an API where you can upload images). And then I read the response of the API what contains the URL and the HTTP status code (200 if ...
3
votes
0answers
68 views

Change an identifier in a .csv file, based on another .csv file

I have only dabbled in Java before (my previous experience being mostly with PHP and JavaScript) but a request come through for a small application that seemed like a good chance to get some ...
3
votes
0answers
2k views

Brute force shortest path in Java

I had to ask myself a couple years ago: before Edsger Dijkstra invented his famous shortest path algorithm, how brute force approach would seem. Below is my version. It's super slow, but I find it ...
3
votes
0answers
539 views

Using combinations of OR and AND filters with RxJava

I'm trying to work out a way to create a combination of OR and AND filters in RxJava. Here's what I've done so far: ...
3
votes
0answers
267 views

Print the nodes of binary tree column-wise, using recursion and iteration

I am trying to code for both recursive and iterative approach to a problem. Below is a recursive code to print the nodes of binarytree column wise. Basically I have count of root as 0 and if I move ...
3
votes
0answers
2k views

Netty connecting to multiple servers

I am using netty to connect to multiple servers, query for an item, and aggregate the results in my Client. The code below works, but I am unsure if it is the best way of achieving my goal. Also, I'm ...
3
votes
0answers
1k views

Map Events From calendar provider to dates in gridview

I working on a calendar app on Android, using roomaorama, which is nice. I am fetching all the events from Events table in Calendar provider once which seems not good performance wise. The library ...
3
votes
0answers
3k views

Authorization token from servlet filter stores user name

I'm having some difficulty with servlet and filter lifecycles. The intention here is to use the front controller pattern with a simple login; authentication is accomplished with the filter. Am I ...
3
votes
0answers
2k views

Bidirectional Edmonds-Karp algorithm in Java

The Edmonds-Karp algorithm relies on breadth-first search in order to find an augmenting path in the residual flow network. This version of the algorithm uses bidirectional breadth-first search in ...
3
votes
0answers
274 views

Kruskal's algorithm in Java - follow-up

The previous and initial iteration at Kruskal's algorithm in Java Now what I did is remove the fields and let the actual Kruskal-routine create the required data structures in the local scope, ...
3
votes
0answers
460 views

Rhino helper class to support ECMA-262 regular expressions

This is a sample class using Rhino (1.7R4). I need it because in the context of JSON Schema, regexes should be ECMA 262. One requirement is that it is thread safe, and it is. But I'm not sure I ...
3
votes
1answer
175 views

Java-based Game Of Life

I've recently had a go at programming a Conway's Game of Life simulation in Java, and I was wondering if anyone could provide some input on how it could be improved. I'm mainly concerned with how to ...
2
votes
2answers
41 views

Performance Enhancement of A Star Path Finder algorithm with 1024 multidimentional array

I have the below code for a A* pathfinder, however it is taking upwards of 10 minutes to find a solution using a simple 1024 x 1024 array. I had to comment out ...
2
votes
0answers
40 views

Is it bad practice to update Graphics in Swing outside of paintComponent like this?

I'm currently implementing a Minesweeper clone in Java using Swing. Rather than updating the tiles like so ...
2
votes
0answers
54 views

Fibonacci Heap Implementation In Java

From my repository. This is my first time implementing a Fibonacci Heap, and since it's pretty complicated (at least to me), I would like to check if it is all correct. ...
2
votes
0answers
115 views

My Java matrix multiply code single thread faster than multithreading, any mistakes?

I'm implementing the matrix multiply function using Java's multithreading. Below is my code: So I first tried the normal single threaded approach, then tried the ExecutorService approach, I don't know ...
2
votes
0answers
27 views

Separation of database and network calls

I have a API and the corresponding service method is like this: ...
2
votes
0answers
46 views

Why does my Clojure implementation of Conway's Game of Life run so much slower than my Java implementation?

I'm trying to learn Clojure coming from a Java background. I have written a simple implementation of Conway's game of life in both Clojure and Java, trying to keep the overall structure of the code as ...
2
votes
0answers
43 views

Spring, Kafka and Mongo how to create a RestController

I'm learning how to use Kafka, I've never used something similar in the past. In my job I was required to create a POC using it and integrate it to Spring Boot and save information on MongoDB (because ...
2
votes
0answers
61 views

JWT authentication system login through API

This is my first time writing an authentication system. Here's how it works, first client needs to send credential within authorization header like { Authorization : 'Basic ' + credential } through ...
2
votes
0answers
53 views

RemoteFile in Java

(Also, see the next iteration.) I have this tiny class for downloading files from internet: ...
2
votes
0answers
58 views

Parsing a Graph To Convert It Into Adjacency Lists And CSR And Then Make Connection Queries Using Bidirectional BFS

I was assigned an university project where I had to parse directed graph files coming from SNAP and then convert them into CSR (Compressed Sparse Row) format. Then the client must have the ability to ...
2
votes
0answers
56 views

Construction of external sorts from comparison ones

Here's an example how to construct an external sorting algorithm from the Quicksort. The method may be applicable to other known internal comparison sort algorithms. I have checked that it shows N*...
2
votes
0answers
52 views

Kadanes algorithm implementation

I just wanted to ask the following question. I have solved Kadanes algorithm using the recursive approach as shown below. The implementation works ...
2
votes
0answers
68 views

Bellman-Ford Implementation in Scala/Java

I think the part to get shortest path from the cost table got pretty messy. Also can use some tips on how to avoid the extra O(V+E) work checking all edges from source to dest after getting the cost ...
2
votes
0answers
78 views

SharedPreferences singleton wrapper

I was wondering wether my implementation of the PreferenceService below is thread safe or could cause memory leaks. Android Studio gives me the warning "Do not place Android context classes in ...
2
votes
0answers
33 views

Library/API: simple springboot / jdbc query builder and ORM

I have been using and developing a simple ORM and query builder library that I have found useful in it's practical application. I am pretty sure there are improvements to be made, and I welcome any ...
2
votes
0answers
42 views

Upload to FTP method for Android that mimics the command line mv

I've created a Java class for Android that connects to a FTP server (using the FTPClient library from commons-net-3.6) and ...
2
votes
0answers
32 views
2
votes
0answers
222 views

Updating UI in Retrofit onResponse

I have an Android project that queries the BART train API. I was curious if updating the UI inside the Retrofit onResponse method is correct or if there is a better way. Below is my code. Also, here ...
2
votes
0answers
106 views

Improving rendering performance of 3D Voxel Game

Improving rendering performance of 3D Voxel Game Technical features added: Perlin Noise Generator 3D Explorable World (You can't break or place blocks) Free camera, you can fly and go through blocks ...
2
votes
0answers
70 views

Faster k-shortest path algorithm in Java

In the \$k\$-shortest path problem, we are searching for (at most) \$k\$ distinct, shortest paths connecting two given terminal nodes. You can see the previous version here. This implementation, ...
2
votes
0answers
416 views

JavaFX lazy loading of images in TableView

This code is based off https://stackoverflow.com/questions/25711103/javafx-combobox-lazy-loading-images but modified to work with a TableCell Firstly, the model object should have an observable ...
2
votes
0answers
79 views

Given a resource ID, instantiate, retrieve and localize a Linked Resource for a REST API call

During a question on Stack Overflow, another user had some comments about the way this code works. He had a few choice words for it, including "magic", "ugly contraption", "you're doing things you ...
2
votes
0answers
77 views

Streaming video from PiCamera to Windows using Java and Python

I'm making a robot with Raspberry. My goal is: Code a server on Rasbperry using Python that captures the image from camera and sends data via socket Code a client on PC using Java that reads data ...
2
votes
0answers
75 views

Game involving finding words containing letters from a memorized list

I wrote this Java game where the user memorizes a list, gets given letters and needs to find a word that contains those letters. The player has only a few seconds to enter the word. Example: Program ...
2
votes
0answers
69 views

Breadth-first search in Java: Competitive style - follow-up

I have improved my BFS in Java according to vnp's suggestions. Again, we wish to find shortest paths in directed unweighted graphs using BFS, competitive style (no ...

1 2
3
4 5
14