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 (1)

6
votes
4answers
257 views

An enum that has situationally invalid entries

Is it considered bad style to have that BOTH value in the Direction enum? Problems can arise from ...
2
votes
2answers
90 views

Finding the largest mirror image of a subset of integers present in an array of integers

The problem I am talking about is this. Problem statment: We'll say that a "mirror" section in an array is a group of contiguous elements such that somewhere in the array, the same group ...
3
votes
1answer
32 views

JSON fetcher for Eclipse plugin — Is this exemplary code for exception handling?

I am planning to use this code as a "good exception handling" code example in one of my papers. It is for a client module of an Eclipse plugin. How does it look? ...
4
votes
4answers
68 views

Random 6 to 10 digits number

I am generating a random numerical 6-10 digit password. I need some important reviews of yours. Is it OK or are there some needed modifications? ...
3
votes
3answers
813 views
2
votes
1answer
34 views

Submitting a Java program which implements the Sieve of Eratosthenes

I would like some feedback on a Java program which implements the Sieve of Eratosthenes to find prime numbers. Some of the 'features' I've included in the program include: It uses a ...
7
votes
1answer
123 views

Min and Max initialization

Is it a good practice to initialize the max to -100000 and min to 100000? Is there any other way to initialize both min and max to 0? ...
9
votes
4answers
582 views

Recursive implementation of palindrome string checker - refactoring issue

I've tried to refactor my program to single return statement at the end of the program however it ruins the end statements of the recursion. because I want to return from function in specific line and ...
-1
votes
0answers
12 views

Element index that has the highest value in Java [on hold]

So I need to find the highest interest rate for a silly banking program I am working on. I have created a method to find the highest rate by searching through the element index. What I am having ...
4
votes
1answer
75 views

Implement queue using linkedlist

Implement queue using linkedlist. Looking for code review, optimizations and best practices. ...
2
votes
1answer
34 views

Detect a complete binary tree

Detect if a tree is complete binary tree or not. Looking for code review, optimizations and best practices. ...
7
votes
1answer
117 views

Unit conversion activities

Please review these activities which handle converting units in an Android app: I would appreciate any guidance and advice on code refactoring and different design patterns or strategies that I ...
0
votes
3answers
56 views

Call method from another method and into the cycle [on hold]

Is this normal or do you have more best practices? ...
11
votes
3answers
453 views

Bank card validation module

I hope that someone could review a module I wrote for bank card validation. I included a class that tests some of the methods, this is purely to show the methods work, rather than unit testing. I ...
4
votes
1answer
32 views

Implement stack using a linked list

I am trying to implement Stack using a linked list. Looking for code-review, best practices and optimizations. ...
3
votes
6answers
498 views

Code Hunter 2.06: Count occurrences of 'a' in a string

I'm playing Code Hunt on level 2.06 (loops). This level is about counting the number of "a" in a String. ...
7
votes
1answer
38 views

Find the Next Greatest Element

Given an array, print the Next Greater Element (NGE) for every element. The Next Greater Element for an element x is the first greater element on the right side of x in array. Elements for which no ...
4
votes
2answers
164 views

Finding the value 'n' in an array that has 'n' or more larger values

Given an unsorted array of integers, you need to return maximum possible \$n\$ such that the array consists at least \$n\$ values greater than or equals to \$n\$. Array can contain duplicate ...
0
votes
2answers
35 views

Partition array into 2 sets, such that different of sums in both subsets is minimal

Given a set of \$n\$ integers, divide the set in two subsets of \$\frac{n}{2}\$ sizes each such that the difference of the sum of two subsets is as minimum as possible. If \$n\$ is even, then ...
0
votes
0answers
11 views

Dynamically add/remove components to/from panel [on hold]

I'm in a little planning phase of my project. Here is a picture: It is a main panel containing several sub panels depending on the selected date in the top center. I want to browse those sub panels ...
2
votes
1answer
19 views

Determine if subset in int array adds up to a given input integer

Given a set of non-negative integers, and a value sum, determine if there is a subset of the given set with sum equal to given sum. On similar lines, Partition problem is to determine whether a given ...
6
votes
2answers
66 views

Planning a rather large refactoring of physics code in a good way?

I have a large file that I want to refactor. My idea is to make helper classes with helper methods so that I can modularize methods. Is that a good idea? For instance before refactoring: ...
7
votes
2answers
348 views

Optimizing this inefficient TicTacToe configuration parser

On a programming contest I came upon this question: Given a partially played 3 × 3 tic-tac-toe configuration, write a program to determine which player will have a better chance of winning if the ...
2
votes
1answer
33 views

ListView with a search filter

I have this piece of code I've been working on for quite some time. It's a ListView with a search filter. Inside each row, it contains a user Image, a User's name and how many friends they have in ...
0
votes
0answers
16 views

Java ObjectInputSteam and ObjectOutputStream for database project [on hold]

