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.

8
votes
3answers
319 views

Simple text-based RPG leveling system

I have two issues/questions with figuring out a proper way to write this code for a player leveling system. My First question/issue is that when this code is run it works as intended with a slight ...
0
votes
1answer
43 views

Refactor REST service with overcomplicated logic

Need to perform such actions: receive JSON from REST extract nexted JSON document calculate hash of the nested document add some fields to extracted document and save it in database return response ...
2
votes
1answer
64 views

Helper class for Fragments management

A Helper class for Fragment Management. The FragmentsManager class has methods to add and replace fragments. The replace method checks if the given fragment is present in backstack or not and if the ...
0
votes
1answer
34 views

Multi threading with CachedThreadPool [closed]

I have server-client communication architecture where there is one server and 150 clients. The server-client communication happens via Java NIO where all the clients send some or the other data every ...
2
votes
1answer
54 views

Map Character to Characters Most Frequently Found With it (in list of strings)

For an interview, I was tasked with writing a program that consumes a list of strings, and produces a mapping between every character in the list, and the characters found most frequently with it (let'...
0
votes
3answers
45 views

Creating 3 sublists based on unique conditions

I have written the following code for one of my requirements. Kindly help me if I can write this logic in a better. ...
1
vote
2answers
135 views

String Compression

Implement a method to perform basic string compression using the counts of repeated characters. For example, the string "aabcccccaaa" would become "a2b1c5a3". If the "compressed" string ...
1
vote
0answers
78 views

Codility Tape Equilibrium

This question is related to this one, since it's about the same Codility exercise (Tape Equilibrium instructions): Time complexity of tape equilibirum Basically, given an integer array, the objective ...
1
vote
0answers
679 views

Find the shortest path between two points in a 2D matrix with obstacles

I need to find shortest path between two points in a grid given an obstacles.. Given a 2 dimensional matrix where some of the elements are filled with 1 and rest of the elements are filled. Here ...
5
votes
1answer
220 views

Repeated Strings Hacker Rank challenge

I'm doing a hacker rank challenge with this one called "Repeated String". I attempted this challenge in my weaker language java. The goal is to print out the occurrences of the letter a. First you're ...
3
votes
5answers
675 views

Unique character lookup

I'm solving 387. First Unique Character in a String LeetCode problem defined as: Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1. ...
1
vote
2answers
37 views

Stack Array implementation of Java

This is my array implementation on stack in Java. It involves push, pop, get and growth when limit of array size is reached. I am a self-taught programmer starting to learn data structures and ...
2
votes
1answer
120 views

Simple Java OOP calculator with GUI

I'm learning Java and I've tried to write my own calculator with GUi based on this post. Here is the repo: https://github.com/MurDaD/java-calculator Could someone check my code and tell me how to ...
1
vote
0answers
69 views

Bidirectional iterative deepening pathfinding algorithm in Java

Introduction I have this iterative deepening search algorithm. The main "research" attempt was to find out a bidirectional version of that search, and it turned out to be superior compared to two ...
1
vote
2answers
91 views

HashMap implementation, is this good enough for interviews?

After understanding HashMaps, I decided to implement my own using 3 classes HashMap, LinkedList, and Node. I knew how to implement LinkedList from before. Can you please give me feedback on this. ...
1
vote
0answers
49 views

Android app to take a photos and show them in a gallery

Gallery will be displayed in RecyclerView. User can select some images and delete it with one button. It all works, but i think I have bad code, because I don't use some instruments (like fragment). ...
0
votes
2answers
127 views

Josephus Problem with cyclic iterator

Given the Josephus Problem. Josephus Problem N people (numbered 1 to N) are standing in a circle. Person 1 kills Person 2 with a sword and gives it to Person 3. Person 3 kills Person 4 and ...
0
votes
2answers
76 views

Storing singleton instances in a generic utils class

In one of my java projects I use singletons a lot and I was looking for a way to reduce repeating code. I made a SingletonUtils class that accepts a class and ...
0
votes
1answer
48 views

Find the square root of the number without using any built-in function?

I am working on below problem: Given an integer, how do you find the square root of the number without using any built-in function? ...
1
vote
1answer
125 views

Swing GUI application to change colour of circle with JSlider

The below code works as intended and I'm generally happy with it - the sliders each change an RGB value to modify the color of the circle in circlePanel. Likewise the diameter slider changes the size. ...
1
vote
0answers
19 views

Encapsulating simple license backup to a disk

I am enapsulating my license backup to disk, using an interface ILicenseProvider and the implementation is DiskLicenseProvider. Also i am throwing an unchecked exception LicenseProviderException which ...
2
votes
1answer
44 views

Leetcode #826. Most Profit Assigning Work solution in Java (Sort + Binary Search)

Problem Statement: We have jobs: difficulty[i] is the difficulty of the ith job, and profit[i] is the profit of the ith job....
3
votes
1answer
56 views

Selection and Insertion sorts from scratch in Java

I am trying to find a good, basic way to make selection and insertion sorts so that I can manipulate them for other sorting techniques. How do these look? Is there a simpler way to write them? ...
4
votes
1answer
64 views

Simple view for CRUD with miglayout

I have created the following view extending the JPanel class, the objective of this view is to allow the user to perform 3 CRUD operations create,delete and modify on the entity "Attribute", this ...
0
votes
1answer
71 views

HashMap Implemention in Java

I just finished implementing a HashMap in Java, with methods: add(String key, Integer value) get(String key) ...
1
vote
1answer
115 views

Menu class in Java

I had to create a selection menu for a Contact Directory project for school. This is the second time I've had to create a menu for a particular project so I recycled the menu from my previous project ...
0
votes
2answers
97 views

Displaying 21 spinners to select body parts

I just wanted to ask how can I make my code a bit shorter. As of now, I have way too much code in the class. The program should display about twenty one spinners. I know it's a lot, but in this layout,...
1
vote
1answer
43 views

Enforce printing sequence using wait() and notify()

This is a follow-up answer "implementation" to a question I posted on SO. For the sake of convenience, I will repeat my intent: I want one thread (called sub-thread) to print 10 times under outer-loop ...
3
votes
1answer
51 views

Unit Testing for Spring Controller

This is my first attempt to do unit test for one of my controllers. ...
1
vote
1answer
73 views

Hash Map implementation with a function to set all values

This is an interview question I saw online and thought to give it a try. The question is about implementing a hash map with a setAll(V value) function. This ...
2
votes
2answers
104 views

Evaluation of a variation of quick-sort (pivot-selection)

Here is a variation of quick-sort where-in the pivot selection is based on calculating the average of the values of the highest and lowest numbers. ...
4
votes
3answers
62 views

Print the first, last, and in-between integers of a range

Given our spec from Code Golf: Given two integers, output the two integers, and then the range between them. The order of the range must be the same as the input. Examples: ...
1
vote
1answer
45 views

Using Java to implement a hash table (dictionary) with only arrays

I'm new to hash codes/hash tables, so I'm very unsure of my implementation. I want to create a hash table, but I can only use arrays. Specifically, I want to be able to insert things like a dictionary ...
1
vote
2answers
98 views

A simple HTTP server implementation in Java

I have implemented a simple HTTP server which can process GET and POST requests from the client. I have written it in Java. For ...
1
vote
1answer
48 views

Add Strings in-between index of ArrayList if not already exists

So as the title states, I am trying to add a specific Items to an ArrayList if they not already exist. So here is how the Array starts. [a, b, c, d, e, f] I have ...
0
votes
1answer
37 views

Inter Thread Communication Even Odd Example

I have implemented a simple example for inter thread communication which have 2 threads to print even and odd numbers in sequence. I am looking for a feedback and points for improving the example. ...
1
vote
1answer
79 views

Producer consumer design and implementation using Java 8

Please review my design and code implementation and suggest if any optimisation is possible in terms of performance (time complexity / space complexity ) or any better way of design or implementation. ...
1
vote
1answer
53 views

Beginner's calculator, supporting M, D, A, S operations on two numbers

I'm new to programming and I sort of understand the concept of methods but, I am little overwhelmed by this program and want to shorten it using methods to make it easier to read and understand. <...
2
votes
4answers
165 views

Split a string into a list of tokens

I have the following assignment that I succeeded in solving, but the code is very inefficient. I would appreciate if someone could show me a more efficient way, perhaps with substring. Note that I am ...
1
vote
1answer
32 views

Simple JDBC Query By Example (QBE) for Spring JDBC Template

This is a quick and dirty QBE method that covers about 60% of my use cases in my DAO. I just wanted to see if someone would take a quick look at it to see if there are any issues. ...
1
vote
2answers
97 views

Balanced parenthesis, with backslash escaping

Given a Balanced Parenthesis problem. "Balanced Parenthesis Create a program that checks if in a given string expression all the parenthesis are balanced. For Example: (test) - valid ...
-1
votes
2answers
62 views
2
votes
1answer
60 views

Printing a K-ary tree stored in level-order in an array

I am given an array that represents a k-ary tree (I am also given the branching factor "k") that is stored in level order. My task was to print the tree in level order. For example a trinary tree ...
0
votes
1answer
74 views

Fluent interface for Logger

I was trying to wrap a Logback logger in order to provide some handy methods and already defined default keys of the logged json output and I came up with something like this. Do you spot any ...
1
vote
2answers
36 views

Top K frequent elements

I am working on an interview question where I need to return the k most frequent elements given a non-empty array of integers. Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] Here is my code: <...
1
vote
1answer
96 views

Android MVVM application architecture

Inspired this guide: https://developer.android.com/jetpack/docs/guide I try to build some app with similar architecture. App interact with remote API via http protocol (json responses from server). ...
2
votes
1answer
104 views

Leetcode #146. LRUCache solution in Java (Doubly Linked List + HashMap)

Problem Statement Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put. get(key) - Get the value (will always be ...
0
votes
1answer
32 views

Self Updtating QuadTree

I'm making a simple 2D game engine, and to make collision detection more effective I tried making a QuadTree class. I don't know if this will work, but that's not that important. You don't have to ...
6
votes
3answers
1k views

Checking if two time intervals overlap

I have two time intervals i1 and i2, each defined by two values, begin and ...