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
39
votes
2answers
1k views

Brainfuck to x86 Assembly Compiler

After my Brainfuck Interpreter written in x86 Assembly I decided that it was time to get to the next step, writing a Brainfuck Compiler in Java that generates x86 Assembly and compiles that to an ...
28
votes
4answers
2k views

Just a lowly counter that turned out to be surprisingly complicated

While writing this review, I saw a need for a Counter object similar to Python's. It seemed like it would be easy to write such a class, but it turned out to be ...
21
votes
4answers
18k views

Reverse words in a given String

I'd like this code to be improved Input string: codereview is awesome Output string: awesome is codereview My approach: ...
19
votes
2answers
4k views

Designing another Coffee Machine Application

After reading Designing a coffee machine yesterday, I decided I could also give the same problem a try. I have used the following problem statement (copied from the given question): Design a ...
19
votes
5answers
3k views

Print the N longest lines in a file

I have implemented the "Find the N longest lines in a file" problem from CodeEval quoted below. I got a full 100 score and 182ms execution time of their data set on the site so I consider the code ...
17
votes
3answers
2k views

Pokemon type evaluator

I thought I would apply what I learned to make something fun. Its purpose is to type check Pokemon, for anyone familiar with the series. It mostly works but I have two concerns: Sometimes you write ...
15
votes
1answer
4k views

Streaming H264 video from PiCamera to a JavaFX ImageView

