The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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
3
votes
0answers
50 views

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

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 ...
2
votes
2answers
210 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
32 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
42 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
36 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 ...
2
votes
1answer
44 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
245k 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
71 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
789 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
112 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
63 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 ...
4
votes
1answer
56 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
229 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
2k 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
81 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
vote
0answers
62 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 ...
6
votes
0answers
551 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
153 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? ...
4
votes
1answer
110 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 ...
0
votes
2answers
72 views

Project Euler problem #19: counting months that began on Sundays

You are given the following information, but you may prefer to do some research for yourself. 1 Jan 1900 was a Monday. Thirty days has September, April, June and November. All the rest ...
2
votes
1answer
54 views

Creating many Android cardViews with different background colors [closed]

I have cardView in my android app with three child component. I set the background color for each components. Based on card INDEX I reset the background colors individually. If it's just one cardView ...
1
vote
0answers
59 views

Single-player obstacle-avoidance space game

I was wondering what I could do to improve the gameplay of this game, as well as the graphics. I would like to use LWJGL, but the rendering library isn't important. I just need to find out ...
5
votes
0answers
70 views

Mahjong hand completeness checking algorithm

As a summer project, I have been working on a small-scale, console-based version of Mahjong (the Rummy-like hand completion game, and not the solitaire version). While having prior knowledge of the ...
3
votes
3answers
61 views

Copy a FileInputStream to a file, either as text or as a string of bytes

I have written a small program that reads input from a text file and then writes this output to a text file. The method contains a switch which decides whether to output to the file as text or as a ...
3
votes
1answer
66 views

Aggregation on list forEach and maps improvals

I am using a function in a SpringBoot @RestController, with Lombok This function is an intermediate result that permit me to do an aggregation between two classes. This 2 classes are: ...
1
vote
1answer
53 views

Graph implementation for solving graph problems (java)

I've currently started solving some competitive programming Graph questions. But Started using adjacency list as HashMap<Integer,ArrayList<Integer>> list...
3
votes
1answer
50 views

Chain of CompletableFutures in Java

I am new to this CompletableFuture function in Java. I have the following code below that works fine but looks quite messy IMHO. ...
5
votes
2answers
178 views

Process multiple request from different threads in batches on one processing thread

So I have a system that uses multiple threads to process data. These data could be processed individually but it would be better to process them in batches. Lets assume we have a class ...
4
votes
1answer
99 views

Computing divisibility and multiplication

Please check my Java program to see if I use the global variables, nested loops and two functions with parameters correctly. I would also like any suggestions to improve my program. ...
3
votes
0answers
76 views

Solutions for counting trapped water on islands

There are some exercises about islands and water. I have seen other solutions in Java, but they are developed in procedural style in one-two methods. I tried to develop an object-oriented solution ...
2
votes
1answer
86 views

Simple UDP server (java)

I write kind of UDP server. It should serves about 50 messages per second. I would like a review about the general code 'quality' and logic. The server uses the same socket for sending and receiving ...
8
votes
3answers
232 views

Find the smallest positive integer that is absent from a given array

I made the acquaintance of big-O a couple of weeks ago and am trying to get to grips with it, but although there's a lot of material out there about calculating time complexity, I can't seem to find ...
6
votes
2answers
95 views

Printing the max of groups of three random ints

I'm trying to teach myself streaming and lambda expressions. Here's the scenario: I have a collection of 10 Thing objects each containing an int[] of 3 random number. I've written code to print out ...
12
votes
5answers
3k views

Stack class in Java 8

I have a exercise where I have to write a Stack class with the push and pop methods. The code compiles and works as it should. Are there better practices to use in my code? Is there something I should ...
2
votes
1answer
46 views

Bookscraper - SpringBoot app to scrape data from online bookstores

BookstoreScraper is application based on Spring Boot. It allows to scrape data from two biggest polish online bookstores - EMPIK and MERLIN. You can scrap books within 3 options: bestsellers most ...
4
votes
1answer
4k views

Android RecyclerView Adapter: Passing normal clicks and menu clicks over the same activity

I am unsure about my approach here. As you can see, I want to send normal clicks and 2 different menu item clicks back to the underlying activity over an interface. Now I wonder if it is bad practice ...
4
votes
0answers
90 views

Biometric data representation in Java

This code represents biometric data averaged over a 1min period, beginning at the given UTC time. Please review my code: ...
2
votes
0answers
72 views

Iterating through every permutation of every subset [closed]

I have this code which I use to iterate through every permutation of every subset in an array witch holds integers. One big problem is the efficiency of course, another problem is the fact that if I ...
-1
votes
1answer
1k views

Maximum Difference in an Array [closed]

Maintain a minimum and max difference as we scan the input array. ...
2
votes
0answers
95 views

Classes for shapes and development [closed]

Task You should create an abstract Shape class that contains the stuff that would be similar across all shapes, and change Line and Rectangle so that they extend Shape. Then, in the DrawingModel ...
2
votes
0answers
40 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 ...
6
votes
1answer
207 views

java - Basic snake game

This is a snake game I made, Note: at this point, I would like to hear any thoughts/ reviews about it. Thank you Game class: ...
2
votes
1answer
42 views

Printing all the combination of indexes for 2 sum exact outcome

Can somebody review the code and provide suggestions on where I can improve on the code like use of better data structure etc. Input: {1,7,2,8,3,6}, 9 Output: [0, 3] [1, 2] [4, 5] ...
2
votes
2answers
77 views

Production-ready comparison between byte-array and ByteBuffer

I want to compare the performance difference between using byte[] and ByteBuffer in Java, which approach I should use in my ...
6
votes
1answer
4k views

Named placeholders filling and extraction in Java

Here's utility class that is capable of filling strings with placeholders and extract values of placeholders from filled strings. Placeholders are enclosed in % ...
4
votes
3answers
103 views

Count the occurrence of each letter in a file in Java

This program prompts the user to enter a file name and displays the occurrences of each letter in the file. Is there a simpler and more efficient way to do this? Please, help me figure this out. ...
2
votes
2answers
104 views

Yet another Minesweeper implementation (in Java)

Here is my take on Minesweeper in Java. Any feedback is welcome regarding readability, design or anything really. Cell.java ...
8
votes
1answer
152 views

An array with \$O(\log\ n)\$ time complexity for all operations

Does this exist already? It's an array (=variable-size list with integer indices) where add/remove/set and get all take \$O(\log\ n)\$ time. I couldn't find this anywhere, so I made up the name "Log-...