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)

-1
votes
0answers
8 views

WLP (Weakest Liberal Precondition) Transformer implementation in Java? [on hold]

Input for our program is array of instructions (Expression [] instructions). Then iteratively starting from last instruction, and going backwards we searching for weakest pre-condition of single ...
1
vote
3answers
82 views

Generate all possible numbers which can be representated as the sum of 2 cubes below N

I have written a program that generates all possible numbers which can be represented by adding 2 cubes which have value less than N For example: when \$N = 10, 1^3 + 2^3 = 9\$ ...
7
votes
3answers
115 views

Return list of common email ids from a list of lists

Input: ArrayList of ArrayLists with email ids. Output: Return ArrayList of email ids which appears in each inner ArrayList. Ex: Input: [[[email protected], ...
8
votes
1answer
37 views

YAuB - Yet another Micro Benchmark

I recently answered this Beautiful String question, where the task is to maximize the value of a string by assigning each character a different value (from 1 to 26) in a way that the sum of all ...
16
votes
4answers
573 views

Calculate distance using speed of sound

Been working on learning Java and this was a challenge as part of a chapter on data types. Create a program that computes how far away, in feet, a listener is from a sound. Sound travels ...
5
votes
2answers
102 views

Find the Biggest Traveler

This is from one of those online test sites, so the result had to be contained in a single class. The problem was stated as follows: Your java method will be given a 2-D array ...
4
votes
0answers
22 views

Simple Chess Game, Part 2: The Pieces

As I was writing my first part of my Chess question, I realised that I couldn't fit all my code into one question (I exceeded the character limit), so I will continue here. The pieces all share the ...
6
votes
1answer
47 views

Simple Chess Game, Part 1: The Board

I am currently creating a chess game, and have so far done the board. The board is pretty much a two-dimensional array, where Pieces are stored in their positions. ...
1
vote
0answers
10 views

OSGI bundle and threads

I am new to OSGI. I have 10 threads, writing their names to a file. After recording thread sleep random 0..1 sec, this all must be a bundle. Any comments? ...
5
votes
1answer
39 views

Implementation of a binary heap

I've read a little about binary heaps/priority queues and decided to try my hand at making my own implementation of one. I'm not the most experienced programmer and I would be really grateful if you ...
4
votes
1answer
34 views

Speed unit converter

I'm basically a newbie in android app developing. So I'm not sure if this is the right way to write these codes. I have made an app called "Zconverter". It has 9 fragments and the code i m showing ...
4
votes
2answers
73 views

Function to get top k words in a given String

This is a two-part job: to identify a word to find the top k words I've tried to use regex to split but it's taking 10x more time when string is really long. ...
4
votes
1answer
27 views

Use of static factory methods for vectors and matrices library

I've been working on a Java-based mathematics library focusing on vectors and matrices. I plan to use it for an important upcoming project, so the classes are analogous to data types available in GLSL ...
6
votes
1answer
41 views

Chess game project

I'm currently just working on a Chess game project to improve my object-oriented skills. It is currently only at the starting stages and there is quite a bit missing (such as error checking) but I ...
4
votes
1answer
27 views

Pollard p - 1 implementation

I'm trying to implement the Pollard p - 1 algorithm seen here, in Java. It has a C implementation here. I am using it for numbers without any smaller factors so trial factorisation isn't needed. My ...
3
votes
1answer
27 views

Comparing multiple arguments and returns the smallest argument

I want to see if anyone knows how to optimize the code below: ...
2
votes
1answer
42 views

Cache for JSON API

I am working on a small project which utilizes a 3rd party API. Many of the queries from the API can take 5-10 seconds so to keep the front end moving a bit faster I decided to cache the responses ...
7
votes
2answers
118 views

Convert Integer to Date in Java

Due to some clueless soul, we have several fields in a legacy database that uses a 6-digit integer to represent a date in (YYYYmm) format. The date field is assumed to be the last day of the given ...
2
votes
1answer
37 views

Copying messages with compression

I have the following Main class: ...
1
vote
1answer
23 views

My Own ThreadPool implementation

I tried to make a Server using Java with a Thread Pool. Any review is welcome: ...
9
votes
1answer
111 views

World Map Viewer with LibGDX

I am working on a game where the player can walk around a world comprised out of a grid of tiles. The World object contains a ...
4
votes
1answer
23 views

Multi-Threaded Java Server

As practice I wanted to write a Socket in Java: ...
2
votes
0answers
25 views

DAO and service layer design in Java MVC web application

I'm building a prototype MVC web application as a learning exercise so I'm avoiding existing frameworks. I'm interested in feedback on the following approach The view consists of JSPs which use EL to ...
9
votes
3answers
325 views

The Beauty and the Strings

This originally appeared in Facebook's hacker cup 2013. Solving it was fun, though I find myself looping through similar data quite often. Challenge: Print the maximum beauty of strings. ...
2
votes
1answer
52 views

Time Limit Exceeded for CodeChef Easy problem - STRQ (Chef and Strings)

I was working through a codechef easy problem here. I've got to a solution, but it only passes the Subtask #1. For the other two subtasks, it shows TLE (Time Limit Exceeded - which is 1 second). ...
3
votes
1answer
48 views

Printing a tree level by level

I have written a program to print a binary tree level by level on different lines, like the tree would actually look if drawn on paper. I have done a BFS traversal and then I proceed to print the ...
3
votes
0answers
25 views

Java 8 CompletableFuture - fan out implementation

I was wondering what is the best way to implement a fan out type of functionality with Java 8 Completable future. I recently rewrote a function that had a bunch of old ...
2
votes
1answer
103 views

Reversing the lines of file

I have written a program to reverse the lines of a file. I made use of the String [] approach with the String.split(separator) ...
3
votes
3answers
85 views

Merge sort implementation and improvements

I would like your opinion on my Java implementation of the merge sort algorithm on an integer array, since I'm not really into algorithms I'd like to know from you if this is a correct implementation ...
0
votes
0answers
18 views

Checking whether a number is in a Fibonacci sequence [on hold]

I was asked to find a way to check whether a number is in the Fibonacci sequence or not. The constraints are: \$1 \le T \le 10^5\$ \$1 \le N \le10^{10}\$ where \$T\$ is the number of test cases ...
1
vote
1answer
69 views

Finding duplicate ID numbers for a list [on hold]

Need to shorten the code below - two of these methods that find out whether there are duplicate ID numbers for a list of dataObjects. I tried to use ...
0
votes
3answers
58 views

Finding all integers in an array with odd occurrence

I am doing an interview exercise problem from here. The problem is to find "all numbers that occurred an odd-number of times in an array". Here is my high level psuedo code thinking: Construct a ...
0
votes
0answers
27 views

Counting the number of a word in a string [on hold]

I'm having a problem finding the number of the profane words in a sentence. I couldn't find out how should I do it. This is my code: ...
1
vote
1answer
25 views

Saving model's data in the model vs an external data manager class

I have a bunch of models (using activejdbc) Person, Company, Health, .... etc (I have 8 models). I'm showing an example of just one model Person In the first approach I have a data manager that ...
3
votes
0answers
15 views

Property Change Listener for Entity Management

Originally (incorrectly) posted in stack overflow: I would like to know if the solution I came up with for managing relationships between entities is sensible. Guys in my team feel it is transparent, ...
7
votes
4answers
406 views

Reversing the lines of a file

I am trying to reverse the lines of a file by reading the file through an array. Is there a more efficient and quicker way of achieving this? ...
-1
votes
2answers
32 views

Should Domain objects for a public API be able to save/send themselves? [on hold]

What follows is a contrived example just trying to illustrate the point. My main questions: FileWithSave handles its saving itself, but delegates it to a repository object. This allows ...
3
votes
1answer
42 views

Sum of left and right nodes (individually) in a Binary Search Tree

I have written a program which calculates the sum of all the left nodes and the sum of right nodes in a Binary search tree. I have used BFS to traverse the tree. The code is as follows: ...
8
votes
2answers
182 views

Video Store Rental Application

I'm in the middle of developing a video store rental application for a school project but am starting to question whether I'm going about things in the correct manner. Although the application is ...
2
votes
1answer
23 views

Using FlatFileItemReader and Asynchronous Processors

I have a simple csv file with ~400,000 line (one column only). It takes me a lot of time to read the records and process them. The processor validating records against couchbase. The writer - writing ...
0
votes
1answer
45 views

Recursive Brute-Force [on hold]

I have to recursively solve the following problem, using a brute force approach: Suppose two people, A and B, have an even number of ordered boxes, each with a given value. For example, ...
3
votes
1answer
20 views

Formatting output

This code has loops under loops which affects the performance badly. Please help me to optimize the code to improve its performance. ...
6
votes
2answers
65 views

Find element in sorted matrix

Find an element in a MxN matrix where each row and column is sorted in ascending order. Any comments on my code? (I added some test cases on non square matrices which I did not copy here) ...
11
votes
0answers
72 views

Project Euler #54 - Poker Streams

This challenge posted by Durron597 intrigued me, and inspired me to answer his question, and also to determine whether a more functional approach was available for poker hand ranking. The problem ...
1
vote
0answers
46 views

Minimum amount of edges that needs to be traversed to visit all vertices… or something like that

So I have this problem, where I'm given m connections over n vertices. The vertices are labeled ...
10
votes
3answers
175 views

Empty Line delimiter, single line output

I'm used to only processing, at most, one line of a file at a time. This is my first time changing the delimiter, and the objective here is to take a file containing lines such as: ...
-2
votes
0answers
16 views

How do I make my battleship code work properly with the shown methods? [on hold]

PROMPT: DROPBOX LINK Basically the user needs to place 3 ships using row, column then orientation, the ships then show up as "S", misses as "m", hits as "X", and water as "-" My problem is my array ...
4
votes
1answer
49 views

Designing a Variable Set

In my application, I need to allow the user to store variables. Variables can only be of specific types, but I effectively handle all variables the same way no matter the type. I would also like to ...
1
vote
0answers
15 views

Handling output and exit codes of processes

For a large, multi-threaded video processing application, I need to manage various child processes. I need to monitor their stdout and stderr. My key concerns: I should not have any spin loops. I ...
4
votes
1answer
57 views

Project Euler #54 Solution Follow-up

This is my second solution to Project Euler #54.. You can find the original post here. Brief problem summary: The file, poker.txt, contains one-thousand random hands dealt to two players. Each ...