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
7 votes
5 answers
11k views

Creating a numeric phone keypad

I'm writing a Telephone class and it has a method called getDigits which takes in a String parameter and returns the number that would appear on your phone if you ...
user84682's user avatar
7 votes
1 answer
479 views

Brainfuck Interpreter: Slower than a Snail?

Inspired by FizzBuzz by Brainfuck, I decided to write an interpreter for Brainfuck. It: Removes all non-command characters Optimizes commands (removing +- and <...
TheCoffeeCup's user avatar
  • 9,454
7 votes
2 answers
1k views

Lock for preventing concurrent access in client data

I am trying to implement lock by which I don't want to have reads from happening whenever I am doing a write. Here is my ClientData class in which I am using ...
arsenal's user avatar
  • 2,167
7 votes
1 answer
3k 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: ...
coderodde's user avatar
  • 28.1k
7 votes
1 answer
344 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 (...
uros calakovic's user avatar
7 votes
1 answer
442 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 <...
h.j.k.'s user avatar
  • 19.2k
7 votes
3 answers
6k views

Fast alternative for String.split by whitespace

After profiling of one project I've found a bottleneck in the code, specifically the line: String columns[] = line.split("\\s+"); I've tried to find a workaround,...
Stan's user avatar
  • 211
7 votes
3 answers
3k views

Guess number game

I'm making a simple guess a number game. In game, user should input minimum and maximum value and program should generate random number between this numbers, later user should try and guess the number....
Goran B's user avatar
  • 177
7 votes
3 answers
5k views

Java Tic-Tac-Toe game (implemented through MVC)

After seeing Tic Tac Toe in MVC, I attempted to create something similar. My program uses the Swing library and it's relatively simple. When I run the game, it's just a 3x3 grid with no extra features....
Chau's user avatar
  • 225
6 votes
1 answer
1k views

Efficient top k words using MultiMap (Google Guava ext lib JAR)

Basic algorithm: Open document/huge text file Use Map and List to separate the words. \$O(K)\$ time complexity (TC) considering ...
JustVirtually's user avatar
6 votes
1 answer
4k 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, ...
Townsheriff's user avatar
6 votes
2 answers
580 views

Improved Van Emde Boas tree based map in Java

After working on Van Emde Boas tree -based map in Java, I came up with this code. I managed to fix the bugs and improve the performance by using internally primitive integers instead of wrapped ...
coderodde's user avatar
  • 28.1k
6 votes
2 answers
3k views

Producer/Consumer implementation

I am using Netty embedded within Grails to process and display incoming SNMP messages. Since Netty 4 doesn't come with a built-in ChannelExecutionHandler I had to ...
Diljot R's user avatar
6 votes
5 answers
824 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 ...
Mark Isenberg's user avatar
6 votes
1 answer
1k views

Missing level of technical depth (Recursive to Iterative)

I recently have given a coding test in a reputable IT company. There were three coding questions. They refused me by saying that as we felt they didn't demonstrate the level of technical depth we'...
AAhad's user avatar
  • 409
6 votes
6 answers
627 views

Beginners Java calculator

I am a beginner in Java programming, and I created a calculator as my first Java project. Therefore, can you review my code and provide feedbacks/ tips? ...
SweetBubbleTea's user avatar
6 votes
2 answers
140 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 ...
maaartinus's user avatar
  • 13.5k
6 votes
2 answers
2k views

Implementation of a graph in Java

A long time ago I posted my implementation of directed graph is Java. Recently I took a look at @coderodde's implementation and decided to write an implementation of undirected graph and directed ...
Maksim Dmitriev's user avatar
6 votes
2 answers
592 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 ...
200_success's user avatar
6 votes
2 answers
10k views

Kruskal's algorithm in Java

I have this Java implementation of Kruskal's algorithm. It solves a tiny problem instance correctly, yet I am not quite sure, whether my implementation is correct. The code as follows: MSTFinder....
coderodde's user avatar
  • 28.1k
6 votes
3 answers
2k views

Missing level of technical depth (Flatten Tree)

I recently have given a coding test in a reputable IT company. There were three coding questions. They refused me by saying that as we felt they didn't demonstrate the level of technical depth we'...
AAhad's user avatar
  • 409
6 votes
5 answers
5k views

Long switch statement to lookup fifty-something commands

I have a very long switch statement which is expected to have nearly 50-55 cases. ...
pointer's user avatar
  • 179
6 votes
3 answers
2k views

Optimizing unique partitions of integers

I am working on a project involving the unique partitioning of integers. I.e. I am looking to have all of the partitions of n = x1 + x2 + x3 + ... + xk, where xi = xj implies i = j. For example, if I ...
Sam Blitz's user avatar
  • 213
5 votes
2 answers
487 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 ...
ndm13's user avatar
  • 718
5 votes
1 answer
80 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 ...
coderodde's user avatar
  • 28.1k
5 votes
3 answers
434 views

Karp-Rabin String Matching, Part 2

Part 1 is here. I wrote a Java implementation of the Karp-Rabin semi-numerical string matching algorithm. I incorporated the suggestions of @fge and @maaartinus from the other question into my new ...
tsleyson's user avatar
  • 980
5 votes
4 answers
1k 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 below ...
TheCoffeeCup's user avatar
  • 9,454
5 votes
2 answers
88 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 ...
coderodde's user avatar
  • 28.1k
5 votes
2 answers
148 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 ...
Vhalad's user avatar
  • 91
5 votes
3 answers
998 views

Prime number util class

A prime number util, which provides 3 APIs - find the nth prime, find the next prime, and find all primes up to n. I must admit this code has been influenced a lot by discussions here. I'm looking ...
JavaDeveloper's user avatar
5 votes
1 answer
191 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 = ...
Simon Forsberg's user avatar
5 votes
3 answers
6k 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 ...
Yodism's user avatar
  • 751
5 votes
1 answer
4k views

Android SQLite Database management

I'd like some opinions about my approach at using SQLite databases in android. Everything seems to work very well, but there may be something wrong that I hadn't noticed. I don't like working with ...
Apperside's user avatar
  • 151
5 votes
4 answers
2k views

School grading string calculator

For my training, i've been given an assignment to build a simple, extendable 'grade' String calculator by a given grade. For now, I had to work by this table: When the ...
Bas's user avatar
  • 699
4 votes
1 answer
946 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 ...
Philipp Doerner's user avatar
4 votes
2 answers
1k 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 ...
Eslam Ali's user avatar
  • 433
4 votes
1 answer
429 views

Guess how many are in the jar game in Java - Take 2

Original question can be found here I took the advice I got to heart, and re-wrote it. Once again I'd appreciate any advice as to how I can improve this using best practices. Jar.java ...
Nilzone-'s user avatar
  • 1,426
4 votes
1 answer
510 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 line ...
durron597's user avatar
  • 918
4 votes
1 answer
146 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 ...
Twiggy's user avatar
  • 333
4 votes
2 answers
178 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 ...
Jack's user avatar
  • 381
4 votes
1 answer
218 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,...
wavekootah's user avatar
4 votes
0 answers
79 views

Print columns of text without hard coding the width (attempt 5)

If you'd like to print this: ...
candied_orange's user avatar
4 votes
1 answer
2k views

Sudoku-Solver with GUI in Java

I've wrote a Sudoku-Solver in Java, which also contains a GUI, so you can just enter the Sudoku, press "OK" and it will solve the Sudoku using backtracking. Here's the code: ...
user avatar
4 votes
1 answer
75 views

Webscraping tennis data 1.1

I incorporated the substantial changes suggested in my previous question that involved building a web-scraper for gathering tennis data. The improved code is shown below: ...
cloudy_eclispse's user avatar
3 votes
1 answer
325 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 ...
hasherr's user avatar
  • 317
3 votes
1 answer
149 views

follow-up - caesar-cipher - java

I now processed the suggestions you can find here. I've deleted some duplications and corrected some other minor mistakes. Here's the code: ...
user avatar
3 votes
1 answer
244 views

Sudoku-Solver - follow-up

I've now tried to use the suggestions you can find here to improve my Sudoku-Solver. Here's the updated code: ...
user avatar
3 votes
1 answer
284 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. ...
Nilzone-'s user avatar
  • 1,426
3 votes
2 answers
357 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 ...
maaartinus's user avatar
  • 13.5k
3 votes
1 answer
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 ...
coderodde's user avatar
  • 28.1k

1 2
3
4 5
21