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
vote
1answer
21 views

Stanford CS106A Min / Max program

I am learning Java through Stanford CS106A and I'm wondering how the code for this early assignment looks. I've worked in a proprietary scripting language before and so I'm trying to get the right ...
0
votes
0answers
11 views

Suffix tree implemenation in java

I was trying to solve the problem where given a larger string and an array/list of smaller string, we need to make the determination whether the larger string contains each of the smaller strings. I ...
0
votes
0answers
9 views

Hashmap in Java [on hold]

Im trying to use a HashMap to do a project where i read in a list of jumbled words and a file of actual dictionary words and use a HashMap to find all the words that match in the jumbled words file an ...
3
votes
1answer
36 views

JPaint (Java painting app)

I have this painting app called JPaint in Java and I'm wondering if it could be improved. The variable declaration seems repetitive and long, and I think it might ...
1
vote
1answer
19 views

Minimal Map implementation with weak values

What follows is an implementation of the java.util.Map interface with weak values. This means that entries should be removed from the map when their values become ...
0
votes
0answers
11 views

Travelling Salesmen Problem - Dynamic Programming

I wanted to review my TSP program for correctness in my approach, although I have not implemented one function subset which would be simple. ...
0
votes
0answers
17 views

Optimized board representation for the 4x4 sliding puzzle

Inspired by this question and my answer to it I told myself I could try an optimized version for a 4x4 puzzle. There are only \$16!\$ possible states, so the state fits into a single ...
0
votes
0answers
12 views

DAO layer in Spring application [on hold]

Let's say I have a Java web application driven by Spring and Hibernate. Let's discuss only about DAO layer. So instead of writing DAO interface for each implementation class I decided to write one DAO ...
4
votes
2answers
95 views

Implementing a Singly Linked List

I am implementing, in my SinglyLinkedList class, an interface where I redefined linked list. I am trying to learn data structures. Please, let me know what I can ...
3
votes
2answers
67 views

Processing buy and sell orders

My code is too slow, it does the desired, but not in \$O(\log n)\$ or faster. Explanation of the auction system: For simplicity we will assume that all orders are for a single unit of the traded ...
5
votes
3answers
190 views

Extending Abstract Person Validator

I have the following code which is responsible for the validation in our app (just an example). Based on the particular tab where user can add person to the database we need to perform additional ...
0
votes
0answers
17 views

sortArray implementation [on hold]

I created this program called sortArray, (pretty self evident what it should do). And, I got rid of all the syntactic errors, but, I know there some semantic ...
0
votes
0answers
16 views

Use less battery with GPS location every 15 minutes [on hold]

I'm implementing an application which need to send a location to GCM every 15 minutes. I implemented an AlarmManager which will be called every 15 minute. Here is my class of my alarmmanager ...
3
votes
2answers
41 views

Using Mockito to verify that an object is saved

We've been reviewing some legacy code and have found differences in the preferred approach to how to write tests using Mockito. Both the following tests pass but which one is better and why? ...
-1
votes
2answers
42 views

Replacing Synchronization with Atomics

I have tried to make modification in below specified code by removing synchronized and replacing Integer with AtomicInteger . ...
3
votes
2answers
79 views

ArrayBlockingQueue: concurrent put and take

I have implemented an ArrayBlockingQueue (put and take) on the lines of LinkedBlockingQueue i.e using two locks so that my take ...
3
votes
0answers
47 views

Remove K digits of a number N in order to maximize N

