Tagged Questions

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)

0
votes
0answers
10 views

Slot machine: writing user's name/score to txt file in Java [on hold]

I'm really (really) new to Java, and I'm trying to include a feature in my slot machine program that writes the user's name and score to a txt file so that when the user selects option 2, they can ...
3
votes
1answer
36 views

Percentage based drop prize on Mob entity kill

I have created a simple percentage-based random prize drop for killing certain mobs. A drop is basically what the player will get in return for killing a mob, as a reward. So I have a large list of ...
-2
votes
1answer
28 views

Checking if the octal conversion of a number is a palindrome [on hold]

The program will output 1 if the number is a palindrome, or -1 if not. ...
-2
votes
0answers
20 views

Linked Lists in Java [on hold]

For some reason the add(int) method isn't working and I don't know why. my output is: How many suitors are there? 5 null null null null [1] 5 Process completed. ...
6
votes
2answers
158 views

Synchronous and asynchronous methods in a client library

I am working on a library in which I need to make synchronous and asynchronous method in my client library. My library does this: The customer will use our library and they will call it by passing ...
5
votes
1answer
28 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 ...
-1
votes
0answers
11 views

Trinary Tree - Java [on hold]

Hello Everyone I have worked on the trinary tree problem insert and delete, can anyone look at it and tell me how it is. source code for that can be found at here: ...
-3
votes
0answers
23 views
2
votes
3answers
83 views

Craps game: breaking a single method to more than one

Below is a long messy one method code for a craps game. The user can play the game multiple times and has the option to quit when ever they want. How could you break this code down into different ...
0
votes
1answer
78 views

Where would you choose an interface over an abstract base class, when defining a hierarchy?

We have numerous threads talking about the usage of interface vis-a-vis abstract class Taking reference of an answer, given by ...
-3
votes
1answer
78 views

High - Low Number Guessing Game

I'm learning how to code in java and i decided to re-write a program made in c++ into java. All feedback is welcome. Here is the original prompt: This program generates a pseudo-random number ...
0
votes
0answers
20 views

Improve my High-Low Game in Java? Novice coder. All feedback welcome [duplicate]

I'm learning how to code in java and i decided to re-write a program made in c++ into java. All feedback is welcome. Here is the original prompt: This program generates a pseudo-random number between ...
2
votes
1answer
19 views

Detaching logic from listener implementation in “Smart UI” approach to follow a proper pattern

I took this code segment from existing source on Android, but it applies to anything from ASP.NET Forms to anything else where the UI has an event callback, and the logic is implemented directly in ...
4
votes
0answers
48 views

Can we now `implement Singleton` using Java 8?

After my success with extending enum - I thought I would try to make Singleton creation as simple as possible since Java-8 makes ...
0
votes
0answers
18 views

ArrayList contains wrong type objects without explicit raw-type casting [on hold]

Can anyone suggest how given code could possibly result in such issue, giving occasional ClassCastException when data is parsed from file. Details : I have a ...
0
votes
0answers
30 views
1
vote
0answers
28 views

MinCostMaxFlow implementation is not fast enough

I'm trying to solve this problem: A root tree is a directed acyclic graph that contains one node (root), from which there is exactly one path to any other node. A root tree is binary if ...
6
votes
3answers
547 views

Making this palindrome tester more efficient

This program takes lines of input. The first line is an int specifying how many further lines will be input. For the following lines (comprised of characters a-z), it will be determined whether ...
5
votes
2answers
77 views

Converting fractions to mixed numbers

I've been making a program for an assignment that converts fractions to mixed numbers, and I'm done, but I was wondering if I could simplify it in any way, since it seems quite complicated right now. ...
0
votes
0answers
33 views

Swing JButton: correct way to add action listener?

I'm aware that there are existing questions about JButtons, but I haven't found anything that's asking exactly what I'm trying to figure out. I inherited a Java project that has a horrible structure; ...
4
votes
3answers
309 views

Having two abstract (static inner) classes within the interface they implement

Is it wrong? Should I have these 2 classes in separate files? ...
3
votes
1answer
67 views

App to give cigarettes through the day

I have this app, that gives you cigarettes through the day, with equal intervals from one another. These are some important variables: wakeUp - is the time, when ...
0
votes
0answers
14 views

Getting IOException while connecting to SOLR server from Spring Web Services [on hold]

I have been struggling to find a solution to this problem which I have tried to explain here. Would really appreciate some ideas that I could try, to fix this. We have Spring Web Services with ...
2
votes
2answers
40 views

Optimizing Sieve of Eratosthenes for larger numbers

I am having difficulty optimizing my code for the Sieve of Eratosthenes. The code works fine for smaller numbers (up to 10,000) but takes a long time to run for numbers over 100,000. ...
0
votes
0answers
23 views

AsyncTask which allows to handle exceptions on UI

The AsyncTask available in android, gives you the result from doInBackground on the UI thread so that you can update UI ...
-2
votes
0answers
31 views

How to use Methods to Make It More OOP [on hold]

There is a discussion among my friends. We have a action class which responsible for making password control and other operations. While making this; there are two ways to perform this Which one is ...
6
votes
3answers
76 views

