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
1
vote
1answer
2k views

Array sort-rank class

I had a task where I was supposed to write a solution to sort entries(Name, score - in an array/list) in order of score and generate ranking based on higher score to lower scores. I tried doing that, ...
1
vote
1answer
135 views

Mergesorting a stack in Java

(See the next iteration.) I have this small program for sorting a stack using mergesort. Basically, the aim was to use as little aid from JDK library as possible. See what I have: StackMergesort....
1
vote
0answers
24 views

Wikipath stack in Java - Part II/IV - The implicit Wikipedia article graph

This question is the continuation of the Wikipath stack series: the two classes that - given a Wikipedia article \$A\$ - return the lists of neighbour articles. The forward node expander return the ...
0
votes
1answer
126 views

Implementation of Bridge Design Pattern

I made an implementation of the Bridge Pattern to handle ever-changing in crawler APIs that I'm using in my APP. ...
0
votes
2answers
527 views

Return the next right node

Given a binary tree, return the next right node. This question is attributed to GeeksForGeeks. For example, consider the following Binary Tree. Output for 2 is 6, output for 4 is 5. Output for 10, 6 ...
0
votes
2answers
368 views

BFS in a grid with wall breaking saldo in Java

In this problem, we are given a 2-dimentional grid, with each cell being walkable or holding a wall. Given an integer \$s \geq 0\$, find the shortest path from the source node to target node breaking ...
0
votes
2answers
120 views

Remove duplications from a Java String

today I tackled this coding challenge: Remove duplications from string. I was thinking of either using a Hashmap or a Set but realized that a set might have a longer run time since the way it ...
0
votes
1answer
190 views

Project Euler#18: Maximum Paths I: Brute Forced Depth First Search

Problem: Data: ...
0
votes
1answer
115 views

A Java subclass of ArrayList that supports rotation in constant time - follow-up

(See the previous (and initial) iteration.) Compared to the previous iteration, I have added more methods that maintain the invariant required for constant time rotations, such as bulk add/remove, ...
0
votes
1answer
357 views

Implementation of bridge design pattern for a web scraping app - follow-up

Earlier today I tried to implement an example of the bridge design pattern, but I ended up misinterpreting it. I made a lot of changes: ...
0
votes
1answer
52 views

FollowUp CommandLineInterpreter (CommandLineInteraction)

I wrote an command line interpreter (CLI) in Java and got some real helpful hints on how to improve. The cli is responsible to pick up the users input (via keyboard aka command line) into any app ...
0
votes
1answer
276 views

Division without using addition, multiplication or division [closed]

Could you please tell me if there is better way of performing division without +, * or /? I'...
0
votes
2answers
545 views

Command pattern implementation [closed]

Recently, I have get familiar with Command Pattern implementation. I have a problem where I need to get a choice for user to select what kind of method to execute typing method name or number, which ...
0
votes
1answer
292 views

Does Java need an Observable object with generics?

This is the follow-up question from here. This is an Observable class similar to java.util.Observable. The difference is that ...
0
votes
1answer
335 views

Find pairs of consecutive numbers fetched from blocking queues

I was coding for the following programming question: Suppose you have two independent blocking queues that will keep getting new data, the new data will always be greater than the last element of ...
0
votes
1answer
370 views

Java MultiThreading using wait and notify - follow-up

After following the tips from @VoiceOfUnreason on my previous question, I want to post the revised code. The purpose of the code is to simulate a Shop and a ...
0
votes
1answer
119 views

Validation on two different classes and passing one object including everything to another class

I have two consumers and each consumer has their own validation logic entirely different from one other so I am using two validator class for that, one for each other. ...
0
votes
2answers
76 views

Follow-up: Find sum of number of times that each character of source occurs in the target

This question is a follow-up of this question. The aim of the questions is to find sum of number of times that each character of source occurs in the target. In the new code, I've renamed the char ...
0
votes
1answer
532 views

Movie rent terminal application

Part 2 I'm studying Java (as a hobby) and decided to create a little simple app just to see what I've learned. The app's purpose is to store data about movie rents: who, what movie, movie's price, ...
0
votes
2answers
82 views

Acey Ducey game - followup

I'm a beginner in Java and want to improve and learn. This is a followup of my previous post. This is a game called "Acey Ducey": The dealer shows you two cards. You decide whether you want the ...
0
votes
1answer
735 views

Graph radius in Java

(See the next iteration.) The following snippet is a brute-force algorithm for computing a graph radius in time \$\Theta(V^2 + VE)\$ and space \$\Theta(V)\$ simply by doing \$|V|\$ breadth-first ...
0
votes
1answer
272 views

Generic object pool [closed]

I'm doing research on GenericObjectPool by putting Cipher in pool so it can be reused. ...
0
votes
1answer
140 views

Heap selection sort - follow-up

See the previous and initial iteration. I got rid of Run objects and just maintain two integer arrays in the RunHeap: one for ...
0
votes
4answers
6k views

Finding all integers in an array with odd occurrence

I am doing an interview exercise problem from here. The problem is to find "all numbers that occurred an odd-number of times in an array". Here is my high level psuedo code thinking: Construct a ...
0
votes
3answers
906 views

Implementing multiple Producer Consumer using custom Blocking queue [closed]

I am trying to implement multiple producer multiple consumer problem using a custom blocking queue. The requirement is that: If the queue is not full, all the producers should be able to produce ...
-1
votes
2answers
98 views

Practicing Java servlets, MySQL and JSON - follow-up

(See the previous iteration.) What's new I have incorporated all the points of Dmytro Maslenko's answer. My code seems a little bit tidier. Code AddPersonController.java ...
-1
votes
1answer
945 views

Refactoring duplicated code [closed]

How can I remove duplicated code? It's hard to me because I use different service class and model each code. ...
-2
votes
2answers
1k views

“ChocolatesByNumbers” challenge

Here is a problem I have attempted: Two positive integers \$N\$ and \$M\$ are given. Integer \$N\$ represents the number of chocolates arranged in a circle, numbered from 0 to \$N − 1\$. You ...
-3
votes
2answers
562 views

Compressing a string

The task is to compress a string. eg. "abcbcdabcbcd" Here as you can see some characters are repeated, so it can be compressed. "abcbcdabcbcd" -> "(a(bc2)d2)$" '$' denotes end of string. My code: ...
-4
votes
3answers
2k views

Finding the longest Collatz Sequence

Inspired by Project Euler 14: Longest Collatz Sequence "Which starting number, under one million, produces the longest Collatz Sequence chain?" I wrote the following Java code: ...
-8
votes
2answers
276 views

Find common “characters” in 2 given strings (rev5)

Could you help me further improve this code, which includes some feedback from this site already Find common “characters” in 2 given strings (rev4)? What has changed since version 4: I re-...