I am creating a database project in java using file handling. The program is working without compiling error. Following points are not working 1. File is storing only first record. (if program is ...
3
votes
2answers
43 views

Class that implements a queue using two stacks

I am looking for a review of my code that implements a MyQueue class which implements a queue using two stacks. ...
4
votes
1answer
36 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 ...
6
votes
3answers
251 views

A Fast Approach to Prime Number Sieving (Non-Threaded Array)

I am posting this question for input on comparisons between other sieving methods and opinions on what I have discovered. I believe this might be the fastest (singular, non-threaded) array ...
-2
votes
0answers
38 views

making a game GUESS MY NUMBER GAME [closed]

I am learning java and now making a game Guess My Number, where computer choses a random number which is declared as int rNumber for random number. i have created 2 buttons, guess and ...
14
votes
2answers
179 views
+150

Analyzing Minesweeper Probabilities

Calculating probabilities in Minesweeper might sound like an easy task, but I've seen so many probability calculators that's either incorrect, horribly slow, or with ugly code (or all of them) so I ...
8
votes
2answers
353 views

Swing calculator - first GUI program

I've recently made a calculator using Java and Swing. I'm okay with the results but I'm curious what are the major flaws I've made (assuming there are, because it is my first program making GUI). I ...
4
votes
1answer
106 views

Is checking for null redundant while using Contract Annotator from JetBrains?

I'm curious whether checking for null is redundant in this concrete example. ...
9
votes
1answer
160 views

Thread-Safe Integer Sequence

I would like to give an Integer to whatever demands it. For that I use the following code ...
0
votes
0answers
43 views

Problem with percolation and weighted quick union [closed]

I am having trouble with a percolation program in java using weighted quick union I think there is either a bug in the main where I use union to tell which locations are connected or there is a ...
1
vote
0answers
15 views

Mutualising multi-threaded calls to EJB from Servlet

I have a Servlet that makes an EJB call to a backing server which takes about a second to return some data that changes reasonably regularly. I can't cache the data on the Servlet-side, so I have ...
0
votes
0answers
31 views

Missing Term in an AP (Programming) [closed]

An Arithmetic Progression is defined as one in which there is a constant difference between the consecutive terms of a given series of numbers. You are provided with consecutive elements of an ...
8
votes
5answers
463 views

Prime Number Sieving Algorithm

Edit: Newly Updated Code here A Fast Approach to Prime Sieving (Array Implementation - Non-Threaded) Original Thread Last semester in my Masters Program I developed this code for sieving. Is this ...
6
votes
2answers
131 views

Testing quicksort user input

I am testing a quicksort implementation. Arrays of random size with random data are passed to quicksort and the return time is averaged out. The user is prompted to enter values for minimum length ...
3
votes
1answer
39 views

An attempt to extend an enum to prevent branching without violating the Open-Closed principle

I love making utility State enums, and giving them methods that do useful things based on which instance of the enum is provided. This works when the enum is very specific to the class I'm working on, ...
2
votes
1answer
38 views

Given suffix array and a pattern, search if given pattern exists

Given a suffix array for a word, check if a pattern (consecutive chars) exists. Example: A suffix array constructed for "ameya" should return true for "ame" but false for "foo" or false ...
7
votes
2answers
86 views

Output in one window

Can anyone give me feedback please? I used what I have learnt so far, mainly methods, loops and arrays. I would like you view based on these topics, however, comments on how to improve are welcome. ...
6
votes
2answers
591 views

A simple semaphore in Java

It is a simple semaphore in Java. Although it passes all their tests with flying colors, I'm still not sure it's correct. For example, the last thing I wasn't sure about was ...
10
votes
5answers
365 views

Checking if a list of coordinates defines a closed, exact rectangle

I have to check if a list of coordinates define a closed, exact rectangle. I start with the question "How do I check if a list of coordinates is in the shape of a rectangle?" The answer is: ...
3
votes
2answers
69 views

Suggested parameter names for utility class function

During our internal code review process, my following code raised some eyebrows: ...
0
votes
0answers
22 views

How do I style this? (Vaadin) [closed]

So I am completely new at Vaadin and I am trying to make something like this: And I did achieve this: But as you can tell, it lacks any sort of styling. It's not pretty in the least. Any tips ...
4
votes
2answers
60 views

The Three-machine proportionate flow shop problem with unequal machine

As part of an Academic project I wrote the following code, according to the algorithm (verbal). When I checked the rest of the article I notice that the efficiency should be \$O(n^2)\$ and I wrote ...
5
votes
3answers
73 views

Calculating the ranks of classmates' exam grades

The questions from hackerearth: Geeko is in worry now because an exam is coming up and he has to know what rank he can get on exams. So he goes back into the the school records and finds the ...
2
votes
0answers
40 views

Abstract factory pattern implemented in Java

I need a code review on my Abstract Factory pattern written in Java. Find the two enums AnimalType.java and DietType.java below. ...
1
vote
2answers
194 views

Code duplication for just an if condition

I have two methods that are near-perfect duplicates. There is of course a code smell. The only thing that changes is the condition to increment a variable. Language: Java7 ...
3
votes
2answers
45 views

Java Cross with characters

I managed to make a perfectly even cross with for loops. I'm trying to make this cross easier to code. I have to keep it with ...