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)

-1
votes
0answers
7 views

Print elements of largest contiguous subarray [on hold]

I am trying to implement Kandane's algorithm with an additional property of displaying the elements as well. But this seems to fail for certain input values. I tried to find out but can't see the ...
1
vote
2answers
26 views

Timer for a Java game

I have a simple game that implements a TimerTask. However, when there's a popup using JOptionPane the timer task doesn't seem to ...
5
votes
2answers
37 views

Simple calculator implemented with lambdas

I was searching for a way to exercise the Java 8 concepts I've been learning, especially pertaining to Lambdas. Incidentally, I hadn't used any swing in a while and wanted a refresher. This is the ...
1
vote
0answers
23 views

A set of names and a request with asterisks

I have a set of names and a request with asterisks. An asterisk can be replaced with any letter. For example, there is a set of names: hasad, ahmed, fizo. And there are a few sample requests: hasad, ...
9
votes
5answers
330 views

TDD for Euler Problem #4

I am in the process of learning Java and going through the Euler problems. For Problem 4 I decided to also implement a TDD approach with JUnit. My questions are: Is there a better TDD approach to ...
3
votes
1answer
33 views

Reducing lock contention for a caching utility, or make it totally lockless but threadsafe

My Java program is a module called configProxy which fetches configuration entries from a remote node (say from a Redis instance). When the caller calls the ...
3
votes
2answers
24 views

loopification of highly procedureal, though fully functional, multiclass perceptron

I've implemented the multiclass perceptron in the one vs. all style. I just thought about it and tried to implement it in the most basic way. I think it's correct though my f_measure is a bit low. ...
4
votes
2answers
45 views

Moving chips between cells

