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)

2
votes
1answer
18 views

Java Connect Four “Four in a row” detection algorithms

I am making a connect four type game for my end of the year project in my programming class. I am about to start building off of the console based version I have made and add a GUI, but I feel sort ...
4
votes
1answer
27 views

Three stacks in a single array

I have implemented three stacks in a single array in Java. Any advice on object oriented design, coding structure, logical part or any sort of advice would be appreciated. ...
3
votes
2answers
18 views

Thread Safe Servlet

I am working on a JSP MVC web application. I am confused about Thread-Safe Servlet concept. Following is my code, please tell me is it thread safe or not. Also, tell me the reason that why it is ...
0
votes
0answers
7 views

Getting data with Rxjava and retrofit

I am using rxjava with retrofit to get data from an api then filtering the data with for loop in the onNext Method. Is there anyway not to use the for loop and just use rxjava to filter or improve ...
4
votes
2answers
40 views

Counting from 0 to a number and back to zero, and space-padding the result to be a given length

I completed a task: The objective was to create a method with 2 arguments: a number to count to, and how many char/numbers in the resulting string. Result: Let's say that "number" is 5, so it will ...
1
vote
1answer
28 views

improved HibernateDao

I have this HibernateDAO.java Class: ...
5
votes
5answers
754 views

Fraction class in Java

I have this class for representing exact fractions. See what I have: Fraction.java: ...
0
votes
0answers
15 views

What wrong with my HeapSort method? [on hold]

I've written a generic heap sort method, which passes in an array and a comparator variable. I can't find out the reason why it's not working. When I call the heapSort method from a simple driver i ...
4
votes
3answers
223 views

Triangle calculator: calculate if it's a valid triangle and what type

This is my first program and I wanted to know if there was any way to improve the design or cut back on unnecessary coding. ...
4
votes
4answers
247 views

Data type detection for a CSV file parser

I am building a CSV file parser, and in order to get the appropriate Object to represent different data types found on the parsed files, I wrote the following function: ...
0
votes
0answers
22 views

Pangram test with non-ASCII characters [on hold]

Pangram Determine if a sentence is a pangram. Determine if a sentence is a pangram. A pangram (Greek: παν γράμμα, pan gramma, "every letter") is a sentence using every letter of the ...
1
vote
0answers
14 views

Handle GCM registration tasks

I have implemented Google cloud messaging in my mobile app following the Google docs. It seems I have a lot going on in my MainActivity class at this point. I'm ...
1
vote
0answers
18 views

Few DatePickers and TimePickers in Android activity

I'm developing an Android activity which asks user to enter start and end dates and times in order to know a certain period of time. After picking start date, user picks start time, and then he/she ...
2
votes
2answers
55 views

Fractional Knapsack in Java

So I solved Fractional Knapsack problem: There are n items in a store. For i =1,2, . . . , n, item i has weight wi > 0 and worth vi > 0. Thief can carry a maximum weight of W pounds in a knapsack. ...
-3
votes
1answer
52 views

Restricting (x, y) coordinates to be within 0 to 4800

Is there a way to write this if tree more elegantly? ...
3
votes
2answers
93 views

Slitherio Single Player

I made a single player slither.io game. Here are the features: You can speed up by holding down the mouse button. You can eat food and grow both in length and width. Only 100 food will spawn maximum ...
-4
votes
0answers
27 views

Code Refactoring [on hold]

How to Refactor the following code ...
2
votes
1answer
46 views

Finding the total time elapsed in the union of time intervals

Given a set of time intervals, I have to find the total time elapsed in the union of the intervals. Test Cases: ...
-4
votes
0answers
9 views

Recursive Base Conversion (Base 2, Base 5, Base 7, Base 8) Java [on hold]

I recently created a base conversion program for my java class and my teacher says I have errors with the program. Could anyone test this program and tell me what the errors are and how to resolve ...
1
vote
0answers
39 views

Binary search tree class in Java

I am trying to create a binary search tree class in Java and am wondering how I did. I am fairly confident on most of the methods, but fear I may have messed up the delete method. I know I am ...
1
vote
0answers
24 views

Delay handling of registrations

I'm trying to solve the problem of a whiteboard receiving registrations before, during and after its own initialization. As each registration needs a bit of handling which can happen only after the ...
0
votes
1answer
33 views

(Java) Dice Rolling Program GUI [on hold]

I am working on writing a small program for a game called "Turkey Trouble" that we did in my biology class. The game involves the rolling of two dice. The two numbers are then added and this number ...
-6
votes
0answers
29 views

reversing a strings in line [on hold]

My string is Input My mobile cost is morethan huawei Output: Mobile my cost is huawei more than My requirement is just i want to reverse the first two strings and reverse the last two strings ...
23
votes
7answers
9k views

Interview coding test: Fizz Buzz

I was recently given a coding test to complete for a potential client. It was a FizzBuzz-type of thing with a two-hour time limit. I had a request to write basic FizzBuzz, then add a special case, ...
6
votes
1answer
415 views

Login UI for an Android app

This code starts a new thread for login and reacts according to the JSON result returned by the server. I think this code has too many conditionals, exception handlers, and nested functions. ...
3
votes
1answer
55 views

A* Search with Array Lists