I'm currently working on a robotics application where a video feed is being displayed from a Raspberry Pi 3. I've been working on a way to stream the video directly into JavaFX (the rest of the UI is ...
15
votes
2answers
419 views

General Game Loop 3.0

Follow up from General Game Loop 2.0 It has been quite a while. Some major changes involve: Removed dependancy on Swing. The more I read up on Swing, the more I understood it was meant for handling ...
13
votes
3answers
6k views

MMO Game Server

I've been building an MMO in Java for a game that will have clients built with libGDX. I have already built clients for the browser, desktop, iOS, and Android. To accommodate multiple platforms, ...
12
votes
4answers
42k views

Merge Sort an integer array

I've implemented merge sort an integer array. Is it okay to use i,j,k as variable name for looping? Should I change them to more meaningful names? Overall, any further suggestions on this code? ...
11
votes
3answers
3k views

Customised Java UTF-16

I have implemented customized encoding mechanism for javaUTF16. Does this implementation support all the characters? ...
11
votes
7answers
22k views

Reading Large Files in Java getting really slow

I am trying to read a large file ~200 MB (~300 million lines of text). I am using a relatively standard way of reading like: ...
11
votes
2answers
2k views

Parsing log files of HearthStone: The API

I am working on a parser that can parse log entries from a game called HearthStone, the overall idea is that it will read the log file live when the game is running, parses the log file and show ...
11
votes
5answers
591 views

FiniteArrayQueue type with interface and unit tests

Doing some exercises on basic data structures, I learned about queues, and decided to roll my own to better understand how a basic queue can function. As the name indicates, this Queue is made from a ...
10
votes
1answer
1k views

Simple wildcard pattern matcher in Java

I have built a simple wild card pattern matcher algorithm. I am concerned where it can be improved. Main concern is algorithm. Any other improvements are welcome too. What it should does: ...
10
votes
3answers
256 views

Getting funky with Pi

Push a button and an LED lights up1 and sends a signal to another computer that plays a song. First project on the Raspberry pi, really simple but definitely fun and educational to implement. Also, ...
8
votes
4answers
15k views

Find the subarray with the max sum

In an interview I was asked to solve the following problem: find a subarray with max sum I have written a piece of code for the same. I need your help in reviewing this code. ...
7
votes
2answers
7k views

External / File-based mergesort

I've implemented an external mergesort to sort a file consisting of Java int primitives, however it is horribly slow (fortunately it does at least work). Very little happens in the sort method: it ...
7
votes
4answers
9k 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? ...
7
votes
7answers
4k views

Sum of the digits is prime or not

Puzzle Description: A number is called lucky if the sum of its digits, as well as the sum of the squares of its digits is a prime number. How many numbers between A and B are lucky? How can I ...
6
votes
2answers
543 views

System for registering people

For a small administrative program, I have to be able to register people and their data. But, files are sometimes created through a phone call "on the fly" and then later certain data is added to the ...
6
votes
1answer
2k views

Karp-Rabin string matching in Java

I wrote an implementation of the Karp-Rabin string matching algorithm in Java 7, based on the discussion in Section 32.2 of Introduction to Algorithms (CLRS). Clearly, I need more experience with ...
6
votes
1answer
10k views

Counting inversions

Inversion Count for an array indicates – how far (or close) the array is from being sorted. If array is already sorted then inversion count is 0. If array is sorted in reverse order that inversion ...
5
votes
3answers
264 views

URLEncoder implementation

I'm looking for feedback on my URLEncoder implementation, which is a drop-in replacement for Apache Tomcat's URLEncoder. It was ...
5
votes
5answers
10k views

DFS in Binary Tree

I have written this code for DFS in a binary tree and would like improvements on it. ...
5
votes
1answer
19k views

Base generic DAO to work with different POJO classes

Right now, I have base abstract GenericDAO class to execute CRUD operations with different kind of objects. I have Customer and Employee POJO classes which are used ...
4
votes
1answer
1k views

Second attempt at a Blackjack game

I posted yesterday about my first attempt at a Blackjack game. After I received much helpful advice I tried my best to fix up my code. I was wondering what you would think about round two! Edit: I ...
3
votes
3answers
6k views

Sherlock and Anagrams

Given a string S, find the number of "unordered anagrammatic pairs" of substrings. Input Format First line contains ...
23
votes
3answers
3k views

Parsing log files of HearthStone: The log reading API

I'm still working on a parser that can parse log entries from a game called HearthStone, the overall idea is that it will read the log file live when the game is running, parses the log file and show ...
23
votes
3answers
6k views

Java Inventory System

I'm often applying to jobs just to test out my skills. I have recently applied to one, had to submit a Java problem, but got rejected. Could someone please review my application briefly and tell me ...
19
votes
3answers
262 views

Translating the Rubberduck - Übersetzen der Gummiente - Part 1: Modelling

So I have committed to making a German translation for the guys over at Rubberduck, which is localized via .resx files. Now these files are basically XML-Files with a certain, rather simple document ...
18
votes
2answers
4k views

Retro Rocket ASCII Art

Inspired by Nested for-loop ASCII art, I looked at building a more complicated ASCII art than just the normal 'diamond' and 'triangle' variations that crop up occasionally here. The challenge: ...
17
votes
5answers
6k views

Using sounds in Java

I'm trying to apply sound today, and the goal in mind was a simple violin tuner. The actionListener seems repetitive/ How might I optimize it (what I tried just ...
16
votes
2answers
4k views

Shamos-Hoey algorithm for checking the self-intersection of a closed shape

I implemented the Shamos-Hoey algorithm to check if a closed shape is self-intersected. Is this algorithm ok in terms of performance? ...
15
votes
3answers
12k views

Finding pair of sum in sorted array

In a sorted array, I am trying to find pairs that sum up to a certain value. I was wondering if anyone could help me improve my code in performance or memory. I believe my code is O(n). If there are ...
14
votes
1answer
9k views

Printing a Binary Tree top-down (column wise)

We have a binary tree, suppose like this: 8 / \ 6 10 / \ / \ 4 7 9 12 / \ 3 5 We have to print this binary tree in top-down ...
12
votes
2answers
2k views

Ultimate Tic Tac Toe A.K.A. Tic Tactics

My attempt at this challenge., incorporating lessons from this question, which turned out into a much bigger project than I anticipated, but it works. I'll definitely be refactoring most of this in ...
12
votes
4answers
28k views

Number aware string sorting with comparator

I have this class for use in sorting strings such that if strings have a number in the same position it will order the numbers in increasing order. Alphabetical gives: file1 file10 file2 What I'm ...
12
votes
4answers
4k views

Gravity model for a simulator

I am designing a planetary system simulator. The coordinates used are standard for JPanel (0,0 in the upper left corner). My model is based on a class Body: ...
11
votes
5answers
3k views

Prime Number Sieving Algorithm

Last semester in my Masters Program I developed this code for sieving. My professor wants me to write a report that he might use locally within the school, but I feel like I've done nothing that new, ...
11
votes
4answers
2k views

Project Euler #1 efficiency

I've started solving Project Euler problems. Is the code completely optimized? Question: 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 ...
11
votes
5answers
3k views

Finding count of character occurrences in a string

I am taking an introductory course in java in high school, however I have some experience in python. I was tasked to find the number of times a character occurs in a string so I did this. ...
10
votes
5answers
3k views

Fraction class in Java

(See the next iteration.) I have this class for representing exact fractions. See what I have: Fraction.java: ...
9
votes
3answers
3k views

Simulation of an ocean containing sharks and fish

As part of my Java learning, I tried solving Part I of problem description here. The only issue that I see now is that I could not close the button of Frame. ...
9
votes
4answers
6k views

Convert IP address to its binary representation

For a recent lab at the university we had to match the longest prefix for an IP (v4) address by using a Trie data structure. The code works fine, but it takes about 2 minutes to load a 14 million-line ...
9
votes
2answers
8k views

Sudoku generator in Java

I have written this Sudoku Generator. How good/bad is this? How can I improve this? ...
9
votes
2answers
3k views

Codingbat maxMirror challenge

I request you to provide insightful suggestions to improve the following code as well as an alternative algorithm to solve it. Problem Specification: We'll say that a "mirror" section in an array ...
8
votes
1answer
810 views

Prefix trees for auto suggest

I wrote a quick prefix tree implementation. I know it may be far from perfect, but I need to make sure that I got the basics right. My main concerns are: Have I settled for the correct data ...
8
votes
4answers
2k views

A new type of builder pattern

The fact is that I wanted to apply the builder pattern. But this could not be achieved, since I could not create an instance of the class with an empty constructor - this is dangerous. The goal is to ...
8
votes
3answers
1k views

Quick Sort Implementation

I have written the below code for quick sort in Java: ...