Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

1
vote
0answers
15 views

Java: Hashing array of strings as Merkle tree in one function

I want to hash array of strings into one hash as shown on scheme on image below. But I do not want to implement some class based merkle tree. It's just a simple function. Is this a good implementation ...
2
votes
2answers
40 views

Minimizing a file path

I have a simple program that "minimizes" a file path. Minimizing simply means replacing unnecessary file entries with entries that mean the same thing: ...
4
votes
1answer
37 views

Java Mandelbrot Set Viewer

I'm writing my own version of a Mandelbrot set generator, with pan and zoom functionality. (There's not yet a color overlay of sets generated with various beta values; the beta value is changed ...
4
votes
0answers
25 views

Sandbox file system for Java

I've recently started work on a hobby project that's basically a sandbox file system written in Java, slightly inspired by PhysicsFS. The point of the project is to separate what files a user can read/...
2
votes
1answer
36 views

Most efficient way to check if user is allowed to update an object

So I have an user which can create his own Locations. I implemented a webservice in order to add and update locations. If the user is not the owner of the location i want to throw an appropriate ...
2
votes
1answer
36 views

Prioritize objects using PriorityQueue and custom comparator in Java

I have a list of objects and a query. I need to rank the objects, based on how do they match the query. A object would match the query 100% if it contains all properties in the query. My program ...
5
votes
1answer
47 views

Try Parse Multiple Types

I am trying to write a method that takes in a String and returns an Object. The catch is I want to parse it to one of a few ...
4
votes
1answer
68 views

Two ways of implementing a combat system

Below is a segment of a game I am writing to stay in practice with my Java. EDIT The class this method is in is the Encounter class. This class just manages the encounter between the player and an ...
-4
votes
0answers
16 views

exception : connection reset in java if the response take more than 5 min from client using httpclient get request [on hold]

Getting Expection connection reset when using httpclient to get response from REST API ,which takes more than 5 minutes for respose. Using java 1.7 when i tried with postman , getting response ...
2
votes
1answer
33 views

Thread-safe stack in Java with fixed capacity

Implement a multi-threaded stack, with freedom to use existing implementations of stack. On top of being thread-safe, it must block (not busy-wait) a pushing thread when stack is full and a ...
5
votes
3answers
82 views

Class for managing a list of scores (game development)

For my game that I'm writing, I need, among other things, a data structure for storing best values. For this purpose, I tried to write a class that meets the most general needs, and yet does not seem ...
2
votes
1answer
46 views

Non-testable class wrapping Java Properties with basic logic

I have written a simple java.util.Properties wrapping class. Unfortunately, in my opinion, it isn't testable at the moment and I don't have any idea how to improve ...
2
votes
1answer
48 views
-1
votes
0answers
12 views

StreamTokenizer [on hold]