Preconditions library

Over the past year I've quietly developed a library for checking method preconditions. The project is hosted at https://bitbucket.org/cowwoc/preconditions/ I would like to get your feedback on the ...
-1
votes
1answer
66 views

Java interview code [on hold]

I was curious to anyone's thoughts, comments, and input as to something I was presented with during a job interview I went to recently. I was provided with some java code and asked to determine what ...
4
votes
2answers
874 views

“Computer guesses my number” game

In this exercise I have to do this: Modify the program so that no matter what number the user thinks of (1-100) the computer can guess it in 7 or less guesses. I'm just a beginner in Java and ...
0
votes
1answer
48 views

Efficiently serialize big JSON using GSON without loading everything in memory?

Below is my JSON in which I have only three reportRecords just for demonstration purpose but in general sometimes we are getting pretty huge json, then it doesn't ...
0
votes
0answers
34 views

Database assignment with MySQL and Swing

I have completed this assignment from Stanford CS108 on MySQL and Swing (it's part B). And it would be wonderful if someone could point out my week spots in code and overall design. I have uploaded ...
0
votes
1answer
69 views

Converting Ocean to RunLengthEncoding object

For the problem statement shown below: Part II(b): Your run-length encodings will only be useful if other classes have the ability to read them after you create them. Therefore, implement the ...
4
votes
2answers
67 views

Rotating an array by position n

Input is 1,2,3,4,5,6,7,8 If rotateOrder = 2 Output should be 7,8,1,2,3,4,5,6 If rotateOrder = 3 Output should be 6,7,8,1,2,3,4,5 Here is my program to do it: ...
2
votes
2answers
50 views

Handling thread interruptions in a directory iterator

This code is code written on a whim to help $someindividual asking for such a thing on $somechatmedium; what is needed is a way, ...
5
votes
1answer
102 views
+50

Efficiently using ZeroMQ sockets in Java

I am working on multithreading project and I am using ZeroMQ socket to send the data as a byte array. Below is my example which works fine. I'm opting for code review to see whether it can be improved ...
1
vote
2answers
71 views

Proper way to wait end of a service and singleton design

My code works fine and I would like to know if I chose the best strategy to implement my code, or if It can written better (more fast, more clear, best use of design pattern, etc). In my android ...
4
votes
3answers
173 views

Is this a good way to implement a tile map from a text file?

I'm working on a small final fantasy type game. I have this for a tile map. I was just wondering if this is a good way to do this or if anyone has any suggestions, I would love to read them. ...
1
vote
0answers
15 views

Updating OpenGL version to 4.1 (LWJGL)

I have a 2D rendering system that's working (for the most part). I want start making use of shaders to implement transformation, rotation, scale, etc., and I want to do it using the latest version of ...
1
vote
2answers
56 views

Personal Minecraft Android app

This won't be released publicly, but that doesn't mean I want to have bad coding habits. I was not too far into this before realizing I could make it better. One of my main concerns is finding an ...
2
votes
1answer
71 views

Naming factories

Given the code below, I'm curious to know if you'd have better naming suggestions for types: VegetablePresentersFactory VegetablePresenterFactory It bothers me a bit that their names only differ ...
3
votes
2answers
33 views

Should I create an abstract runnable? I've 4 sub-classes which perform similar work but only 3 of them have identical constructors

I've added the code for an abstract thread class and 2 sub-classes. The structure and job of the threads (sub-classes) is identical except one difference: ONE of ...
3
votes
3answers
172 views

TimeZone computing method

I feel like there is a code smell in this. Can someone help me to refactor/optimize it? ...
0
votes
0answers
248 views

Length of longest distinct characters subsequence [closed]

I want to find the length of the longest distinct characters subsequence. If the logic is correct is there any way to make it more optimized? What would be the limit on the size of the string up till ...
4
votes
3answers
55 views

Regex to find addresses and phone numbers

I am trying to optimize my Java code where I am parsing an address field. Address fields have the format: ...
1
vote
2answers
68 views

Long methods in background task

My code in my main background async task is a mess. Everything is everywhere. I'm afraid of moving things around without something breaking but I definitely think it needs work. What I can do to ...
-1
votes
0answers
45 views

Read chunks of data [closed]

I'm a complete beginner to intermediate programming. I have tried using PHP and Java to parse a CSV file and process the links stored within it line by line. From my understanding, reading a large ...
0
votes
0answers
18 views

Getting the natural log of a factorial [closed]

I have this code which calculates the factorial of a number and then gets the natural log of that number, however: the output keeps saying NaN ...
3
votes
0answers
43 views

Fuzzy database search - code and logic

I'm writing a Java Servlet application where the users must enter information about a business. I'd like to prevent as many duplicate entries in the MySQL database as possible and I'd appreciate ...
6
votes
2answers
67 views

Loading card data from XML file

For our Cardshifter Project we wanted to be able to load card definitions from file. A card is defined as: Having an unique id. Having a set of resources, which are integers identified by a string. ...
4
votes
2answers
29 views

Convert impute2 files to mach format

Here is a program for converting Impute2 files into MaCH format (related to genetics). Source files include one xxx_haps file and one xxx_samples file, for example: ...