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.

Filter by
Sorted by
Tagged with
2
votes
2answers
45 views

handle null in Comparator class

I have a class LoanAccount that contains an attributes creationDate and loanAmount. I ...
13
votes
2answers
484 views

Get the encrypted payload from an unencrypted wrapper PDF document

This is code, written by our dev team, and SonarQube tells me that the Cognitive Complexity is too high: 21, and the current (default, out of the box) metric limit is 15. I've had a go at reducing the ...
0
votes
1answer
61 views

How to make below code more readable and efficient? [on hold]

Code below reads static variables from ProductConfiguration class. Functions setAccess and ...
-2
votes
0answers
38 views

Java: Store temperature values in just one byte [on hold]

I have got the following code to pack and unpack temperature values into one byte and from one byte: ...
5
votes
1answer
264 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 ...
1
vote
0answers
12 views

Android: Fill a spinner data from the server dynamically

I'm new to android. How do you fill a spinner from the server's data dynamically. This is my Spinner layout: ...
2
votes
1answer
135 views

check for null before or after casting

I have a list of BasicDBObject that I fetch from my database. This is basically a JSON document converted into a java Object. Let's assume that we have a ...
7
votes
2answers
135 views

Heights of Cats

I have an assignment to solve this problem. However, I have exceeded the time limit required, can anyone suggest where to improve my code? Cats like to sit in high places. It is not uncommon to see ...
2
votes
1answer
72 views

transform list to array

