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 byte-code and run in a virtual machine (JVM) enabling a "write once, run anywhere" (WORA) methodology.
0
votes
0answers
12 views
A console-based bingo game in Java [on hold]
https://github.com/qbolt/Bingo
I created this for a class assignment and I wanted to do it in an object-oriented way. I haven't really shown anyone my code before and none of my teachers thus far ...
5
votes
1answer
27 views
Checking for surrounding mines
Am trying to create a minesweeper game, I have the following code which has to many nested ifs, I want to change the code to take out the nested ifs and make it better to read. But I am stuck on how ...
2
votes
2answers
27 views
The Boyer-Moore Majority Vote Algorithm
I have started learning Java recently and was looking into some easy algorithms.
I found the Boyer Moore voting algorithm here.
I am trying to get better at writing good code for my solutions. Please ...
2
votes
1answer
16 views
Displaying a String array in tabular format
I have an array of strings called theArray. All strings in theArray are of length 20. I wish to display this array in tabular ...
1
vote
1answer
14 views
3D bin packing algorithm using Java?
I wrote a 3D bin packing algorithm but I am still not sure if it is correct or not.
I did not follow any code or pseudo-code that's why I would like to know if it is an efficient algorithm for the 3D ...
0
votes
1answer
15 views
Generic matrix in Java supporting arbitrary rotations in constant time
I have this generic "matrix" holding elements of arbitrary type. It supports any horizontal or vertical rotations (of any step size) in \$\mathcal{O}(1)\$. See what I have:
...
1
vote
2answers
113 views
Find the highest unique element in an array
Here is my approach. Unique element means that element should present only once in the array.
...
-1
votes
2answers
43 views
Validation logic for range check with input can be String or Number
Requirement
Validate two inputs (from and to). Input can be either Number or String (value hast to be date in UTC format)
...
-4
votes
0answers
28 views
Displaying all possibilities Java [on hold]
I've found a simple program for displaying all possibilities of String from given letters and the size of that String. Could you explain for me the for loop? I ...
-2
votes
0answers
11 views
Postfix Evaluation [on hold]
I'm having a hard time understanding whats wrong with my code. When ever I go to run the application program, I get an Empty Stack Exception
...
4
votes
1answer
34 views
Evicting an entry from a size-limited HashMap<T, Integer>
I have a HashMap with a limited size of 1000 elements. When I want to put one more, the T with the lowest related Integer in the map should be replaced with the new one.
I already have this working ...
0
votes
0answers
23 views
Filtering based on actions and keywords
I have an Android function that when an intent is passed, it filters based on the actions and keywords. How can I improve this function?
...
6
votes
1answer
75 views
Very Simple UNO Game
I made a simple text-based UNO game in Java. It lacks some features of the original game, but it's good enough for now. I'm new to Java, so I would like to receive as much feedback and suggestions as ...
0
votes
1answer
12 views
Design of thread pool reuse with Executors.newFixedThreadPool in Java
In my application I have code which should run every hour on a new items and execute some expensive operation with multithreading:
...
1
vote
1answer
42 views
Methods to check form validity and to count invalid form fields
I have two these methods. Their loops are pretty similar. I'd like to refactor it to avoid duplicate nested loops. How could I do that?
...
1
vote
0answers
27 views
Game engine for 2D games in Java
I am writing a 2D game engine library that I can use for simple future games, and I've been told that it is written very procedural rather than objected oriented. I was wondering what I should do to ...
3
votes
1answer
45 views
Two solutions to Project Euler 12, but one is drastically faster
My code for #12 (first triangular number with over 500 divisors) is as follows:
...
2
votes
1answer
50 views
Quiz program in Java
I have made this small quiz with 10 question and 40 JRadioButtons. One question and 4 JRadionButtons for each panel. So I had to ...
0
votes
1answer
49 views
Enhance the performance of the source code in Java
I need help to enhance the performance of java source code. The code take txt file that has name, amount and date in form (name) (amount) (date yyyy-mm-dd) separated by spaces. After reading the file ...
0
votes
0answers
25 views
AVL Tree Array Representation
In a school assignment I'm supposed to create a program simulate insertion, deletion, count nodes, and delete tree algorithm and displays the traversal, level order, and array representation of it. ...
2
votes
2answers
94 views
Given a string S and Q query strings(q1,q2,…), check for each query string whether or not it is sub-sequence of S
Here is my approach. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.
...
5
votes
0answers
28 views
Thread-safe algorithm to make trades based on moving window of prices
Here is problem to be solved
TradingAlgorithm employs a trading algorithm which, based on the prices it receives, will return a trade to execute.
The trading algorithm must implement the ...
4
votes
1answer
44 views
Printing the right diagonal of a matrix
I am solving a coding challenge whose objective is to print the right diagonal of a matrix. And below is my code to do that.
...
3
votes
1answer
64 views
Parsing speech out of text
I'm working on an experiment to parse speech out of an emote in a text roleplaying game (MUD) so that if you can't hear it correctly, or if it's in a different language, you won't understand it. This ...
5
votes
1answer
42 views
Deterministic finite automaton in Java
Formally, a deterministic finite automaton is a 5-tuple \$M = (Q, \Sigma, \delta, q_0, F)\$, where
\$Q\$ is the set of all possible states
\$\Sigma\$ is the alphabet
\$\delta \colon Q \times \Sigma ...
-3
votes
0answers
13 views
8
votes
1answer
72 views
Java hex dumper
Can somebody please try and help me speed up my code? The file is ~12MB (you can download it here). It takes around 500-600 milliseconds to run on my i7 4790k.
...
-2
votes
0answers
23 views
MSD Radix Sort in Java [on hold]
I wrote the code for most significant radix sort but I keep getting an error of IndexBoundsException on the line: arr[i] = arr1.get(i);.
...
3
votes
1answer
57 views
Conway's Game Of Life in Java
I've written a simple demo for Conway's Game Of Life for self-practice.
How can I improve the code, especially the processLife() method which traverses and updates ...
2
votes
0answers
24 views
Speed Up Twine Cipher for Java Card
I implemented the lightweight cipher Twine described
here but it seems to me that this is not sufficiently optimized.
For example, below I have the key expansion for 80 bits:
...
5
votes
2answers
61 views
4
votes
1answer
31 views
Pulling from data from SQLite DB on Android
Apart from merging the 2 get methods, what else can I do to optimise this?
Both input and output cannot be changed. Is there a way to iterate a map while writing to it?
...
4
votes
0answers
47 views
Swing UI to display and edit terrain for a game
I would like someone to review my code and maybe give me some advice to maintain it because I'm still a beginner.
...
2
votes
3answers
367 views
Generic methods to find the maximal element in part of a list
This is the question from Oracle docs:
Write a generic method to find the maximal element in the range
[begin, end) of a list.
I had my implementation like this:
...
-2
votes
1answer
29 views
Writing clean and efficient recursive function
How would you rewrite this function, to be as much readable as possible, while containing minimum lines and being not much slower:
...
4
votes
2answers
85 views
DAO to create, update, and delete a project
I'm trying to write my first "complex" program in Java. So far, I created a local H2 database but I'm not sure about the quality of my code (I'm newbie in Java) because I don't know how I can deal ...
1
vote
2answers
62 views
Converting and enriching an array of data
The method below converts an array of TheatreListData objects to an array of TheatreListDataWrapper. It also loads additional ...
1
vote
0answers
62 views
Thread safe REST API
My assignment was to develop a REST service that will provide Airport information. This service is assumed to be used by multiple users, therefore data consistency (thread safety) and responding fast ...
8
votes
2answers
563 views
Comparing two strings to see if string 2 is inside string 1
Here is what I have to do:
Write a function scramble(str1,str2) that returns true if a portion of ...
0
votes
0answers
27 views
Prompt to pay for in-app purchases
I have the following code that prompts the user to pay for an in-app purchase when they click a button. I was wondering whether it was efficient or not:
...
0
votes
0answers
30 views
Calculate normal forms in a database
Here I calculate normal forms. To begin, I check if there something on the right side of my dependencies; if so, I save it. Then I create a powerset of all possible keys and delete those which do no ...
3
votes
6answers
276 views
Creating an array of random numbers with no duplicates
I only need three random numbers within the range of 1-54 (deck of cards) and none of the three numbers can be a duplicate. I cannot use an ArrayList; I must use a ...
2
votes
1answer
159 views
A very basic semaphore in Java
Here is is a fixed code, taking in to account Spurious wakeup issue.Thanks to Costa for bringing that up.
ISemaphore:
...
5
votes
2answers
354 views
Computing the circumference of two circles
This is a program which computes the circumference of two circles and gives some information such as the difference between circumferences. I want to know whether the method declarations and method ...
3
votes
0answers
69 views
Beginnings of a 2D Java game engine
I've been out of working in Java for quite some time now (almost two years), so I've been working on a fun side project just to get back into the swing of things.
Essentially, in the long term, the ...
0
votes
0answers
15 views
Spring validation: multiple DTOs vs single DTO with multiple validators [closed]
I need a user management service for my spring-boot project. I generally understand the use of DTO (Data Transfer Object) in spring. But when I'm thinking to design the service, I use multiple DTOs ...
3
votes
0answers
44 views
Shape inheritance hierarchy
I have managed to build an inheritance hierarchy for shape class object and I am wondering if there is a better solution to combine the following 2 hierarchies.
To begin, I have a 4 shapes classes ...
-6
votes
1answer
33 views
3
votes
1answer
91 views
Command for inequality of char
I want to ask the user about whether he wants to continue playing or not. For this I have used,
...
0
votes
0answers
20 views
Counting the occurence of each element from an array [closed]
To solve the problem, I sorted the array first and calculated the number of occurences of each element from an array. But I am getting exception while it tries to calculate and print the last index ...