Stack Exchange Network

Stack Exchange network consists of 174 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.

4
votes
1answer
60 views

Drawing consecutive rectangles with an algorithm

I have an assignment to draw rectangles that get larger and larger each time I draw them. Just like shown below. I've labeled them TL = Top Left, TR = Top Right, BL = Bottom Left, BR = Bottom Right. ...
0
votes
0answers
43 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: ...
1
vote
1answer
38 views

Find the highest result between two elements in an array using their values and indices

I got a programming question on an interview where performance was the focus. I couldnt come up with a better solution than the one below which I think has a time complexity of O(n^2 + n) and scored ...
1
vote
1answer
48 views

Keypress output to screen

For a school project, I had to make a keylistener that would output whatever you typed to the screen. A JFrame would be initialized to have the focus required for the listener to work. It uses delete ...
3
votes
1answer
65 views

Maze navigator AI

I developed a maze navigator in Java for a project for my school. It works fine, and it gets through the maze just fine. The program prints to the screen each time it loops through the maze to set the ...
2
votes
1answer
75 views

Grouping items in a list into inner lists

I have a function that looks up in a list the elements which share same values in order to group them. As a fast summary, this should be the input/output: [A, A'...
0
votes
1answer
41 views

Trying to follow BDD in tests, end up with two exactly same tests

I am testing my repository class: interface AccountRepository{ void save(Account account); Optional<Account> findById(Long id); } And when writing ...
2
votes
1answer
52 views

Search for the biggest amplitude in an array

I have a assignment to find which season has the biggest temperature amplitude. Input par is the int array with temperatures: ...
0
votes
1answer
52 views

Nested stream to check the truth condition at first instance

Lets say I have Cars with Features, and I have been given a List of features to look for in ...
2
votes
1answer
56 views

Java League of Legends ping checker

I'm still a freshman and this one of my first projects I made using Java and Swing. The program is a simple League of Legends multi-threaded ping checker that pings the server 10 times to get an ...
2
votes
2answers
79 views

Splitting a String and Returning Converted Data

I have 2 Classes, the first one is only used as Container, and the second Class Splits a GpsString, Converts it to suitable data types and returns the Container Class. The String to analyze looks ...
1
vote
3answers
59 views

Generic implementation of binary search tree in Java

The following is my binary search implementation in Java: ...
1
vote
0answers
65 views

Animated Button on Android using AfterEffects and Lottie

I have a question about my implementation of a "special" Next-Button. First I want to show you my AfterEffects file: So This Animation has 3 parts Green: Entry correct Red: Entry incorrect Blue: ...
1
vote
3answers
95 views

Remove duplicates from sorted array, in place

I solved this problem: Given a sorted array nums, remove the duplicates in-place such that each element appears only once and return the new length. Do not allocate extra space for another array, ...
0
votes
0answers
45 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. ...
2
votes
1answer
64 views

Determine whether a word appears in a sentence

Given an array of words representing a sentence and a word to search for, the method must determine whether the word appears in the sentence. Specifications Case insensitive. The arguments are never ...
1
vote
2answers
100 views

Tic Tac Toe Java Swing game

I just created a simple game. Now I'm thinking what could be done better here. I want to get some tips how to make the code better/easier or what to add to it. Code: ...
1
vote
0answers
43 views

Retrieving date and time from Datepicker and Timepicker and then converting it to milliseconds

I currently have an Android Activity that allows the users to select the startDate, endDate, ...
1
vote
1answer
64 views

Rectangle packing in smallest possible area

I have written a Java Program to place a bunch of rectangles into the smallest possible rectangluar area(no overlapping and rotating). Here is a short summary: I calculate minArea and maxArea: ...
3
votes
3answers
151 views

Count characters of a text file

This program counts the number of the occurence of each character that is used in a file. I tried to use everything that Java offers to me properly. If you have tips which library functions would ...
4
votes
3answers
113 views

Java Magic square program

Here is my improved version of my Magic square program from following this earlier version. I also added a few comments. Any help for improvements would be really appreciated. ...
1
vote
0answers
55 views

Solutions for counting trapped water on islands

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

String reversing x times

Inspired by CodeWars We have a string s Let's say you start with this: "String" The first thing you do is reverse it: "gnirtS" Then you will take ...
2
votes
2answers
68 views

Return Set<Integer> with random unique Integer numbers between min and max range

I need set of random unique Integer numbers for my unit test. I implemented this method, however I'm not sure if this is best way to implement this. ...
1
vote
2answers
56 views

Reading new data from a constantly updating file in Java

I have a log file which is constantly updated with new lines of data. I need to get new added data in java as soon as it's written. For now my solution is: ...
1
vote
2answers
74 views

Call multiple asynchronous HTTP requests and wait for the result

I have a Repository class which looks like this: ...
0
votes
1answer
35 views

Generating probability table of 2-character combinations from text file in Java

I have written a probability table generator in Java to help me generate randomized girl's names for the game I am making. It reads from a text file and creates a ...
3
votes
3answers
250 views

Calculate with numbers from different number systems

This program calculates with numbers from different number systems and outputs the result in the desired number system. You call it like that: ...
1
vote
1answer
30 views

Merge Two Sorted Lists by splicing together the nodes of the first two lists

I solved this problem: Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. How can I improve its execution ...
3
votes
2answers
201 views

Remove all occurrences of an element from an array, in place

I solved this problem: Given an array nums and a value val, remove all instances of that value in-place and return the new ...
0
votes
1answer
44 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
41 views

Search insert position

I am trying to solve this problem: Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. and ...
0
votes
1answer
53 views

Recursive fluent builder

Problem statement I have entities whose relations form a graph. As an example, let's imagine Users and Groups. Each user has a <...
2
votes
1answer
43 views

Calculate supporting forces of a simply supported beam

The program uses a very simple algorithm to calculate the supporting forces of a simply supported beam. I'd like to know if thorwables are good practice to handle semantic errors and if one should ...
0
votes
1answer
27 views

Factory to instantiate and configure Selenium WebDriver

I, also, need to know whether this is a valid implementation of the factory pattern. The amount of effort which goes into configuring DriverFactory to simply get a ...
1
vote
1answer
46 views

Find two numbers with target sum

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: ...
2
votes
1answer
48 views

Merge sort implementation with various improvements

So I was working on merge sort today, and was trying to speed it up. I would like your opinion on the implementation and if it's possible to make it faster. Besides that I was wondering if there are ...
2
votes
1answer
230 views

A* Pathfinding for a Game

I'm working on a game and I have developed A* path finding for certain enemies. But I think I have some optimization issues. If I put the player in an area that cannot be reached and put 3 or 4 ...
2
votes
1answer
51 views

Number of way to render an amount of money

I made an algorithm to train my skill in dynamic programming and I would like to have feed back on it. This algorithm takes a money system (int) and have a certain ...
2
votes
2answers
148 views

Java implementation of well-separated pair decomposition

I was trying to implement the algorithm of the 3D well-separated pair decomposition WSPD using an octree. First, I begin by implementing the class OctreeNode as ...
3
votes
1answer
47 views

Search indexing of Battle Mech Loadouts

Background I am since a long time ago developing a JavaFX application for creating and analysing 'Mech loadouts for Mechwarrior Online. I previously had a very crude search function based on a ...
1
vote
1answer
61 views

Fisher-Yates shuffle Java implementation

This is my attempt at an implementation of the modern Fisher-Yates shuffle in Java. I'm not sure if it can be made more efficient, but I did my best to make it as simple as possible, and I learned how ...
2
votes
1answer
43 views

Java n-ary Tree class with custom made methods and nested Node class

I'm a beginner and I wrote this (working) code for n-ary tree. The specifics: Each node is to be built with an integer value. Each node has a variable number of children. The nodes should have an ...
1
vote
2answers
65 views

Reporting sums of shopping carts

I have an object (ShoppingCart) that has a list of CartItems, which contains the related ...
1
vote
1answer
33 views

Avoiding the use of ordinal() in an already-deployed enum

While reviewing a PR, I found an enum being used like this: ...
1
vote
1answer
94 views

Simulate BankAccount in Java

I have been learning Java for the past two months, and started writing this task about simulating Bank and BankAccount to practise a bit of OOP and exception handling. Problem is I am not confident ...
1
vote
1answer
33 views

Numbers adder via generics

This method add all numbers in list and return it as double ...
0
votes
3answers
64 views

Represent a Class which holds translation Strings [closed]

I have a class which represents some translations of a keyword. ...
0
votes
1answer
28 views

Program to check if heap order is correct or not

There is a Java program to check if a Heap (Min) is in the correct order. Heap Order means the parent is less than both left child and right child. ...
2
votes
2answers
52 views

Basic AES/CBC implementation in Java

A little bit about myself: I am 18 years old, a student living in Germany and currently working on an android app. I would like if someone has the time to review my code. I am especially interested ...