We’re rewarding the question askers & reputations are being recalculated! Read more.

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
62 views

This divides the class of game objects into material and immaterial

The fact is that a material object must have a field that does not make sense to an immaterial object Here is a class whose objects I want to divide into material and immaterial: ...
8
votes
4answers
735 views

A new type of builder pattern

The fact is that I wanted to apply the builder pattern. But this could not be achieved, since I could not create an instance of the class with an empty constructor - this is dangerous. The goal is to ...
5
votes
2answers
110 views

Lock implementation using atomics

I was recently given an interview and was asked to write my own lock implementation using atomics, but not necessary reentrant. I didn't answer the question, but at home, I wrote this code. Please ...
1
vote
2answers
35 views

Unit Test BST in Java

I have written BST in Java for practice. How can I write better unit test cases. I am sure the way I have written them is not proper. Code for BST ...
2
votes
0answers
24 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 ...
0
votes
0answers
39 views

Calculator using Shunting Yard algorithm

I have implemented a simple calculator using the Shunting Yard algorithm. It takes infix expression as an input "3 + 5 * 2", which evaluates and returns the value 13. ...
3
votes
0answers
52 views

Making a fast Mandelbrot Fractal viewer

I'm making a Mandelbrot set viewer in JavaFX. It takes a while, like maybe 5 seconds to finish. Here's my code: ...
1
vote
1answer
63 views

Creating a 2D array from a txt file

