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.

learn more… | top users | synonyms (2)

2
votes
3answers
55 views

Choosing a Color based on an int for a 2048 clone in Java

Is it possible to make this cleaner / more efficient? I know that this is probably not the best way to do this and probably could be made better but I cannot figure out how I do that. Basically, a ...
3
votes
2answers
71 views

Bitcoin trading system

Recently I did an exercise for a interview pre-screening, but was not selected. They did not give much detailed feedback apart from "the code was not up to what they wanted". It would be really ...
0
votes
0answers
8 views

Populate List View - Android Studio [on hold]

I've a little problem with my code. I have a simple application that should collect data from SQLite database and print on a Listview, I'm currently use the way who implements a DataProvider, an ...
3
votes
0answers
42 views

Java Snake game

I am a self - taught coder, and have been learning Java / C# for the last 2 1/2 years (inconsistently). I have recently created a snake game in Java with the help of an online tutorial. I have ...
0
votes
1answer
26 views

Stack that does Push, Pop and Median in O(1)

Here are two implementation of a stack that does Push, Pop and Median in O(1). Invite comments on complexity and betterment. Option - 1 ...
1
vote
1answer
29 views

Sort by year and day descending, yet time ascending

I recently discovered a hugely inefficient portion of code in my program, and have gone about rewriting it. I am however, not quite sure if the rewritten program actually does exactly what I want, due ...
1
vote
2answers
53 views

How to structure empty check for individual object? [on hold]

I have an object like this, ...
1
vote
1answer
61 views

Skeleton of a Multi-threaded web crawler in Java

I am trying to prototype a simple structure for a Web crawler in Java. Until now the prototype is just trying to do the below: Initialize a Queue with list of starting URLs Take out a URL from Queue ...
3
votes
1answer
77 views

Convert an Integer number to readable format in Java

The number is ranging from 1 to 999999999. ...
-2
votes
0answers
20 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
276 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
26 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: ...
-5
votes
1answer
28 views
0
votes
0answers
14 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
27 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 ...
3
votes
1answer
51 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
70 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
82 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 ...
3
votes
1answer
62 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 ...
3
votes
0answers
27 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
14 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
15 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
58 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
3answers
78 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
4answers
85 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
28 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
22 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
85 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
139 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
33 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
47 views

Using generics to find a View by Class

This works but feels clunky - any suggestions for improvement? ...
4
votes
2answers
38 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
788 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
19 views

Java If Statement Not working [closed]

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
52 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
18 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

Throw exception in Spring when loading a file

I have this following piece of code: ...
3
votes
2answers
58 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
93 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
24 views
2
votes
1answer
74 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
2answers
95 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 ...