Questions tagged [java]

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 bytecode and run in a virtual machine (JVM) enabling a "write once, run anywhere" (WORA) methodology.

Filter by
Sorted by
Tagged with
1
vote
1answer
590 views

Refactoring conditional statements among different classes

I wonder there is any method of refactoring nested condition. It's just the same content with different contents and different classes which looks bad. I really want to reform this code which looks ...
1
vote
1answer
783 views

NBA*: Very efficient bidirectional heuristic search algorithm in Java - follow-up

This post elaborates on NBA*: Very efficient bidirectional heuristic search algorithm in Java. I have made the following changes: Added an explicit type for representing digraph paths: ...
20
votes
3answers
2k views

Writing better JUnit tests

I am using Spring Framework, Hibernate and JUnit. I am testing persisting of a UserEntity. The UserEntity has the following associations: ManyToMany - City ManyToMany - ActivityCategory ManyToOne -...
15
votes
3answers
1k views

Trading Card Game's Hand class and tests

As part of a Trading Card Game, I have created a Hand that will need to hold all cards that a player currently has in his hand. The code is built using Java 8. The ...
12
votes
2answers
592 views

Finding a word within a pre-defined set using a search string with wildcards

The other day I was intrigued by this question (originally from here): Write a program that answers YES/NO search queries containing * placeholders. Example: if the data you have is (hazem, ahmed,...
11
votes
2answers
3k views

Rock Paper Scissors Lizard Spock as a code-style and challenge

The following is a program that lets a Human play "Rock Paper Scissors Lizard Spock" against the computer... (almost playable at: http://ideone.com/EBDlga) Note I have posted a follow-up question ...
11
votes
5answers
366 views

First missing positive with only primitives

As soon as I saw the First missing positive question, I decided to write my own method for this before writing my review on the question. Judge me by the same standards as bazang wants to be judged, ...
11
votes
1answer
236 views

Binary Bayes network classifier in Java - Part I/II

I was working on the binary Bayesian network classifier I asked about earlier. See also Part II/II. See also the next iteration of Part I. TERMINOLOGY We are given a directed acyclic graph (dag) \$...
11
votes
1answer
480 views

Ultimatoe — 1. GUI and general game interfaces

For the community challenge, I wrote ultimatoe. For me, the most interesting part is clearly the AI, but what I did so far is just a stupid Monte Carlo tree search, which isn't ready for a review yet (...
11
votes
1answer
129 views

YAuB - Yet another Micro Benchmark

Note -> Follow-on question posted here: YAuB - Micro Benchmark Follow-on I recently answered this Beautiful String question, where the task is to maximize the value of a string by assigning each ...
10
votes
5answers
3k views

Efficient FizzBuzz

I wrote the following Fizz Buzz program. How can I improve it or make it more efficient? ...
9
votes
2answers
1k views

Simple calculator that seems inefficient

I have a simple calculator program that needs some reviewing. Is this as efficient as it can get, or is there a better way? ...
8
votes
1answer
232 views

Simulating a GUI windowing system

I was eager to learn the implementation details behind windowing GUI systems. Because I am mostly a high level programmer having not much experience in low-level stuff, I had to simulate it instead of ...
7
votes
1answer
321 views

Model simulation using Java annotations

A couple of days ago I posted my code that models systems made up of moving parts. I got several great tips and ideas and here is my latest version. My actions are now methods annotated with @Action (...
7
votes
3answers
353 views

Having full atomicity against all the threads without impacting performance or throughputs

I am working on a project in which I construct a URL with a valid hostname (but not a blocked hostname) and then execute that URL using RestTemplate from my main ...
7
votes
1answer
607 views

Are AVL trees equal?

I was inspired by this answer and decided to implement an AVL tree with the methods equals and hashCode as if I was asked to do ...
7
votes
1answer
335 views

Onion Run Festival (or the unexpected anagram for Union of Intervals)

Original question: Union of intervals In the original code, the Interval model class implements Comparable so that an input of <...
6
votes
1answer
3k views

Determining winner and winning hand in poker (holdem)

I wrote couple classes that calculate winner, winning hand and winning hands rank (straight, flush, fullhouse etc.). I searched for something similar, but only found posts where five cards are used, ...
6
votes
2answers
504 views

Integer Partition using an iterator

I tried implementing Integer Partition (enumerating all possible sets of whole numbers whose sum is a given integer). Looking at @rolfl's answer, I reasoned that with a stack data structure, we ...
6
votes
1answer
2k views

An iterator returning all possible permutations of a list in Java

I have this class that iterates over all permutations of an input list: PermutationIterable.java: ...
6
votes
2answers
122 views

IntModulus reloaded

As my question Modular arithmetic was hard to review and terribly long, I've added a few comments to the easier part, namely IntModulus. The code uses Guava and ...
6
votes
5answers
753 views

DP solution to min triangle path

I am studying for interviews for various companies. I wrote a solution to this problem, but if an experience programmer looks at it I am sure there are certain areas the code can be made in to a more ...
5
votes
3answers
5k views

Find the missing number in a array

I'm working on a personal project to practice my programming skills and I came to this problem. I tried to create a program that will find the missing number in a array. I'm looking forward to ...
5
votes
2answers
78 views

A tiny library for textual serialization of lists in Java - follow-up

See the previous and initial iteration. See the next iteration. I have mainly refactored the code and made it a little bit robust (if serialization of a single object produces a string with new line ...
5
votes
1answer
159 views

Triangulate the divisors and divide the triangulars

Project Euler 12 - Highly divisible triangular number The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be \$1 + 2 + 3 + 4 + 5 + 6 + 7 = ...
5
votes
2answers
126 views

Tracking Containers in a Train Station

This is a time line for control over the events of some containers in a train station. It gets all the data to build the time line by getting a JSON from a database via REST service. The app resets ...
5
votes
4answers
953 views

Project Euler #1 in Java

Project Euler #1: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 ...
5
votes
1answer
74 views

A tiny library for textual serialization of lists in Java - follow-up 2

See the previous iteration. See the next iteration. I emphasized the fact that serialization routine may not return a string with new line character by using more or less explicit identifier. Moved ...
5
votes
2answers
456 views

Multi-threaded domain status checking in Java

I'm tinkering with the idea of crafting a search engine in my spare time. More of a learning experience than anything at this point, but still a project. A key aspect of this system is checking ...
4
votes
1answer
120 views

An Update on my TileMap Class

I'm making a old-school Final Fantasy type game and I made a tile map class a while back and posted it on here (Is this a good way to implement a tile map from a text file?) But, when I got to ...
4
votes
2answers
824 views

Calculate Geometric and Arithmetic Mean

I am trying to make general class to calculate Geometric mean using exponential of the arithmetic mean of logarithms , and Arithmetic Mean. I am looking for some general feedback on how I can improve ...
4
votes
1answer
160 views

Video playlist interface in Swing

I wrote this piece of code for a GUI i am making, which is a playlist interface. I was wondering if I could write all of this code out differently, but to the point where it functions exactly the same,...
4
votes
1answer
407 views

Copy File, remove spaces in specific lines

This question now has a follow-up question 1 and follow-up question 2 As an exercise in writing decent code and because I learn best by example, I wrote this program and would ask for a review so ...
4
votes
2answers
166 views

Find sum of number of times that each character of source occurs in the target

I wrote the following code in response to this question "find sum of number of times that each character of source occurs in the target", is there any better solution for it? Analysis ...
3
votes
1answer
300 views

Custom component organization system

I'm rewriting an old Swing project that I did a few months ago, a fairly simple copy-cat of MS paint. I've been doing a pretty good job of keeping the code maintainable and organized, but I've hit a ...
3
votes
1answer
116 views

Find common “characters” in 2 given strings (rev2)

Could you help me further improve this code, which includes some feedback from this site already (Find common "characters" in 2 given strings (rev1))? I have rewritten the code below, ...
3
votes
2answers
252 views

BigRational based on BigIntegers

For Project Euler I've implemented a BigRational. The functionality is rather limited, just things I needed or will probably need soon. The style departs a bit from ...
3
votes
2answers
217 views

Computing even huger Fibonacci numbers in Java - follow-up

See the previous and initial iteration. I have incorporated almost all the suggestions by Peter Taylor: The actual method returns a BigInteger instead of ...
3
votes
2answers
148 views

Follow-up 1: Copy File, remove spaces in specific lines

This Question now has a follow-up question After learning a lot about applying OO principles, interfaces and a bit about argument-handling I post a revised version of my previous code. This is still ...
3
votes
1answer
2k views

Simple data structures for representing graphs in Java

Motivation I do a lot of graph-theoretic code, and, by now, I feel substantial need for data structures that can represent weighted graphs, both directed and undirected. Up till now, I was in a habit ...
3
votes
1answer
89 views

Follow-up 2: Copy File, remove spaces in specific lines

This is an iterative review: The Original Question | Follow up 1 Differences to Follow up 1 This iteration tries to take the previous review to heart and see how it turns out. It sacrifices the ...
3
votes
1answer
122 views

Refactoring RadioGroup setter code?

I am setting different RadioGroup like this: ...
2
votes
3answers
1k views

Find all triplets in array that add up to a given sum

Given an array and a value, find all the triplets in the array whose sum is equal to the given value. For example, if the given array is {12, 3, 4, 1, 6, 9} and the ...
2
votes
4answers
3k views

Detect if a tree is complete binary tree

Detect if tree is complete binary tree. This question is improvement over previously asked here. Looking for code-review, optimizations and best practices. Verifying both space and time complexity to ...
2
votes
1answer
451 views

Guess how many are in the jar game in Java

I'm reading up on java and have completed a fairly simple console game. I'm unsure on my own structure when considering maintainability, separation of concerns and best practices. Any tips or ...
2
votes
1answer
3k views

Delete nodes in linkedlist whose next node is greater

Given a singly linked list, remove all the nodes which have a greater value on right side. Examples: a) The list 12->15->10->11->5->6->2->3->NULL should be changed to 15->11->6->3->NULL. ...
2
votes
2answers
3k views

String 'expanding' - reinserting repeating characters

The challenge: Given a String, for each digit in that original string, replace that digit with that many occurrences of the character following it. So a3tx2z yields ...
2
votes
1answer
227 views

Date validation in Java

I'm learning Java, and would really appreciate any tips on how to improve this code. It's just a simple date validation class. ...
2
votes
1answer
158 views

Date validation in Java - take two

I read through and implemented the advice I received yesterday. I would, once again, really like some input on how this can be improved. e.g. encapsulation, interfaces, abstract classes etc.. Right ...
2
votes
1answer
381 views

3D bin packing in Java

I made some changes to the first code here I wrote and I want to know which one is more correct logically (before the changes or after the changes). It's really hard to manually test these kind of ...