Tagged Questions
4
votes
3answers
101 views
Defining of new, temporary, variables or usage of already known ones?
I want to check if the length of phone number is appropriate for specified country (let's consider that only some countries have restriction, another countries accept phone number with various ...
5
votes
2answers
291 views
Circular buffer implementation for buffering TCP socket messages
I have written my own for practice and also some tweaks for my specific requirement. There is an insert which can copy a range (well array copy really) which I am hoping is more efficient than ...
2
votes
3answers
110 views
Readable code with many components (Swing)
Please help me to make more readable and simple code like this. What if I had 20 components? Is it right to organize code like this?
package newpackage.view;
import java.awt.GridLayout;
import ...
3
votes
2answers
126 views
Is using return appropriate here?
I wanted to get the boolean status from a function. Here is my sample code, wherein I used return in try and catch, to get the status of function.
public static void main(String[] args) {
...
6
votes
4answers
362 views
Critique: readability of java interview question
In Cracking the Coding Interview by Gayle Laakmann McDowell, there's a question that asks you to write code for the following:
Given two sorted arrays, A and B. Write a method merging the elements of ...
5
votes
2answers
173 views
Can someone help me improve my code to convert an integer number into its word representation written in Java?
I've written this code to convert an integer number into its word representation. I've tested it for many cases and it seems to be working as expected.
E.g
1000 displayed as One Thousand
99999 ...
5
votes
2answers
155 views
Return inside try block
Is this return style acceptable? Would the code be more readable if I assigned the MonthDay.parse() return value to a variable and returned that variable on the last line?
Also, is it a bad idea to ...
3
votes
1answer
203 views
Improving readability of 3d math in Java
Doing graphics in Java, I find myself writing lines like these regularly:
Vector3f b = mid.add( a.mult(yOffset + length / 2) ).add( up.cross(a).mult(xOffset) );
It gets even worse when I'm reusing ...
2
votes
3answers
140 views
Retrieving current time and computing a hash value
Can someone critique this Java code?
package javaapplication;
import java.util.Date;
import java.lang.Long;
interface infix_operator {
public int apply(int x, int y);
}
class f implements ...
8
votes
4answers
331 views
Reduce length of condition
Is there a way to reduce this lengthy if condition:
if(
statusCode.equals( NO_ERRORS_NO_WARNINGS ) ||
statusCode.equals( HAS_ERRORS_NO_WARNINGS ) ||
statusCode.equals( ...
28
votes
7answers
3k views
Is using the ternary operator like this considered less readable?
I often like to do things like this:
return (aCondition == aThing)
? someLongExpression.getAThing()
: somethingElse;
Is this practice considered more or less readable than using a ...
3
votes
2answers
310 views
Intersection of Array Question, limited only to methods
Problem: Find the intersection of two Object arrays without creating any new classes (no anonymous classes either) and without using any native Java classes in the solution (so no ArrayList ...
4
votes
4answers
2k views
Intersection of Arrays - Java
public ArrayList<Integer> findIt (int[] a, int[] b){
ArrayList<Integer> result = new ArrayList<Integer>();
Arrays.sort(a);
Arrays.sort(b);
int i = 0;
int j = 0;
...
1
vote
1answer
125 views
How Can I improve This Level Parser?
The code for the LevelParser is shown below. It is also documented using Java-doc, the docs are in the project directory.
Now by improving this piece of code, I do not mean optimizing it to ...
4
votes
1answer
256 views
Jon Bentley's bitmap sort implementation
I've implemented Jon Bentley's bitmap sorting algorithm from Column 1 of his Programming Pearls book. This code supports user-defined integer range (works from Integer.MIN_VALUE to Integer.MAX_VALUE), ...