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.

693 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
1
vote
0answers
188 views

Using HttpServltRequest to store a Request Scope map cache

I'm playing with CDI interceptors and thought use a interceptor to cache some methods in a managed bean: ...
1
vote
0answers
984 views

Testing with multiple input datasets and expectations

I wanted to make 3 test suites where each would run a test class with a specific input. I figured that in order to do this I could: Make an abstract test suite with all the variable parts (...
1
vote
0answers
690 views

Parsing PHP-style nested query string parameters

I searched all over for a query string parser that could handle nested parameter names ala parse_str in PHP. I was unable to find anything, so this is what I've ...
1
vote
0answers
222 views

Using the Template Design Pattern to reduce code duplication between two algorithms

I have made a Skyline query solver which for now can solve the query with two different algorithms. The first is Block-nested loop (BNL) and the second is Sort filter skyline (SFS). The two are ...
1
vote
0answers
530 views

Is this implementation of the ECIES cipher correct?

I downloaded source code of cryptosms and implemented the ECIES cipher in my work for Java mobile. I doubt validity of this step (full code of my method is below): ...
1
vote
0answers
77 views

Enhancement to Trezor library for Android

I'm only asking because I'm new and don't know enough to have a concrete question. Did I do this correctly? I worked on this until the code performed as expected, but I don't think I'm done. In ...
0
votes
1answer
18 views

Simple Connect Four Game With GUI added

I am trying to improve my coding skills in Java by taking existing code, studying it, and adding on to it. In this code example, I took code from Connect Four game in Java and edited it. The most ...
0
votes
0answers
19 views

Process Extension for Oracle Agile Product Lifecycle Management to update product number field with value from the description field

We are digging into a performance issue with our Agile system. This Process Extension (PX) is used to update the product number field with whatever is in the description field. The product number ...
0
votes
0answers
18 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 ...
0
votes
0answers
24 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? ...
0
votes
1answer
28 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 ...
0
votes
0answers
21 views

Authentication and auto renewal of an API Token

Following is an https call to retrieve the token, once it's retrieved, it's cached. Callers call the addTokenObserver method that sets a timer based on the token ...
0
votes
0answers
113 views

gRPC Java client with TLS Mutual authentication

I'm not a Java developer but I'm trying to put together a quick start snippet to help Java users consume our service using code generated from .proto service definitions. I've cobbled together some ...
0
votes
0answers
81 views

Brute-force cracker for hashed passwords

I want to crack the password hash. This is my data which I want to display the username and the passwords. This is my code ...
0
votes
0answers
118 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 ...
0
votes
0answers
18 views

Salesforce Live Agent Chat Client Code in Java

I have to use SwingWorker for the first time today, and I'm pretty pleased with the result. Would you mind helping check that I used it correctly? My class starts ...
0
votes
0answers
34 views

Templated JSON parsing methods that work with an element or elements array

Consider the following two Java methods. The first takes a JSON string representing one element, the second representing multiple elements. gson.fromJson() can be ...
0
votes
0answers
56 views

Please check my HTTPServlet route parsing extension for quality

Please critique my codebase https://github.com/davidbyng/acme-simple-servlet-extension ...
0
votes
0answers
78 views

Find the smallest subarray with sum greater than a given value

Given some array, find the smallest subarray with a sum that is greater than a value given. So for instance, given this array: {1, -4, -45, 6, 0, 19, 16, 17} ...
0
votes
0answers
47 views

Spring Component Thread Safe

Recently I refactored an application to start using spring, and after some research, I found out that @Component is not thread safe. The class is this: (It's a converter from xlsx to json string) <...
0
votes
0answers
267 views

Simple card game with updating GUI

I have coded a simple card game that updates the GUI each second and contains many nodes in game which are used to display game events and animation. People who have tried the game said that their ...
0
votes
0answers
52 views

Android - Notification service to handle background notification

PREMISE: I have zero knowledge of Java and Android development. I put this together in a couple of weeks. The code works. But I look forward to some feedback and to know how I can improve it. ...
0
votes
0answers
41 views

Inter Thread communication between n thread

The following program takes 3 integer inputs(noOfThreadToBeCreate,fromNo,toNo) and print the Consecutive numbers based on the range using different threads e.g (Thread 1 - Print 1, Thread 2 - print 2, ...
0
votes
1answer
67 views

Class to fill model objects with data from the database

This is a helper class that helps fill models with data obtained from the database. ...
0
votes
0answers
295 views

Join (custom) query in Spring Data JPA

I'm trying to make a REST service using Spring Boot and Spring Data. I have written a query using join and have achieved the required o/p but I'm curious to know if ...
0
votes
1answer
83 views

Efficiently compare 2 lists to replace and order

I have 2 list containing some Objects (Fruit class). I am using a 3rd list to add these elements based on following 2 criteria. I want every object in the 1st list added to 3rd list. But if I have a ...
0
votes
0answers
48 views

JNI: porting a semaphore data type to Windows

I have this JNI code to review. The demo driver + irrelevant porting code is here. semaphore_impl.h: ...
0
votes
0answers
59 views

An iterator returning all possible permutations of a list in Java - follow-up

(See the previous and initial iteration.) My main attempt here was to get rid of monolithic code and split the implementation into smaller methods when applicable and do more extensive commenting. ...
0
votes
1answer
66 views

Graph Implementation in Java using Set and Map

There is a Graph implementation. I'm using Set to store unique Edges and Map to store Vertices and their associated edges. Assume Vertex and Edge class has been defined somewhere else implementing ...
0
votes
1answer
92 views

Handling response from another microservice

I have this piece of code placed in ESI class. There is switch statement nested in a try-catch block and it feels simply wrong ...
0
votes
0answers
22 views

Processing object writes to external datastore in parallel using ForkJoinPool and list streams

I have the following code. I wanted to see if you thought this was a good way to go about processing an array of objects in parallel using a ForkJoinPool and array streams. This is just a sample, in ...
0
votes
0answers
20 views

Untangling a data class where annotations from different frameworks mix

The framework mix problem I'm using two frameworks -- PingIdentity's SCIM 2 SDK, which uses Jackson, and Spring LDAP -- to deserialise a SCIM resource (i.e. JSON) to a Java object then write it to an ...
0
votes
0answers
44 views

Optimize the file content comparison

Program to compare if files within two directories are having same content I followed the approach of getting the list of files under two directories recursively and store it in different list with ...
0
votes
1answer
2k views

Java MongoDB client as a singleton

Is below code a valid Singleton design pattern for Mongodb in Java? Please suggest any improvements. ...
0
votes
1answer
80 views

Fluent interface for Logger

I was trying to wrap a Logback logger in order to provide some handy methods and already defined default keys of the logged json output and I came up with something like this. Do you spot any ...
0
votes
1answer
188 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: ...
0
votes
1answer
87 views

Finding the mean using RxJava

I'm learning RxJava and this is what I attempted to find the mean of 'n' transactions. ...
0
votes
1answer
44 views

Handling a response in a @Controller

I have a simple spring controller which takes a @ModelAtrribute object and registers an employee. If it is a success, I forward it to a success, else an error page, ...
0
votes
1answer
6k views

Detect that a class is marked by a custom annotation in Spring

I would like to enable application behaviour based on the presence of a custom annotation that marks the configuration class (normally named something like ...
-1
votes
1answer
91 views

Reverse String in Java

I've been revamping on my coding puzzles practices. What is the complexity (both time and space) for this method: ...
-1
votes
1answer
1k views

Maximum Difference in an Array

Maintain a minimum and max difference as we scan the input array. ...
-1
votes
1answer
707 views

Reading bytes from file to compute its SHA256 hash

I need to get text hash (sha 256), so I need to convert file to its type representation. Is this a fast way to get a byte representation of a file? ...
-1
votes
1answer
66 views

Some kind of multiple singleton

I need several singleton, I wanted them to be easily accessible via auto-complete, so I made this thing. ...