In the below code, I am parsing a mathematical expression to translate from infix to postfix and then evaluate. To avoid invalid expressions, I need to check for improper input (i.e. "3++4", "3 3+", ...
2
votes
2answers
49 views

Validating that a Java program has two equal-length arguments

I'm writing a small almost one method Java class for a job application and the advice given was to write it as though it was a piece of commercial software. The ...
7
votes
2answers
870 views

Arranging numbers in a circle such that the sums of neighbors and sums of diametric opposites are prime

I need to create a circle with numbers from 1 to n , however it is necessary to respect some rules: All numbers from 1 to n are used in the circle only once. The sum of two consecutive numbers ...
-1
votes
0answers
23 views

making 1 player pong in java, can't figure out collisions [on hold]

I'm trying to piece things together with things that I have a vague understanding of. If you think there's an easier idea I'm open to suggestions. ...
-2
votes
0answers
18 views

NZEC runtime error in The Next Palindrome problem on SPOJ using JAVA [closed]

So I have just started to solve some problems on SPOJ. I am stuck on the The Next Palindrome problem. I get the desired output on IDE but end up with NZEC on SPOJ. Problem statement A positive ...
2
votes
2answers
57 views

Iterating over a range of integer ranges in Java

My use case is this: RangeDemo.java: ...
7
votes
3answers
113 views

Java Servlet & JSP simple login

I am currently learning Java Servlets and JSP at university. As a little practice I created a project where I want to be able to login into a protected area. Now, I got it working by using a ...
4
votes
3answers
216 views

Swimming Pool Staff/Patron Structure

To work on my Java skills, I decided to create a structure for a pool that I work at. Lifeguards get shifted when their time at their position is up, and managers periodically check the pH level of ...
2
votes
1answer
48 views

library having two types of books

I need to make a project related to a library catalog. It should have following methods relevant to these books: add delete list There are two types of books: novels and poetry. Both types have ...
6
votes
4answers
720 views

Return a String containing only alphabets without spaces

Scenario: Return a String that contains only alphabets without spaces. input = "A man, a plan, a canal: Panama" output = "AmanaplanacanalPanama" Can you please critique my code? ...
6
votes
1answer
84 views

Minimax implementation of tic tac toe

I have the following working tic tac toe program. Someone said it's a convoluted mess and I'm looking for pointers on how to clean it up. ...
0
votes
1answer
53 views

Optimize this code of adapter's overriden method getItemCount() [closed]

How can I optimize this code of adapter's overriden method getItemCount() into simpler form? ...
1
vote
0answers
24 views

Benchmarking k-shortest path algorithms in Java without JMH

In this post, I have the demo driver that benchmarks two \$k\$-shortest path algorithms. The entire GitHub project is here. Next, my code follows: ...
2
votes
0answers
40 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, ...
5
votes
0answers
76 views

Java multithreading many readers one writer implementations

I have a shared data object with writer threads and reader threads. Number of threads can read from the shared data at the same time (in the code getmethod), and ...
3
votes
2answers
97 views

Test if a number is within 2 of a multiple of 10

I have solved this exercise, but it looks really redundant. Is there a built-in function in Java or a cleaner way to caluclate mod of a value + deviation without multiple OR statements? If I had to ...
9
votes
5answers
2k views

Java guess the number

I have just returned to college to finish my associate's in programming. The language my school uses for all of the programming classes is java, so I've been trying to get used to the language. The ...
2
votes
1answer
53 views

Converting hex strings to byte arrays and back to hex strings in Java

Here is my attempt at converting hex strings to byte arrays and converting byte arrays to hex strings: net.coderodde.util.ByteStringConverter ...
6
votes
2answers
74 views

Multiple null Checks or try/catch NullPointerException [closed]

There is A LOT of information online stating that you should NEVER catch a NullPointerException. Generally I agree, but I am wondering about this one case. I have inherited code that requires me to ...
1
vote
2answers
151 views

Turing machine schoolwork

Our teacher doesn't give much feedback on our code itself. Was just looking for some feedback on how I could improve on this. This is the method that tests the string against the Turing machine that ...
1
vote
0answers
48 views

Spring boot for a blog REST API

I'm working on a blog REST API and I would like to get some opinions on where to place the logic for a single operation to filter posts. I have Category and Post in the model package. A category has ...
2
votes
1answer
55 views

Removal of subtrees in tree on condition optimally

I have a small program that removes subtrees of a tree based on following condition: If a subtree consists only of nodes with "rank" 1, remove it. I am using recursive DFS approach. Trees or ...
1
vote
0answers
22 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 ...
1
vote
2answers
65 views

Java lexical analyser

I created a lexical analyser in Java recently, but I don't think the performance is very good. The code works, but when I debugged the program, it take around ~100 milliseconds for only two tokens... ...
0
votes
1answer
42 views

Country, city, and address tables for a customer

I need to create a customer and I have foreign keys for each table. Below is an image displaying the relationships of the tables when I want to insert a new customer. Then below the diagram I list out ...
0
votes
1answer
56 views

Two-player Yahtzee game

I am working on a Yahtzee game development for two players that consists of all the categories Full house, Yahtzee, ones, twos, threes, etc. I have implemented the interface that works for two ...
2
votes
1answer
35 views

RecyclerView with different ViewHolder using generic

I have different ViewHolder for different Feed implementations. But I can't use the best practice of having each ...
5
votes
0answers
79 views

Java objects for a network sniffer program

I'm working on a network sniffer program, whose structure uses 3 main classes: Frame Class - One per monitored frame, holds reference to all the other sub frames Parse Class - Holds the hex value of ...
0
votes
0answers
16 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 ...
6
votes
2answers
90 views

Finding collisions of the first few bits of a SHA-1 hash

My objective is to find a hash collision of my modified hash function. Assuming my modified hash only outputs the first 36 bits of SHA-1. As we know, SHA-1 is a 160-bit hash value, hence, we only need ...
3
votes
1answer
90 views

Random String Chooser

I was tasked with creating the class RandomStringChooser that prints the strings in the passed array in a random order, based on the ...
1
vote
2answers
102 views

Implementation of Dijkstra algorithm

I am trying to implement Dijkstra algorithm. I try to calculate cost of reaching every node from first node. Though I have tried with couple of graphs and results are correct but I have one doubt ...
2
votes
1answer
34 views

Check if current time is within the timeframe using Joda-Time

Novice Java developer here. I've never really used a time/date library before and I'm curious how an experienced developer would solve this. You're given 4 ints: startHour, startMinute, endHour and ...
0
votes
2answers
56 views

Creating a Java text-based game map [closed]

i got a college project and i'm trying to create a map for my text-based game in Java. Me and my colleague* created this code: ...
3
votes
2answers
129 views

Strategy advisor for a Yahtzee Roll

I'm implementing a Yahtzee app and i have a class StrategicAdvisor that is responsible for deciding which strategy should be followed. The ...
6
votes
3answers
113 views

Postfix calculator in Java

I made a postfix calculator in Java. The code performs the functions I planned without problems, However, I'm not satisfied with it, because it's too verbose and I couldn't split it up into methods ...
1
vote
0answers
34 views

Near immutable, thread safe Builder

I'm writing a torrent streaming client. The plan is to wrap WebTorrent-cli and provide a Java interface to observe download state, cancel or pause downloads etc. Anyways, I came up with the following ...