Q: Write a method that transforms a list into an array (don't use collections or already implemented methods in lists, make your own method) I've come with this solution: ...
5
votes
1answer
94 views

Plain-text file encryption and decryption

I have created an Encryption and Decryption Algorithm that encrypts plain text using a given cipher and also decrypts it back to the original notation. It works great. This was my code for a coding ...
3
votes
0answers
30 views

Concurrency control between a non-blocking and a blocking methods

In this program, there is a list of Holders that is managed by a singleton class. Each of the Holders keeps a copy of the ...
-2
votes
0answers
12 views

Suggestions on removing duplicate CallableStatement boilerplate and a better design [on hold]

We have many stored procedures and functions that we call on our DB and the setup for each call in our data access layer is really verbose with setting the inputs and registering the output etc... Is ...
3
votes
1answer
52 views

LeetCode Reverse Words in a String without using any java library

The following problem is from LeetCode: Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order. ...
0
votes
0answers
19 views

Springboot/hibernate queries result optimization

I am developing a Springboot application, and my requirements are the following: I have 8 sql queries, that I have to run in parallel and that return a single result. My entities using this sql ...
1
vote
0answers
17 views

Akka FSM: Traffic Light Implementation

Recently I did an exercise to understand Akka FSM. I implemented a Traffic light system with Akka FSM which changes its state every 30 seconds. My code is like: ...
5
votes
3answers
708 views

reverse a list of generic type

Q: Given a list, reverse the order of its elements (don't use collections). Here is my solution: ...
1
vote
1answer
78 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
0answers
12 views

Load data from server to populate in spinner

I'm learning ROS and I'm trying to populate data from my server to spinner. my JSON is: ...
3
votes
1answer
80 views

Find two numbers that add up to target

I am trying to solve this problem: Given an array of integers, return indices of the two numbers such that they add up to a specific target. and this is my implementation: ...
3
votes
0answers
46 views

Getting a list of waypoints assuming that there is a map [on hold]

I'm a beginner learning ROS. I'm developing an android application that will control my robot and that includes getting the list of waypoints to display it to my spinner. How do you get the list of ...
3
votes
0answers
50 views

Rest Api with generic crud operations

I am learning how to create a rest api in which I've decided to use generic for crud operation. I am attaching the code which I have written so far. Please have a look. Thanks for the review in ...
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: ...
1
vote
0answers
27 views

Functions to obfuscate and deobfuscate String. Am I missing out any edge cases?

I have 2 functions, which are going to hide/ unhide the multiple languages plain text. Security is not a major concern. The objectives are Just want to find a way to hide multiple ...
3
votes
1answer
37 views

Validate URL with Regex and java.net.URL

I'm writing a URL validator. Firstly, it checks for special characters in the input. Secondly, it adds 'http://' and checks for validity. ...
1
vote
0answers
27 views

Stochastic gradient descent - backpropagation over mini-batches in one go

I have been working through a tutorial on neural networks. I have then been translating the code to java, to help improve my understanding of what the code is doing. The book mentions a way of ...
5
votes
2answers
170 views

Automate tasks with Lambdas

Can I use #define fori(s,n) for(int i=s;i<=n;i++) in Java? And of course, Java doesn't have precompiler so we cannot do that in java. So I thought we can do ...
-4
votes
0answers
27 views

parse json file recursively with JAVA [closed]

I have a json file that contains chapters which contain chapters and sub chapters .... it is not always the same number of chapters and sub chapters: For example ...
-4
votes
0answers
29 views

Java For Arraylist [closed]

Good morning guys, I need help. I search the Internet for a way to read two values from the keyboard n and m then save the i values to an Arraylist. Subsequently, I intend to scan the arraylist for ...
2
votes
1answer
38 views

Trading System with Akka

Recently I did an exercise to understand Akka. I implemented a trading system with Akka to process orders with Actors. My code is like: Order: Immutable class with acts as the messages in the ...
51
votes
5answers
243k views

Removing elements on a List while iterating through it

I needed a way to remove elements on a List while iterating through it. Supposedly something like this (illegal code): ...
4
votes
1answer
69 views

Comparing game tree search AI algorithms in Java

(The entire project lives here.) I have a program that benchmarks three game tree search algorithms: Minimax, Alpha-beta pruning, Alpha-beta pruning with move ordering. So here is my code: ...
6
votes
1answer
781 views

Finite State Machine supporting shortest path transitions

In our automated test framework, written in Java 8, there are different entities representing test data, having different states and transitions between them. To model this behavior, I started to ...
1
vote
2answers
100 views

Merge k sorted lists in Java

I hava a question similiar with mege in Python but I am trying to write Java code. Here is my code: The input is: The first line - a number of arrays (k); Each next line - the first number is the ...
3
votes
1answer
51 views

Java solution to CodeChef “Surgical Strikes” challenge

I've just recently completed this programming "challenge" called surgical strikes: \$N\$ Indian Air Force fighter planes are located in different bases across the country. Each airbase is described ...
0
votes
0answers
27 views

Avoiding `@SuppressWarnings(“unchecked”)` [closed]

I have the following code but in the method I needed to put in @SuppressWarnings("unchecked") to suppress this warning Warning:(49, 45) Unchecked method '...
-1
votes
0answers
33 views

Computational Chemistry - is there a bug with my code? [closed]

Hi Code Review Stack Exchange! I had originally posted this on Chemistry StackExchange, but they suggested I try here instead. Anyways: I was checking my RHF code and found a couple of bugs (which ...
4
votes
1answer
53 views

A thread that can be interrupted before starting

As per the Java documentation: Interrupting a thread that is not alive need not have any effect. Particularly, interrupting a thread between the call to start() and the invocation of run() has no ...
4
votes
0answers
88 views

Minimum amount of edges that needs to be traversed to visit all vertices… or something like that

So I have this problem, where I'm given m connections over n vertices. The vertices are labeled ...
2
votes
0answers
228 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 ...
6
votes
1answer
1k views

Simple Java game of a rocket ship flying in space

This is just some code I wrote for a hobby really, I'm trying to get better so please tell me all the bad/weird stuff I've done. Thanks for helping! I've left a little boring code out but most of it ...
5
votes
2answers
79 views

Edit file name method - run time complexity

I wrote a function in Java that edit file name, and replace each space char into dash char. Currently I iterate all the files in a specific directory, iterate in each file name, creating a new file ...
-1
votes
1answer
81 views

Some kind of multiple singleton [closed]

I need several singletons and I wanted them to be easily accessible via auto-complete, so I made this thing. ...
1
vote
0answers
60 views

Recursion to dynamic programming [closed]

I was trying to solve a problem on de-arrangements (Number of partial derangement such that exactly prime number discs are found away from their natural positions? (Any number of non-prime K disks ...
2
votes
1answer
40 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 ...
-3
votes
0answers
18 views

Processing language to draw scatter plot [closed]

I am trying to plot the following data using the columns, ID, ACT_m and GPA into the scatter plot, but I don't see any data in my plot. Thank you so much for your time. ...
2
votes
0answers
48 views

Modelling a Call Center in Java (multithreading approach)

I wanted to give a shot to Modelling a Call Center from Cracking the Coding Interview. The problem statement is as follows: You have a call center with three levels of employees: Respondent, ...
6
votes
0answers
537 views

Pseudo-parallel depth-first search

I'm writing a small program that generates a file containing an adjancency matrix, it then reads from that file, constructs a graph and does something like a parallel depth-first search (dfs) on it. ...
2
votes
1answer
150 views

Project Euler #16 - Sum of all digits of 2^1000

2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. What is the sum of the digits of the number 2^1000? ...
5
votes
1answer
107 views

Java program to encrypt/decrypt text

I am working on adding a GUI to the project that I was making in some course. I am curious if the layout looks good, if there variables and methods are shared properly between particular classes, if ...