The first line has 2 integers \$S\$ and \$K\$ that represents respectively the number of digits in \$N\$ and the number of digits to be removed of \$N\$. A second line is given with \$N\$. (\$1 \leq K ...
0
votes
1answer
39 views

Creating an array length n * n, separating it into n groups, and adding numbers to it n times

I am completing the CodingBat exercises for Java. Here is the one I have completed just now: Given n > = 0, create an array length ...
1
vote
2answers
45 views

arrayHistogram implementation

I wrote this code, called arrayHistogram, that would generate a random number within a set range, and print it in an array ...
10
votes
4answers
535 views

Greatest Common Factor

I wrote this program to determine the Greatest Common Factor of any 2 given numbers, and would like to know of any improvements that can be made. I have tested it using a loop and 2 randomly generated ...
3
votes
2answers
56 views

Shutdown method in queue implementations

I am trying to implement a shutdown method in queue implementation. I took the code from BlockingQueue source from Java and trying to check the shutdown method. Will the following code be thread safe ...
2
votes
1answer
51 views

Minesweeper algorithm that works within O(1) space complexity

For minesweeper algorithm, instead of the most obvious BFS or DFS solution, I want a O(1) space solution. First of all, I'll explain how the program works. I will pass in a 2D array, with 1 ...
7
votes
4answers
186 views

Identifying array elements, rearranging them, and replacing them

I am completing the CodingBat exercises for Java, and, having learnt from the answers to the previous one, I completed the one that follows: Return a version of the given array where all the ...
5
votes
3answers
219 views

Rearranging array elements depending on their indexes

I am (still!) going through these CodingBat exercises for Java. Here is the one I have just done: Return an array that contains the exact same numbers as the given array, but rearranged so that ...
3
votes
4answers
451 views

Validating Firstname and Lastname

I have written some code in Java that checks if the strings Firstname and Lastname are valid names. These are inputted by the ...
4
votes
1answer
42 views

Chatroom log in with no 3rd party libraries

So, I'm creating a chatroom with no 3rd party libraries and currently I'm logging people in like this: ...
4
votes
3answers
139 views

Java A* Algorithm Implementation Performance

I've coded a working implementation of the A* Algorithm however it's not meeting my performance expectations - it explores way too many nodes and takes a lot longer to find a route than I expect. ...
5
votes
2answers
53 views

Carpet Calculator Program Final Edit

I asked a previous question of this same program. I would like more opinions before I submit this assignment since I edited the program after receiving feedback last time. ...
3
votes
1answer
45 views

Basic Java statistics class

I noticed there's some code on StackOverflow that is, to put it mildly, suboptimal. I'm posting here to see if we can provide a better solution. Here's a proposal for fixing it. The approach is to ...
-1
votes
0answers
41 views

How to avoid nested loops

I have a program that uses a lot of nested loops because I am terrible in creating an efficient program. For example: ...
1
vote
0answers
24 views

Hibernate insert with foreign key

Ι have the following database: ...
7
votes
3answers
113 views

Fastest sum of absolute values of 32 differences

A long should be treated as a list of 32 unsigned numbers, each of them just two bit long. So 0x1234F... represents ...
2
votes
5answers
211 views

Return true if the elements of an array do not contain one or the other

I am gradually completing the CodingBat exercises for Java. Here is the one I just did: Given an array of ints, return true if it contains no 1's or it contains no 4's. Here is my code: ...
4
votes
3answers
106 views

Single value computation

I'm writing code to compute a single value answer to a given numbers in integer array such that step sum is calculated till only 1 number is left. For example: Input: ...
1
vote
1answer
30 views

Max-heap implementation with List

I am trying to create max-heap for practice. Are there any bugs? Are there ways that I can improve the code quality? ...
1
vote
0answers
14 views

Map operation to update data | Hazelcast IMap returns clone object

I have a nested hazelcast distributed map: Map<CountryId, Map<CityCode, Map<data_key,data_value>>> where "data_key" is "population", ...
1
vote
0answers
44 views

Getting device's location once in Android

In my Android app I need to get device's location once after user clicks a button. I don't really need to keep updating localization after I get the location coordinates. I created a class which uses ...
9
votes
1answer
171 views

Beautiful code which helped me understand concept of chasing objects

This code simulates a polygon (say a triangle) with a person at each vertex, every person is looking at the next adjacent vertex/person. They all start moving towards each other with a constant ...
1
vote
2answers
28 views

Identifying numeric substrings of an alphanumeric string, and summing them

I am going through the CodingBat exercises for Java. Here is the task I have just completed: Given a string, return the sum of the numbers appearing in the ...
-2
votes
0answers
5 views

Hibernate Criteria Distinct Projections [closed]

I have Bill and Bill_Details with onetomany and manytoone Relationship. I need a help in getting Bill List. Pojo Bill ...
2
votes
2answers
28 views

Returning matching substrings, of n length, at the beginning and end of a string

I am going through the Java CodingBat exercises. Here is the one I have just completed: Given a string, return the longest substring that appears at both the beginning and end of the string ...
6
votes
4answers
330 views

Summing digits of an alphanumeric string

I am going through the Java CodingBat exercises. Here is the one I have just completed: Given a string, return the sum of the digits 0-9 that appear in the ...
-2
votes
0answers
23 views

recursive method in java that evaluates a postfix notation [closed]

i need to write a recursive method that evaluates a postfix form for example: 7 3 5 * + 4 - , which in infix form is (7 + (3*5)) – 4. the operands could be of 2 or more integers, and operands and ...
0
votes
0answers
15 views

Text not centering (Java, awt.Rectangle, awt.Graphics) [closed]

if anyone wants an excuse to always back up your computer, let programming be it. While making a game, I thought I should separate my project into the core game and the main menu. I'll see how that ...
1
vote
0answers
17 views

Generating a bitset for keywords

This generates a bitset for each keyword by mapping a keyword to the set of documents (files) which contains a particular keyword. A multimap variable is declared to store the files that contain each ...
6
votes
2answers
101 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 ...
7
votes
4answers
959 views

Locker Puzzle in Java

The author of my book does not release odd-numbered solutions to students, so I can't check my solutions. I was wondering if there was a better way to solve this problem without simply printing out ...
3
votes
1answer
66 views

ASCII game Java applet

This code is probably really badly written and terrible... but it works. I need some constructive feedback, and some tips on optimizing it as it kinda flickers whenever I move the x with the arrow ...