Challenge: You are given a line of N cells with positive integers written in them. Initially a chip is placed on the leftmost cell. Each time it can be moved in any direction (to the left or to ...
6
votes
2answers
153 views

Beginning calculator program

I am a beginner in Java and programming at all. I decide to try to write a calculator, as a my first "complete" program. It works for me, however I am curious is it worth anything in reality. I would ...
7
votes
1answer
191 views

Let's Break Down the Party

This is a rags-to-riches question, the original is here: Coin dispenser program There are three parts to this, a Denomination ...
0
votes
0answers
14 views

Stream file to opencsv with the least amount of I/O possible

I have the following code snippet where I'm picking up a file from an ftp server and then streaming it to opencsv. I have very little experience with streams, so I'd like to have someone review this ...
0
votes
0answers
16 views

java.lang.NumberFormatException: For input string: “” [on hold]

This is my code and i am frustrated by the error: ...
0
votes
0answers
10 views

Designing a Solution for generalization and future scope with Inheritance [on hold]

I have below code/classes/interfaces with me: An Interface: public interface Animal{ void fight(A otherAnimal); } 2.Tiger class which is implementing Animal ...
1
vote
0answers
31 views

Generating a histogram efficiently from the datasets in a Map

I have a map in which I store total bytes as the key and count of users as the value: ...
6
votes
5answers
280 views

Database abstraction in Java

I am working on a project in Java which includes a lot of database related tasks. For instance, I would have to insert, update, retrieve data so many times within the application. To use code ...
0
votes
0answers
21 views

ReturnCode code class uses generics to hold an object [on hold]

I have a series of methods that need to make database queries, and at any point, it might need to return a return code (a boolean and message) indicating that the query has failed. However, it ...
11
votes
5answers
619 views

Singly Linked List in Java

I created my own implementation of a Singly Linked List. Is there anything I can improve on, in terms of effciency. Also, what other methods would you recommend for me to try and implement. My goal is ...
12
votes
4answers
608 views

Coin dispenser program

I've decided to go tech and learn a language. I have been reading Java for a week and here is my first attempt. I am making a habit to write JUnit test cases so that I start on correct path. Here is ...
1
vote
4answers
40 views

Finding the second largest element of large input sets

I have a problem where I need to find the second maximum element of the user inputs. It's an online practice problem and I can't figure out why the server responds back with a Non-Zero Exit Code error ...
5
votes
2answers
59 views

Database access concept

I've got a small tomcat web application that's used to receive customer data from an iPad app. After receiving those information they will be saved on a local MySQL database and then sent to an SAP ...
4
votes
1answer
38 views

Static method to get user ID

I have a method which extracts the logged-in user details from a SpringSecurityContext object. I have read that only utility methods (which does certain ...
0
votes
0answers
30 views

Loop to obtain sublists of arraylist [on hold]

I have the following code: ...
4
votes
3answers
72 views

Evaluation function for Connect Four

Here is some code I have written as a connect four negamax evaluation function. The state of the board is stored inside a class state. ...
-2
votes
0answers
22 views

Recursive function calls with same parameters [on hold]

I have a function "CALLER" which gets some variables from the application and then passes to a recursive function "CALLED". Some of these these variables are same for all the recursive calls to ...
2
votes
1answer
32 views

Path from the root to a given node in binary tree

Based on the solution provided in this question , I have written non-recursive Java code to find the path form to a given element in a binary tree. This code is working for all the elements except ...
0
votes
0answers
16 views

What is the proper way for these methods to function? [migrated]

How can I properly design what a method or function should do? To clarify the question I am going to use an example from a simple (non GUI) hangman game I created. The design is simple, it has a ...
2
votes
1answer
49 views

Bucket sort implementation

I want to optimize my code for performance and fine-tuned logic. ...
2
votes
0answers
30 views

Map Events From calendar provider to dates in gridview

I working on a calendar app on Android, using roomaorama, which is nice. I am fetching all the events from Events table in Calendar provider once which seems not good performance wise. The library ...
3
votes
1answer
96 views

Servlet responses to upload/download requests

My task is to write a program to store files in object store. One of the subtasks requires to send json or xml format response to the file uploader/downloader as requested by client. The following ...
5
votes
1answer
41 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 ...
2
votes
1answer
49 views

Reading and Writing object from files

I have a server which has a permanent state which has to be saved on stable storage. It is composed by three fields: List<LogEntry> log ...
6
votes
2answers
104 views

3-D Space Vector

I wrote the following implementation of a Vector in Java. I was wondering what you folks thought of it. ...
5
votes
1answer
106 views

Optimization of a “Sieve of Eratosthenes” in Java

I have created a simple Pseudo "Sieve of Eratosthenes," for a class in Java. I am looking for the most optimized option, or at least an option that is more optimized than current. If there is any ...
3
votes
2answers
31 views

Distinguishing user input numbers and characters

I am currently taking a computer science class in high school, and it is my first time programming (2 weeks since I started). I have currently finished my program; however, there were a few details ...
6
votes
2answers
261 views

Sum the exponents of the prime factors of a number

My goal is to find the sum of the exponents of the prime factors of an integer. I wrote the code below with the complexities specified here (I am not 100% sure of the complexities though): Runtime ...
1
vote
0answers
13 views

Getting the latest hash from a file

I'm trying to write clean code, but I'm not so good with exception handling. How can I improve this method? Or is it good enough already? This method gets a hash from a file. ...
3
votes
0answers
67 views

Building an efficient bubble sort function

I've been asked to create a bubble sort function that checks whether the array has been filled sorted before all passes are complete, thereby avoiding unnecessary passes. This is to involve ...
5
votes
3answers
75 views

Line passing the most number of points

Given points on a two dimensional graph, find a line that passes the most number of points. Any comments please? ...
7
votes
1answer
81 views

Hangman program in Java

Here's an implementation of Hangman using Java 6. I've split the code into 2 classes - a logic class & a gui class. Is it ok to have so many static member variables? Please let me know if there ...
8
votes
1answer
43 views

YAuB - Micro Benchmark Follow-on

Following some great advice here from Simon, I realized that I had over-engineered things, and that the Task builder methods were a horrible Java8 abstraxction. In Simon's words: "From a usability ...
4
votes
2answers
378 views

Non-recursive method for finding a ^ n

I am working on an interview question from Amazon Software. The particular question I am working on is "to write a program to find an." Here is my recursive solution to this problem (in Java): ...
4
votes
0answers
35 views

Creation of Queen Ann's Lace fractal

I've created a program which recreates the Queen Ann's Lace fractal. However, when the amount of points that are being plotted increases, the points are plotted way slower. Is there any way to make it ...
12
votes
1answer
87 views

Parsing log files of HearthStone: Loading card data without external libraries for JSON

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 ...
2
votes
0answers
26 views

Read from DataInputStream (Socket connection)

I am interfacing with a network device and must read a response after I issue a command. Sometimes when I attempt to read, nothing has been returned from the terminal. This means I must wait, but not ...
2
votes
0answers
25 views

JSON extraction

Given the code below, is there a better way to essentially create different native objects without changing the native constructor or the nativeList.json file? The only option I can see is adding a ...
6
votes
3answers
382 views

Nested loop to render tiles in a grid

This code works but I'm not really sure if I wrote it good enough. It seems a bit vague but I can't really assess it properly. I'm particularly concerned with the ...
-1
votes
0answers
12 views

WLP (Weakest Liberal Precondition) Transformer implementation in Java? [closed]

Input for our program is array of instructions (Expression [] instructions). Then iteratively starting from last instruction, and going backwards we searching for weakest pre-condition of single ...
2
votes
3answers
204 views

Generate all possible numbers which can be representated as the sum of 2 cubes below N

I have written a program that generates all possible numbers which can be represented by adding 2 cubes which have value less than N For example: when \$N = 10, 1^3 + 2^3 = 9\$ ...
7
votes
3answers
162 views

Return list of common email ids from a list of lists

Input: ArrayList of ArrayLists with email ids. Output: Return ArrayList of email ids which appears in each inner ArrayList. Ex: Input: [[abc@gmail.com, ...
9
votes
1answer
60 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 ...