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.
2
votes
0answers
15 views
Factory that creates a complex object tree
I've got a complex object tree that I need to instantiate. The object tree is a bunch of specialized classes that don't have a common root object (other than Object) and has generic objects (that I ...
1
vote
0answers
40 views
Fast constant time evaluation of “x==7” to 1 (true) or 0 (false) in Java [migrated]
I want to port a crypto function from C to Java. The function has to run in constant time, so no conditional branchings are allowed.
The original C code is:
...
3
votes
1answer
24 views
ProductManager: a basic CRUD for products with SQLite
I would like to have a review of this basic CRUD application so I can improve and learn from your experience. The code can be found here.
Design pattern/coding principles improvement that could be ...
5
votes
1answer
29 views
Class managing queuing updates from another thread, Version 2
This is an updated version of: Class to manage updates coming in from another thread
Managing updates from other threads into Swing is a hard problem. In MVC design, if you don't want to have the ...
2
votes
0answers
31 views
My own version of a search binary tree
I wrote my own version of a search binary tree in Java. Could someone kindly review it?
...
3
votes
1answer
23 views
Function that shortens a String based on a term/abbreviation mapping with special cases
This is a update of this question since the requirements for this task changed.
I have a function that takes a description as a String and returns a shortened ...
6
votes
1answer
44 views
Return Y integer with same bit sets as X & having | X - Y | minimum value
I happened to come across one question:
Given an integer 'x' (Only positive), write an algorithm that returns
integer 'y' such that it has the same number of bits set as 'x' and is
not equal ...
-3
votes
0answers
27 views
Water volume calculator [on hold]
I'm at the beginning of my Java course, and the instructor gave us this question:
Create a java program that will calculate the water volume of a swimming pool or pond. The basic formula for ...
1
vote
0answers
34 views
AVL tree implementation in Java
Please ignore the OOP aspects of the code for a moment and concentrate on the efficiency of code. I would be obliged if someone could suggest a way to shorten my AVL tree implementation, such as using ...
6
votes
1answer
33 views
Generation of Groovy source from parent Java class
I use Groovy to write business rules into big, long term Java software. Use Groovy in object way, that is not as groovy Script, but every elementary groovy source overrides some Java API class.
i.e. ...
7
votes
1answer
243 views
Null check in .equals implementation
I have inherited some legacy code that I'm now trying to clean up.
I feel like the 2nd null check is redundant, see comments:
...
1
vote
0answers
43 views
1
vote
0answers
31 views
Batching using semaphores
I need to batch messages when pushing them, where multiple threads do the publishing. What could be a better way of doing this?
...
19
votes
4answers
3k views
“ONCE”, “UPON”, “A”, “TIME”
I'm working on a small program to perform various tasks on text content, primarily at the word level. I wrote these methods as ways to help prepare the raw text file into something more malleable, ...
9
votes
4answers
966 views
E-mail testing code
I made some code to check that e-mails given apply to the right format, and I'm sure there must be a better way to do this.
...
5
votes
2answers
46 views
Class to manage updates coming in from another thread
Managing updates from other threads into Swing is a hard problem. In MVC design, if you don't want to have the Presenter be responsible for Thread safety, you can end up with deadlock issues, and also ...
3
votes
2answers
62 views
Simple object oriented design for a patient system
I want to model this scenario in object oriented language:
A hospital has number of patients
A patient can have zero or more medical conditions
A medical condition is identified by name and date
...
-1
votes
0answers
18 views
Draw a map from encoded polylines [on hold]
I'm using the google maps web services service to find a route. From the json response I parse it encoded polylines and store it on coordinates String.
Then, coordinates is passed as parameter to ...
2
votes
0answers
29 views
Observe closeable with default methods
I want to extend the Closeable-Interface so that I can add Listeners, that get notificated when the resource is closed.
The CloseListener-API is rather simple and straight forward:
...
7
votes
2answers
242 views
Efficient URL Escape (Percent-Encoding)
Here I have a simple algorithm to percent-encode any string.
(Specification from Wikipedia; note that this is not compatible with URLEncoder.encode())
Is this an ...
7
votes
1answer
58 views
Stack using an array
I designed a simple drop-out stack a while back. Basically, I just want to get a few opinions on whether or not this is a good implementation and whether I am understanding the concept of a drop-out ...
4
votes
1answer
57 views
BMR (Basal Metabolic Rate) Calculator
Been working on a BMR calculator on and off for a while now. Created an interface and been over different ways to store user input, different ways to calculate BMR/TDEE etc.
I created another class ...
9
votes
0answers
58 views
IDA*: Iterative Deepening A* implementation
I created a generic version of IDA*. I am attempting to create the following code with exceptional quality and performance. I'm hoping to try and create short code tutorials regarding. However, the ...
15
votes
4answers
601 views
Floating point equality in “Numbers.java”
Floating point inaccuracies are really annoying. I understood that in its true sense while developing the next version of Point (this time I'm actually foolproofing my code). Before I upload it for ...
-3
votes
0answers
13 views
JAVA run time error(NZEC) [on hold]
I've been given the following task:
Devu got hold of a 1-indexed array A consisting of N integers while Churu has an empty array B. Devu in his turn will choose a contiguous segment from his ...
5
votes
1answer
48 views
Multi-threaded bitcoin vanity address generator written in Java
The application leverages the bitcoinj library to generate a vanity bitcoin address. A vanity address is simply a bitcoin address that contains a personalized string. I would like some critical ...
-1
votes
0answers
41 views
Inverting a binary tree [on hold]
So I came across some code which is used to invert a binary tree, and it looks like this:
...
-2
votes
0answers
17 views
How to refactor, clean, and/or merge a massive code base efficiently [closed]
We have a massive code base of over 8,000 Java, JavaScript, CSS, Java Server Page, and Spring-specific files. I have occasionally inquired about the ability to refactor certain files for readability ...
10
votes
3answers
454 views
Fastest possible text template for repeated use?
While reviewing Sending templatized e-mail to a million contacts, I wrote this implementation to illustrate an alternate approach. It is designed to be the fastest possible way to generate templated ...
-4
votes
0answers
12 views
About PokerHand Rule [closed]
I never played PokerHand before and I do not understand the given test. Can anyone tell me why it shows two result(assertTrue(a.compareTo(b) < 0); AND assertTrue(b.compareTo(a) > 0);)?
...
-1
votes
0answers
14 views
2
votes
1answer
69 views
“Little Deepu and Array” challenge
I'm trying to solve this problem. I changed Scanner and used BufferedReader. I'm still getting ...
6
votes
1answer
87 views
Sort all the characters according to their brightness
I wrote a little fractal noise generator the other day, and to test it I wanted to display the dark values with a darker character and the bright values with bright characters (I use a dark background ...
-2
votes
0answers
29 views
Inseting a node in binary search tree [closed]
When I'm inserting a node on the below binary tree,it is giving incorrect answer,although logic seems fine to me.
...
3
votes
1answer
124 views
Duplicate integers in an array
Code shows duplicate values of integers in an array with indexes and the number of occurrences. Can you please critique my code and provide your thoughts on where I should improve my code?
...
6
votes
3answers
89 views
Java Swing Application - Roleplaying Aid
I've been working on this utility for a while now, and have since gone through a couple reworks to try and increase the readability and best practices, but since I don't usually work a lot with Swing, ...
7
votes
1answer
57 views
Number-guessing game with a cheat code
As my first Java program, I have written a number-guessing game. I would appreciate any suggestions on how I can clean it up or streamline it. I don't mean cut down on the general tasks executed ...
0
votes
0answers
25 views
Getting a String property of an Optional<> if present [closed]
I am calling the getDetailOfUri(uri) method, which returns an Optional<PageDetail>, and I would like to set the strings ...
-1
votes
0answers
16 views
How to simplify this multi component gradle.build? [closed]
I'm working on https://github.com/jadekler/git-java-websiteskeleton. It's a multi component skeleton with two components - products and users. I define an acceptance test gradle task at the root ...
1
vote
1answer
37 views
ArrayBlockingQueue - blocking drainTo() method
This is a follow-up question to this question.
Is this a reasonable implementation for a blocking version of method ArrayBlockingQueue.drainTo(Collection)?
...
-3
votes
1answer
67 views
Converting from one collection to another
Basically I am trying to iterate over one collection moduleList and adding to another collection targetList
Is this a good ...
14
votes
4answers
235 views
Numbers, pairs, and a difference
Problem statement:
Write a function which returns the total number of combinations whose difference is k.
For example, ...
-3
votes
0answers
38 views
4
votes
1answer
49 views
Unit Testing and good use of matchers
I been having discussion with colleagues recently about good use of matchers. Consider the following sample:
...
5
votes
1answer
69 views
Basic Java Swing Calculator
I am new to Java Swing and have decided to create a calculator to learn some of the basic. I would like someone to look over my code to see if they can give me any improvements.
I have 6 classes and ...
5
votes
2answers
70 views
Project Euler #10 - sum of primes below two million
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
...
0
votes
1answer
35 views
Calculation of image offsets for performing cropping
I am using the java.awt.Rectangle class to construct subsets of a GEOTIFF file. In order to do this I would need to specify the x,y offsets, height and width of ...
11
votes
0answers
63 views
Getting chatty with FX
Applying a lot of unprecedented concepts here, it's a simple chat server capable of handling multiple clients, which are run through JavaFX, and have their individual threads instantiated and handled ...
6
votes
2answers
83 views
Basic game with moving objects in Swing
This is a simulation attempt of an "old-style game", where a "car" (nothing more than a red rectangle) must dodge some "obstacles" (blue squares) falling from the upper edge of the frame. If an ...
5
votes
1answer
59 views
JavaScript program to count lines of Java code
I've implemented a small program in JavaScript to count the number of lines of a string of java source code.
This was done for one of the Code Kata exercise: ...