Tagged Questions
2
votes
1answer
58 views
TicTacToe in Java
I created this game in Java:
import java.util.Scanner;
public class TicTacToe {
public static Scanner input = new Scanner(System.in);
public static String getName(int noPlayer) {
...
-1
votes
0answers
28 views
Using for loop to get the Hamming distance between 2 strings [closed]
So i'm having some trouble with this code. i need to get the Hamming distance (the Hamming distance between two strings of equal length is the number of positions at which the corresponding symbols ...
1
vote
1answer
89 views
Playing Card Class - is this right?
The Art and Science of Java, a course book that uses the ACM library has an exercise that reads like this.
Implement a new class called Card that includes the following entries:
• Named ...
1
vote
1answer
126 views
Which code is better? And why?
I found two ways of writing the same program (one that only uses local variables, but no methods other than the main one) and other that uses one instance variable that is used in two methods.
This ...
2
votes
2answers
110 views
How can I improve this coin flipping code?
I am doing exercises for the Art and Science of Java textbook. I had an exercise that required me to program the simulation of flipping a coin until 3 consecutive "Heads" result appeared.
I did it, ...
1
vote
2answers
75 views
How to optimize this code?
So I have this piece of code in Java(Android) to add a list of brokers to a local SQLite database as one single sql instruction.
public void Add(List<Broker> brokers)
{
if(brokers == null ...
0
votes
1answer
34 views
Improving the redundant code I have while inserting to Cassandra
I have started working with Cassandra database recently. And I was trying to insert some data into one of my Column Family that I have created.
Below is the code by which I am trying to insert into ...
0
votes
1answer
55 views
Optimization: Eliminate conditional expression within common code
Background
The following code (part of a natural language processor) was written to eliminate duplicate code by using isLeft as a conditional throughout the method:
private void ...
0
votes
0answers
67 views
Optimization of Android code suggestions? Iteration based
At the "if(a==2)" part of my code below, the android emulator takes 8 seconds to process and display some data in a list. I need to reduce this time to 1 second or less. I am accessing a 50 KB .txt ...
1
vote
1answer
74 views
Is this the proper way to do it?
I'm not sure if this is the way I should be doing this
if its true then it is supposed to enable/disable python/ruby
is this the correct way?
public void init() throws IOException {
...
3
votes
1answer
169 views
Fastest way to delete a large folder using JAVA
I am trying to delete a large folders (with many levels of subfolders) over a network (i.e, on a remote machine.
I have the following code and it takes 10 minutes. Is there a way to improve this, ...
1
vote
1answer
63 views
Looping through the ResultSet efficiently and the add the values for columns in List<String>
I am working on a multithreaded project in which each thread will randomly find columns for that table and I will be using those columns in my SELECT sql query and then I will be executing that SELECT ...
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 ...
4
votes
2answers
99 views
Move object by one up or down algorithm in a custom order
Basically, I did an object (using hibernate) with a field called sorting_order. This field needs to be unique and I wish to swap two object by one. So one element has to be after or before the current ...
1
vote
2answers
124 views
Optimizing code: longest repeating substring
I know i have some real problems with the following code (as others said). can you please help me to optimize it a little bit? Maybe some example of how to do it.
(find the longest repeating ...
1
vote
3answers
80 views
Evaluating result for mastermind comparison
I'm implementing a Java version of the game Mastermind.
My version uses numbers to represent colors, for example 2315. This function compares a string of numbers to the secret code the object ...
2
votes
1answer
67 views
Count the number of cyclic words in an input
Cyclic Words
Problem Statement
We can think of a cyclic word as a word written in a circle. To
represent a cyclic word, we choose an arbitrary starting position and
read the characters in ...
2
votes
1answer
108 views
Sorting parallel ArrayList
I have a model class that contains 3 ArrayList which are in order by parallel of the same size. <Object><Calendar><Long> I want to sort it by the <Long> Is this the most clean? ...
0
votes
2answers
124 views
Review code for optimization and implementation
The below code does Read csv files and process it to do some sort of
cacluations.This is more of small picture code , to introduce big picture.
The csv file contains information of seeds of crop which ...
2
votes
1answer
164 views
Recursion and iteration how can i optimize this code
I have written some code which will fetch contents from a resource which is actually stored in a tree format. Since it is in a tree format, there will be a parent-child relation and hence recursion.
...
-1
votes
1answer
68 views
Applying for a job as a Java developer/QA Specialist [closed]
I have recently applied for a job as a Android Java developer/QA specialist. The company has now asked me to show them some of the code that I have written so far. Since I am a indie developer, that ...
1
vote
1answer
67 views
Using java keyword final on reference objects inside methods body [closed]
As per Joshua Bloch's book "Effective Java", Item 15 - Minimize mutability, using final keyword on private class fields in addition to immutability and thread-safe syncing could improve performance.
...
3
votes
2answers
125 views
Closable BlockingQueue
I am working on legacy code, specifically a sort of BoundedBlockingQueue (mainly used as a pipe between different threads). As it is heavily used in the system and the current implementation features ...
0
votes
1answer
78 views
Optimisation suggestions for swing project (NetBeans) [closed]
I was working on my uni project (Digital Clock) when I noticed that it gets really buggy.
I'm using NetBeans (as a requirement) and there is a LOT of code. I'm not that good as well, so I don't know ...
2
votes
0answers
150 views
Not getting Log(n) performance from quadtree
Here is my QuadTree class and node.
The problem is really with Querying.
In my game, I have a city which can have n * n streets (randomly generated).
And each street has buildings.
What I do is put ...
2
votes
2answers
150 views
Optimization of exponentiation
I'm writing some crypto code, and as part of it, we have to implement modular exponentiation.
I have it working, both with the right-to-left binary method and with the Montgomery formula.
While ...
2
votes
1answer
83 views
Calling API (with rate of 5 calls/second) using Jersey Client
I am using Jersey Client to make API call to validate Session. This call is being made at rate of around 5 calls/second. I want to ensure that the client call doesn't have performance issues.
Please ...
1
vote
2answers
257 views
Modular exponentiation optimisation in Java
As part of an assignment in Cryptography I've been asked to write code that involves calculating modular exponentiation. The BigInteger modPow is not allowed in this case, we have to implement it ...
5
votes
3answers
192 views
Would appreciate feedback on college-level project
In this program, I have been asked to read a an existing textfile (1324passlist) containing a list of passwords, then create a dictionary file with both the password and MD5 hash of the password on ...
5
votes
3answers
152 views
Java string replace
I am new to java and I am trying to learn about optimizing code to make it production ready. I have the following code below. I would like to know how I could optimize it.I thought by using a small ...
3
votes
0answers
85 views
OpenCV Mat processing time
I'd like to know whether having different variables for the src (source) and dst (destination) of an OpenCV function will have an effect on the processing time. I have two functions below
that does ...
3
votes
3answers
145 views
want to cache 1600 integers, but caching and searching from treeSet takes lot of time
Set<Integer> set = new TreeSet<Integer>();
//some logic to populate 1600 numbers
for (int cases = 0; cases < totalCases; cases++) {
String[] str = br.readLine().split(" ");
...
2
votes
1answer
423 views
Word Search solving algorithm
The following is my wordsearch solving algorithm. I'd greatly appreciate tips on how to improve it (e.g. improve efficiency, better approach, etc.):
public boolean traverse(Grid grid) {
for (int ...
4
votes
2answers
2k views
Reading a line from a text file and splitting its contents
I have this kind of file structure
MALE:FooBar:32
FEMALE:BarFoo:23
Where I would want to identify the gender and age of person, <Gender>:<Name>:<age>
try{
BufferedReader in = ...
0
votes
0answers
127 views
optimize segmentation code
This is part of a code from spectral subtraction algorithm,i'm trying to optimize it for android.please help me.
this is the matlab code:
function Seg=segment(signal,W,SP,Window)
% SEGMENT chops a ...
2
votes
1answer
1k views
Validate IP address in java
Following is the code that I'm currently using to validate the user given ip address (IPV4 and IPV6). It makes use of apache commons-validtor's InetAddressValidtor. However, their function validates ...
9
votes
2answers
2k views
Problem 5 on Project Euler
I just recently learned about Project Euler and have started doing the problems on there. I cleared problem 1 and 2, had no idea how to do 3 and 4, and started to do 5. I've seen the post regarding ...
5
votes
3answers
292 views
Printing braces
Question goes like this :
input: 1
output:
{}
input: 2
output:
{}{}
{{}}
input: 3
output:
{}{}{}
{{}}{}
{}{{}}
This is my program :
public class PrintBraces {
int n;
char []braces;
...
1
vote
1answer
132 views
Can this code be improved?
I am new to java, and I would like some tips from the 'pros'. I know of the Pascal naming system, and things like that, but how can I improve this code?
Menu.java
package com.x12.addsubtract;
...
3
votes
1answer
364 views
Efficient Album Cover loading for ListView
I have a list view which display in each view a Album's name, the associated Artist and the album art.
Here is the code of my ListFragment which display this list:
public class AlbumsFragment ...
-1
votes
7answers
480 views
java Optimize this function as much as possible
i am new on java and i have not more knowledge about java. please help me for optimizing it as much as possible
public void q1(String str, int[] arr) {
String local = "findnumber";
for(int ...
4
votes
0answers
126 views
Streaming pages of a different size than a cache's pages
I need to write a service to return objects in pages of size 20. The caching of these objects is done in pages of size 60.
To abstract the logic of streaming differently-sized pages, I wrote this ...
1
vote
3answers
200 views
Performance Improvement
Problem Statement:-
First Case:- Where inclusion and exclusion both are not empty so that means inclusion overrides anything in exclusion so for that algorithm is like this
--If key is either equal ...
0
votes
2answers
5k views
Create a list of all possible combinations of elements into n-groups from a set of size k
I'm trying to write a Java program that, given a particular number of groups and number of total participants, creates a list of all possible ways to fill that number of groups evenly using all the ...
2
votes
2answers
380 views
Multiple IF Statements. If conditions of all IF statements are true then do something
Sorry about the title of the question I am open to improving it if you have any suggestions.
I am not happy with the following code and I get the feeling there is a better way to do this? I'm also ...
2
votes
2answers
190 views
Java - Object declaration out of while loop
Could you explain to me which code is better (more optimal) and why?
Vesion 1:
while(something){
Runnable task = (Runnable) taskQueue.dequeue();
Throwable ex = null;
...
}
Version 2:
Runnable ...
2
votes
2answers
1k views
Optimizing mass inserts into SQLite
I am trying to optimize inserts from a returned JSON which contains data from multiple tables on the remote server. My code is working, but I just want to figure out a way for it to work better. I ...
1
vote
2answers
280 views
Comparing strings
My question is What's the fastest (quality is important too, but a little less important) way to compare two strings?
I'm looking for the most efficient way to compare two strings. Some of the ...
1
vote
2answers
184 views
How to optimize this SQL delete
I want to optimize the performance of this SQL query. If I populate this hashtable with one million keys the query will take around minute. How I can optimize this Java method for faster execution?
...
9
votes
4answers
2k views
Good method to check whether a string is a valid number?
I'm developing a Java Helper Library which has useful methods developers don't want to type out over and over. I'm trying to think of the best way of checking whether a string is a valid number.
I've ...