I implemented A* Search with Array Lists following the pseudocode here. I have been working with different algorithms on my own, and now, I am trying to optimize them so that I can run them with less ...
2
votes
0answers
71 views
+50

Make Depth First Search program more efficient

This is a problem from programming contest. In the first line there is one integer T denoting the number of test cases. Description of T test cases follow. Each one have two integers N and K ...
1
vote
3answers
35 views

Byte array to floating point such as FPE2 in Java

Apple's System Management Controller uses FPE2 and SP78 as floating-point formats. While writing a Java library that that interfaces with the SMC, I ported someone's C function to convert read a ...
3
votes
1answer
47 views

Celebration Party Problem - Algorithm

I solved the following problem: Let's consider the following situation. You've invited a lot of children to a celebration party, and you want to entertain them and also teach them something in the ...
3
votes
1answer
36 views

Minimum Refills from A to B

I am studying algorithms and I had to solve this algorithm: Consider the following problem. You have a car such that if you fill it up to full tank, you can travel with it up to 400 kilometers ...
4
votes
3answers
129 views

Count words in a string

Continuing my TDD from exercism. Write a program that given a phrase can count the occurrences of each word in that phrase. For example for the input ...
3
votes
1answer
13 views

Varnish - HttpClient Exception Handling

I'm consuming some messages from a rabbit queue. Within the consumer/processor I need to invalidate a varnish cache and requeue the message if the purge failed. I'm using a local purge proxy. The ...
6
votes
1answer
46 views

Simulating character selection with JOptionPane

I am writing a program to simulate some parts of the popular game Hearthstone by Blizzard Entertainment in Java. The first thing that happens in any game is the selection of the character each player ...
5
votes
1answer
69 views

Dice-throwing game

I'm a beginner trying to create a dice game according to the specification given below. This is an improved version of my program based on the feedback given by users on my original question. Again, ...
7
votes
2answers
116 views

Decides the mechanism of organic chemical reactions based on user input

I'm new to programming, and I would appreciate any constructive criticism on my code and if there may be a more efficient way to code this. ...
0
votes
1answer
74 views

Business logic parallelization engine

In my Java 8 application there are 3 different classes but each of them contains one similar method, which is dedicated to parallelization of the business logic ...
7
votes
1answer
106 views

Button-clicking UI for a game

I've been working on this game for a couple weeks now as a purely personal project to help myself learn Java. I'd like to know if I'm on the right track with my project. Items I'd like specific ...
2
votes
0answers
50 views

Fast exact algorithm for subset sum problem in Java

I have implemented an \$\mathcal{O}(N2^{N/2})\$ algorithm for subset sum problem described in Wikipedia. That is what I have: SubsetSumFinder.java: ...
2
votes
2answers
51 views

Simple singleton database connection pool

I'm studying design patterns, and to demonstrate a singleton, I've implemented a primitive database connection pool. ConnectionPool.java ...
0
votes
0answers
35 views

Checking if a number can be made from a group of numbers [on hold]

This code is used to check if a number between 1 and 12 can be found in OR made from a group of numbers which can be any combination between 1 and 9. For example, if the number to be found is 7, can ...
7
votes
3answers
187 views

Nucleotide Count

I am learning Java and hence practicing it from here. The solution seems pretty trivial to me but still I would like to have a honest review which would guide me to following ideas: Am I maintaining ...
3
votes
2answers
24 views

Cache of shared observables (Rx)

So the idea is to maintain a cache of shared Observables - accessible by a key - which if not present will produce one using the given factory. The underlying shared Observable is accessed via an ...
3
votes
0answers
56 views

Check if a binary tree is a binary search tree or not

This checks if both the left and right subtrees are binary search trees. If they are, then it compares the nodes data with the maximum element in the nodes' left subtree and minimum element in the ...
2
votes
1answer
27 views

Verify that a binary tree is balanced

A binary tree is balanced if both its children are balanced and the difference between the heights of its children is at most 1. ...
5
votes
3answers
191 views

Determine if Class B uses Class A ( Java Reflection)

Below is a function that determines if Class B uses Class A. Currently, it tests for: Fields Superclass Constructors Methods ...
3
votes
1answer
37 views

Transfer XML data to database where table fields must match with elements

This is my first Java program, where I have a class that gets XML data from a certain website and another class that does all the database related tricks. I omitted all non-related code to this case. ...
-1
votes
0answers
14 views

How do I recognize which JButton was clicked in a separate Handler class? [closed]

This is my first class where I add the 2 JButtons and pass the object of MyHandler class handler to the 2 buttons. ...
3
votes
3answers
516 views

Finding the candidate with the majority of ballots

I am doing a code wars problem and so far I have managed to loop through a collection to find the "winner" (defined by the String that appears more than ...
1
vote
0answers
26 views

Symbolic Math/Computer Algebra System redundant code problems

I am programming this Computer Algebra System, it works fine, but I'm running into some problems where I'm writing a lot of redundant code, I'd like some advice on that. The most problems I'm having ...
5
votes
1answer
84 views

Castling move in Chess

I have just finished building a Chess game in Java as an exercise. Whilst I am quite happy with the rest of the code, my castling move check code is lengthy and ugly and I want to see if there is a ...