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)

3
votes
0answers
17 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
46 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. ...
-1
votes
0answers
20 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
13 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
69 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
3answers
113 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
23 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
26 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? ...
2
votes
1answer
29 views

Using generics to find a View by Class

This works but feels clunky - any suggestions for improvement? ...
4
votes
2answers
27 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 ...
5
votes
4answers
770 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
47 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
44 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
20 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

Throw exception in Spring when loading a file

I have this following piece of code: ...
3
votes
2answers
54 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
83 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
68 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
39 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
31 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
79 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
53 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
87 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
26 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
71 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
56 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
140 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. ...
3
votes
3answers
103 views

Loading modifications at runtime

I'm working on a game engine among other things in Java, and would like to know how to optimise my code, as it is ridiculously ugly and bloated. I'm terrible with operating the ...
-1
votes
0answers
13 views

JFrame Background Color Not Working [closed]

I just made a new JFrame And I Want To Know Why The Background For This Isn't Working ...
2
votes
1answer
39 views

Raindrops in Java

Problem Statement: Write a program that converts a number to a string, the contents of which depends on the number's prime factors. If the number contains 3 as a prime factor, output ...
2
votes
1answer
34 views

Creating List of String elements that occur a certain amount of times using only the List ADT

I am tasked with creating a list with no duplicates of all String elements, in this case first names, of an ArrayList. The method is passed a threshold, and the ...
-2
votes
3answers
98 views

Generating a very long random string of letters

I was trying to fill a file with about ten million random characters (a-z,A-Z,' '). To my surprise the code is extremely slow. I inserted this print ...
-2
votes
0answers
33 views
5
votes
2answers
76 views

Movement around a large map

I'm trying to make a small shooter game, where you can only see a small portion of the map around you. The map will also be much larger then the actual JPanel (The panel is 1000 by 1000, the map ...
3
votes
1answer
35 views

Serialize and deserialize n dimensional int array

I've made two symmetric methods which serialize an int array of any number of dimensions into an OutputStream, and read such an array from an InputStream. I was wondering if there is ways this code ...
2
votes
1answer
57 views

Refactor legacy code to spring

I am refactoring a legacy codebase to use spring. I am newish to spring and was wondering if you have any suggestions for the following code I refactored. Specifically about providing the ...
-4
votes
0answers
38 views

Understanding about clean code [closed]

I am struggling to write a clean code. I read lot of articles about clean code. I have written a small project to demonstrate my understanding. Can Someone review my code. advice to improve the ...
3
votes
3answers
48 views

Binary string to decimal conversion

Problem Statement: Write a program that will convert a binary number, represented as a string (e.g. '101010'), to its decimal equivalent using first principles Implement binary to decimal ...
2
votes
0answers
17 views

Class for serializing generic gson objects

I realized I had just created two classes that were virtually identical for simply saving objects to their own json files, so I've attempted to make it more generic. My only noticeable problem is ...
-3
votes
0answers
33 views

How do I avoid the runtime error in the following code? [closed]

INTEST - Enormous Input Test no tags The purpose of this problem is to verify whether the method you are using to read input data is sufficiently fast to handle problems branded with the enormous ...
-1
votes
1answer
70 views

Accepting any object and returning the object

I have been tinkering with generic methods in Java but still haven't figured out a way to optimize this code. Here I need to write similar piece of code for both plan and add-on. ...
3
votes
1answer
44 views

Sort stack using two stacks

My program is supposed to sort a stack such that the smallest item are on the top. I can use a temporary stack, but you may not copy the elements into any other data structure. The program works ...
2
votes
0answers
25 views

Adding messages to a new user record

I've a User and Notification Entity relationship as: ...