I was told to create a 2D array from a txt file that had the "carModel, carColor" followed by a new line. The 2D array is 8x8 and for each time a certain carmore and carcolor appear, their respective [...
4
votes
1answer
52 views

HTTPUrlConnection code optimization

I have this below code where i am sending some content over a POST and then consuming the response. I would like to know if there can be any optimizations that can be done and is there any possibility ...
2
votes
1answer
61 views

Simple local cache that checks by date else get from db

I'm looking for feedback on how this can be improved. Basically what I'm trying to do is check if the cache has the object, else check from the database. I have a list of ids, then I separate them ...
-2
votes
0answers
26 views

Difficulty reading .txt data when running Stable Marriage algorithm in Java [on hold]

I am new to Java and am trying to execute the code of the stable pairing algorithm Gale Shapley, but when executing the code below, the following error appears: ...
-3
votes
2answers
54 views
5
votes
2answers
2k views

Parsing a JSON file upload

I'm trying to parse a JSON file upload. I know the format JSON will arrive as this: ...
0
votes
1answer
49 views

Basic implicit tree implementation in Java

I tried starting off with something like below. Note that traversal etc. is not included, this is the portion for storage and modifications. It feels like this could be much more elegant at places but ...
1
vote
0answers
36 views

HashSet without collision

I have written a custom HashSet and though it isn't completed yet (this code does not consider test cases with collisions), I would like to know if there is anything I can improve in areas of clean ...
0
votes
1answer
50 views

Complexity of bubble sort

I have a simple integer sorting problem at hand and to solve it, I am planning to write a variation of bubble sort. It seems to be working fine but I am not sure about it's complexity in big-O. What ...
7
votes
2answers
1k views

Generating a range of ints as strings in Java 8

I'll have two integers and will want to generate an array of those two numbers and all the numbers in between as strings (I know the ranges are small). i.e. given ...
3
votes
3answers
202 views

Finding unpaired number in an odd length Array of integers

codility OddOccurrencesInArray: A non-empty array A consisting of N integers is given. The array contains an odd number of elements, and each element of the array can be paired with another element ...
3
votes
1answer
74 views

Code to print even and Odd number using two threads

Below I am giving you my code which I wrote to print even number using even thread and odd number using odd thread sequentially. Could anyone please validate my code whether it is correct way of ...
14
votes
4answers
15k views

Go (board game) in Java

Go is a board game (it looks like 5-in-a-row and plays like chess) and I tried to program it in Java. Rules: Two players take turn placing stones on a board. The goal is to capture teritory. ...
0
votes
0answers
51 views

Calculating the value of Pi with Monte Carlo

I made this code to calculate pi using MonteCarlo method. I'm also learning how do Java threadpools and multithreading work. Can you tell me if this method is thread-safe and how can I improve it if ...
5
votes
4answers
3k views

Cyclic Rotation

Can I get feedback on my code? Problem: A zero-indexed array A consisting of N integers is given. Rotation of the array means that each element is shifted right by one index, and the last element ...
7
votes
3answers
171 views

2048 graphic game

This game is made for JFrame. You can control using the arrows. The numbers in the cells are the degrees of the number 2. It is possible to change the initial position of the window, its size, and the ...
7
votes
3answers
3k views

Game counting to 21

The idea of the game is that the player and the computer take turns entering either 1, 2, or 3, and that number is added to a running total. Whoever goes over 21 loses. I need to develop a strategy ...
1
vote
3answers
91 views

Populating Lists with harcoded data

I have a class MassiveDTO that contains lists. At some point in the project, I need to generate an object of this class, that will contain some hardcoded data. I ...
6
votes
0answers
101 views

Understanding RSA key generation and implementation in Java

Here is an attempt to leverage Java's BigInteger class to implement the RSA algorithm, as well as md5 and sha512 hashing functions to generate keys for what I hope to be strong cryptography. My prayer ...
-4
votes
0answers
28 views

Design Debugger [closed]

This is a popular interview question. I see it posted everywhere but no solution to it. I know its a bit open ended but could someone explain what could be an acceptable solution in the scope of an ...
0
votes
0answers
87 views

Animal class with Threads and factory

it's my first time working with threads and I had this Homework to solve: Homework Text: Program a class called Animal. Animals have a spatial position that represented by an x ​​and a y coordinate (...
5
votes
3answers
122 views

Proper way to find newest file in a directory

I wanted to ask if this is a better way to find a latest file in given directory. This is my current approach: ...
3
votes
3answers
70 views

Getting rid of an inordinate use of the `instanceof` function

I am working with a library that has a base class Base, and three class descending from it Destination, Amenity and Landmarks. The Base class looks something like this ...
7
votes
2answers
276 views

Fastest way to get a value from csv file using java 7

My code picks a value from a too large csv file (~300MB.) at a given index i and j (assuming the csv as 2D array because it ...
-1
votes
0answers
21 views

How to check the all elements in the array [closed]

i want to make a method called isSorted which takes an array of integers and returns an integer value as follows: 0 if the array is not sorted 1 if it is sorted in ascending order -1 if it is sorted ...
3
votes
1answer
60 views

GridItem and GridContainer

This library provides methods for storing items into an inventory. the container is based on a grid as well as the items going into that container. can you please review the code in any way? ...
5
votes
3answers
100 views

Image filtering application

I'm building an image filtering application, and I'm new to the Java frameworks that I need to do so. Right now, I can apply a simple 3x3 kernel blur to my thing by overwriting the RGB values of the ...
4
votes
2answers
237 views

Wrapper class for adding elements to HashSet

I have many object of class Test. I want to be sure that among them, there are no two objects o1 and ...
2
votes
2answers
796 views

Creating an array length n * n, separating it into n groups, and adding numbers to it n times

I am completing the CodingBat exercises for Java. Here is the one I have completed just now: Given n > = 0, create an array length ...
0
votes
2answers
338 views

Find The Simplest Sum

I was trying to solve The Simplest Sum from hackerrank. Could anyone please let me know how I can make this code much effective in terms of time and space complexity? You are just learning to code ...
3
votes
1answer
92 views

Knuth-Morris-Pratt algorithm in Java Finding substrings in a matrix

Problem Given two matrices: a pattern p and a text t. Write a program that counts the number of occurrences of ...
5
votes
1answer
87 views

Store in console

I implemented a sign in from different accounts on which different amounts of money lie. You must also specify what will be sold in the store. When you buy, you can put things in the basket, get them ...
1
vote
0answers
48 views

Using user-defined iterators in user defined aggregators [closed]

suppose i have a class called Sequence which accepts Aggregate functions and i have a class Aggregator which does the aggregation ...
7
votes
2answers
5k views

Java Pig Latin Translator

Over the last few days I created this Pig Latin Translator just for fun. I would really appreciate it if anybody could give suggestions of how to improve the code and make the program more efficient. ...
2
votes
1answer
55 views

Simple Banking application in Spring boot, JPA, REST where balance can be transferred among predefined accounts and transaction history retrievable

I want to create a very simple banking application where (i) predefined accounts with a positive balance can send money (ii) requesting balance and a list of transactions can be found. I have ...
2
votes
1answer
46 views

interpre function implementation

Here is the description of the problem. Write a simple interpreter which understands "+", "-", and "*" operations. Apply the operations in order using command/arg pairs starting with the initial ...
3
votes
1answer
80 views

Resource manager class with basic dependency handling in java

Updates: I kept the original code here, while performed some changes on my machine, including: fixed the incorrect return documentation for clear() made the ...
3
votes
1answer
80 views

Statistics component of Finance Tracker

I'm doing a Java software engineering team project in school and my team has decided on a Finance Tracker application, which contains the main components of Expense, Budget, Statistics, Suggestions ...
1
vote
2answers
106 views

Minesweeper game for the console

You can set any size of the field and any number of bombs. I think I got a pretty flexible program again(Tic tac toe game for the console). What do you think about the code? I would like to know if I ...
-1
votes
2answers
57 views

How to filter and update the hashmap in java 8 streams? [closed]

I have a scenario and I am not sure what possibly could be the effective way to filter hashmap and update the same map. Here is my hashmap; Map> mappedProducts = new HashMap<>(); I have put out the ...
3
votes
1answer
136 views

Stopwatch utility class in Java

Looking for input on my code for a Stopwatch utility written in Java. ...
2
votes
0answers
48 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 ...
3
votes
2answers
68 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: ...