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.
2
votes
1answer
46 views
-1
votes
0answers
15 views
skip list insertion in java [on hold]
I'm trying to insert an element into a skip list. While I think that my search function does what it's supposed to, I don't seem to be able to wrap my mind around how I'd go about inserting an ...
7
votes
2answers
227 views
Chocolate Distribution in a school
Problem Statement
In a School, Chocolate bars have to be distributed to children waiting in a queue. Each Chocolate bar is rectangular in shape. Consider its side lengths are integer values.
The ...
1
vote
0answers
19 views
Finding shortest paths in a Wikipedia article graph using Java
I have this sort of a web crawler that asks for two (English) Wikipedia article titles (the source and the target), and proceeds to compute the shortest path between the two. My code is as follows:
...
-4
votes
0answers
19 views
0
votes
0answers
11 views
Knight's Tour - all Solutions and Optimizing - Java [on hold]
I wrote a Code for the Knight's Tour Problem. I googled alot to try to make it as efficiant as possible. I got the Buffer. I also thought about using the Heuristics Algorithm. I don't know where I ...
2
votes
1answer
24 views
JavaFX app which does CRUD on a database table
I created my first java application for a college assignment. I tried my best to design my application using best practices of MVC design patterns. I have read about it on Stack Overflow and other ...
2
votes
1answer
45 views
Sorting a list and another list inside each item
I have a list of factories. Each factory has an item of its own and a list of other items from competitors.
I need to sort the list of factories based on price of their items and also sort list of ...
1
vote
0answers
33 views
Genetic algorithm in Java
I am working on a genetic algorithm using the following code. The variable best in generateNewPopulation stores the best ...
3
votes
3answers
75 views
Find majority element in an array given constant external space
Given constant external space (yes no HashMap), how would you improve the following code (code-wise or complexity-wise with stress on the latter) to find the ...
2
votes
1answer
43 views
Dijkstra's algorithm
Assuming everything else works as expected, is the following a correct - but not the most efficient way - of implementing Dijkstra algorithm? Because I have tested it on several examples and it gives ...
2
votes
0answers
23 views
UI-based memory game
I have created a UI shown in the screenshot. I am initalizing too many JPanels within a panel in my code to achieve the UI which will lead to bad code design and ...
-2
votes
0answers
8 views
How to check if scanner input is a string? [on hold]
I am a beginner to java, and I have a pretty simple calculator:
...
2
votes
0answers
12 views
GUI rogram connecting to SQL and listing information about products in specific category
This is my very first application written in Java and so I finalized it, solely because it occurred to be my thesis.
It is a very simple program that lists categories (Northwind database is used as ...
-3
votes
0answers
12 views
Apriori Algorithm - Mining association rules in Java [on hold]
Scan the transactions to find L1
For ( k = 2; Lk-1 !empty; k++) {
Generate Ck from Lk-1
Count the occurences of itemsets in Ck
Find Lk
L1: set of all frequent 1-itemsets with counts no less than the ...
2
votes
1answer
49 views
Travelling Salesman Problem solver
I am writing a program that can implement algorithms to solve the TSP. My goals:
The solver can record every algorithm step, so that the whole solving process can be later visualised by charts or ...
4
votes
1answer
38 views
Command line password generator
I built a random password generator in Java which is meant to be run from the command line. It accepts options for:
Length
Upper case letters
Lower case letters
Special characters
Numbers
The ...
3
votes
3answers
60 views
Method for String Building in java
I have written a custom method to use StringBuilder in java. My Requirement is to create a method which accepts any number of arguments of any type and return String by concatenating the arguments.
...
-2
votes
0answers
26 views
Printing the nth term of the Fibonacci Series (Array out of bounds error) [on hold]
I've written the following code for to print the nth Fibonacci term,
...
0
votes
0answers
16 views
Rearrange String such that similar characters are placed at least 'K' distance apart
So I was asked this in an interview, and I had to write this code on a white board. Sadly I couldn't complete the code :( .
I've realized that writing code on white board is completely different ...
0
votes
3answers
77 views
Detecting if two given strings are isomorphic using Java data structures
So I have written the following code and it works for various same length isomorphic strings I have tried. However I am not sure what are some time complexity improvements and coding tweaks that could ...
2
votes
4answers
130 views
Reverse Polish Notation Evaluation in Java
I would like to hear feedback about my code both in term of improving efficiency if possible or using other data structures. Also go ahead and let me know about code styles/patterns.
...
0
votes
0answers
27 views
Codility Fish Test 50%? [on hold]
I am getting a 50% overall mark (75% correctness and 25% performance) on the Codility Fish problem and my solution seems to be O(N) but I am only getting 25% performance. The results can be seen here ...
3
votes
1answer
31 views
Queue implementation using two stacks
Here's my code and I want to know if there's a better method for doing so. While the question has stated two stacks I wonder if we could do only with one as well?
...
3
votes
1answer
40 views
Using generics to find a View by Class
This works but feels clunky - any suggestions for improvement?
...
4
votes
2answers
32 views
Unit testing Equals, hashcode and comparator - asserting contracts
After reading Joshua Blosh's Effective Java 2nd edition, I decided to implement equals, hashcode and comparable(where applicable) to every class I have been implementing.
I have written a generic ...
6
votes
4answers
781 views
Detecting if two strings are anagrams using TreeMap
I decided to use Java TreeMap because it seems like a great data structure to fit this problem. However, I am not sure if there could be much simpler methods using ...
-1
votes
0answers
18 views
Java If Statement Not working [on hold]
I Am Making a Command Console for java, but the if statement inside the loop won't work whenever I type "help".
...
3
votes
1answer
51 views
Faster palindrome checker in Java
I wonder if there could be a faster palindrome checker in Java. The best one I have is O(n/2) which is O(n) eventually:
...
2
votes
0answers
31 views
Bit string builder for Java
I have this Java class for building bit strings. The set of methods it provides resembles that of java.lang.StringBuilder.
See what I have:
BitStringBuilder.java:
...
7
votes
2answers
45 views
Higher performance reading shorts from binary file
I just got rejected at the tech interview of a job application. They gave me the following exercise for me to complete:
They gave me a binary file with 10 million pairs of 16-bit signed integers. ...
0
votes
0answers
21 views
Finding the mean using RxJava
I'm learning RxJava and this is what I attempted to find the mean of 'n' transactions.
...
0
votes
0answers
17 views
Mapping immutable entity content
Our application currently has many immutable entities which are used for holding information on the database level:
...
1
vote
0answers
20 views
3
votes
2answers
55 views
Merge and sorting arrays of String and int in more efficient methods
Are there better methods for merge and sorting arrays of int and String in more efficient methods both time-complexity wise and ...
9
votes
2answers
85 views
Min sub array size with a given sum
How can the time complexity of the following code be improved (assuming it's \$O(N^2)\$)? What about style and patterns?
This code is trying to find the minimum subarray size that adds up to given sum ...
-6
votes
0answers
22 views
2
votes
1answer
70 views
Rock-Paper-Scissors (etc) with encapsulated business logic
Overview
The following is an attempt at a Rock-Paper-Scissors (etc) game that has its business logic encapsulated in a rules engine. For the purposes of this exercise, I kept all of the business ...
0
votes
0answers
40 views
Parallel integer tree sort algorithm in Java
Introduction
In this post, I will present a parallel sorting algorithm for sorting primitive integer arrays.
Treesort
Treesort is an algorithm which iterates over the input array and constructs a ...
3
votes
1answer
33 views
Overloaded applyRestrictionsToCriteria(…) methods
We want to refactor two methods that are exactly the same, except for one difference: one takes an org.hibernate.Criteria and the other ...
2
votes
1answer
80 views
Primes & Squares
Codeforces #230B
Question
Whether a number has exactly three factors. (i.e. 1, itself and its square root, thus squares of primes) [Time limit is 2 sec, Memory 256 MB]
Input
Number of testcases, n ...
5
votes
1answer
54 views
Home Test Exercise - Create a Java Service capable of posting GitHub events to Slack
I was asked to provide a codebase for the following exercise. I have provided the requirement of the problem and also putting down the code of two main classes. Can you please review and provide your ...
4
votes
1answer
91 views
Algorithms to find various kinds of paths in graphs
I think many here are familiar with the graph data structure. Not very long ago, I implemented as an exercise a supposedly simple Graph application that does some traversals. To note, the most complex ...
1
vote
0answers
31 views
AutoCloseable Lock
Surprisingly, this question has no satisfactory answer. A safe usage of a LockCloseable would be like
...
3
votes
1answer
28 views
Form every unique combination of the items of a list of lists
I've tried looking some stuff up. I thought it was transposition first, but looking at this, that's not exactly it.
I hacked this code together in about 3 hours, stopping frequently due to ...
-1
votes
2answers
73 views
Code efficiency - Piglatin
My code works and does what it is supposed to. However it needs to be more efficient. Could anyone help me tidy this up and show me where I could perhaps not rely on large loops (which it does a lot ...
0
votes
1answer
69 views
Radix sort in Java
As homework I had to implement many sorting algorithms including radix sort in Java. The task is to sort doubles in the range [0-1) that are rounded to the 10th ...
-5
votes
0answers
33 views
How do i check a year is a leap year or not from user input [closed]
I am doing an Object-Oriented programming with Java course in University.
Where I have to program it by checking if a year is divisible by 4, if the year is divisible by 100, it is a leap year only ...
4
votes
2answers
144 views
ToDoApp with persistence (using JSON)
This is a simple ToDoApp with a CLI that is made useful by adding persistence. A shout out to @Phrancis and @syb0rg for guiding this little project to where it is now.
The structure is rather simple. ...
2
votes
0answers
39 views