Tagged Questions

Java is a popular programming language and runtime environment which allows programs to run unchanged on most platforms.

learn more… | top users | synonyms (1)

0
votes
0answers
11 views

Java Multi-Client Chat Application - Sending messages problem

My chat application is having a problem when sending messages. Many clients can easily connect to the server and if I wish to chat with a specific online user I can do so. But after sending two or ...
3
votes
2answers
39 views

Nested condition subset of the top one

I've got this code Double best = nodes.get(edge.getToNodeId()); if (best == null || (best > g+h)) { nodes.put(edge.getToNodeId(), g+h); if (best == null) { open.add(new ...
0
votes
0answers
16 views

Finding Potential Thread Safety issues and Race conditions in my Multithreading Code

I am working on a project in which I have two tables in a different database with different schemas. So that means I have two different connection parameters for those two tables to connect using ...
3
votes
1answer
51 views

Get rid of pokemon exception handling

I wrote a productivity app for Android. It let's you switch system settings, like bluetooth, wifi, screen brightness, volumes, ringtones, mobile data, airplane mode, etc. Unfortunately I have ...
3
votes
2answers
22 views

Shortening method based on an argument name

As you can see below, I have a method which executes statements based on the first letter of a component firing an ItemEvent: public void itemStateChanged(ItemEvent ie) { if(ie.getSource() == ...
3
votes
3answers
59 views

Simulating ALU in java

I want to create a program(in Java) which simulates the functionality of Arithmetic Logistic Unit(ALU). Here is my code. Please check is this correct. Can I implement it better? public class ...
0
votes
1answer
32 views

Creating an Array of Linked Lists from a BST

Question Given a binary search tree, design an algorithm which creates a linked list of all the nodes at each depth (eg, if you have a tree with depth D, you’ll have D linked lists) Here is my ...
1
vote
3answers
62 views

How should I read coordinates from a text file?

I have a text file with lines that look like this: Robot(479.30432416307934|98.90610653676828) Robot(186.42081184420528|213.11277688981409) Robot(86.80794277768825|412.1359734884495) or, more ...
1
vote
1answer
30 views

Log and Count the exception in a Single method

I am tring to count the number of exceptions happening and log those exceptions as well. So what I did is, I created one method addException in which I am counting all the exceptions. addException ...
0
votes
1answer
34 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 ...
2
votes
1answer
51 views

Observer pattern in Java

I'm going to have a lot of integer values, and at any value change I might need to update any number of UI elements, other values which are computed from the first ones, etc. Sounds like time for the ...
0
votes
0answers
29 views

Cannot seem to find error within Game of Life program, Java [closed]

I am sorry that the code is quite extensive, but this is my main class, as well as a class that creates/modifies/updates the cells. I believe the error is contained within the calculateNext method in ...
0
votes
0answers
19 views

Lock-free DoubleBufferedList

I posted this on SO and would appreciate any ideas on it's stability. Much like the old double-buffering algorithm, this uses a List<T> to which are added entries. You can also take the list at ...
1
vote
0answers
28 views

suggestion to improve http get and post code

Hi all I had developed an application in which I hit several urls and show data on mobile. But problem is that it requires more time. If I check same url on Firebug tool I got response in 2-3 seconds, ...
4
votes
1answer
44 views

Coverage processing on multiple Java projects with gmake

As part of my data collection, I have to run multiple kinds of coverage processing on multiple Java projects. Below is my main Makefile intented only for gmake. Portability is not a requirement for me ...
0
votes
1answer
29 views

2D Array: Retrieve the “Left” Item

I am creating a game that contains a Board and Pieces. The Board is basically a 2D array of Pieces. [Think smaller chess board] One of the things that I want to accomplish is to be able to retrieve ...
4
votes
3answers
84 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 ...
3
votes
1answer
66 views

Thread Safety issues in the multithreading code

I am working on a project in which I have two tables in a different database with different schemas. So that means I have two different connection parameters for those two tables to connect using ...
-1
votes
0answers
43 views

Improve Design of this Java Application [closed]

I completed a group assignment for a Java course, but due to deadlines I was unable to really make it as clean as I wouldve liked. Since its over now and I have submitted the assignment I would like ...
2
votes
2answers
57 views

multi-recursive replacement function

I wrote a function for creating all possible translations of a source string, based on a multiple translation map. It works, but generates a lot of intermediate maps (see line marked with *). Is there ...
2
votes
2answers
102 views

Getting Country Based on IP - Java

Im using Struts2, Google App Engine. Below is my program for getting the country based on IP of the visitor of the website. In my Struts2 action: HttpServletRequest request = ...
3
votes
1answer
85 views

Java multithreaded file server and client. Emulate TCP over UDP

This is for homework. My task was similar to my last assignment but this time I had to do it with UDP instead of TCP. This basically means I had to emulate TCP over UDP. Multithreading was an ...
1
vote
2answers
112 views

Does my main class have too much code?

For some reason i have the feeling that i should put all of my thread starts and joins in a for loop just to reduce the amount of code. I dunno if that will hurt readability on this class? Also is it ...
4
votes
4answers
162 views

Find the 2 distinct highest values in a array

Good Night I want to know if there is a better way to improve my code to find two highest in a array, and these numbers need to be distinct. I don´t want to sort the values. Only run in the array ...
2
votes
0answers
48 views

Design Pattern for Swing application

I have a Swing application with no real design pattern. I want to start learning to design Swing or any types of application properly. Here is the main JFrame class. import java.awt.Component; ...
1
vote
2answers
127 views

Spotify's “Reversed Binary Numbers” Problem

I wrote some Java code for Spotify's Reversed Binary Numbers puzzle and I tested it on my machine and I am almost positive that it behaves as expected. However, when I send it to puzzle AT spotify.com ...
3
votes
1answer
64 views

Which is a better style to write default return case in if-else

private String GetFacilityName(String facilityHexID) { if (facilityHexID.equals(FACILITY_AIRCON_HEX_ID)) { return FACILITY_AIRCON_NAME; } else if ...
-1
votes
0answers
31 views

Need help to find breakout game collision bug [closed]

This is a grade 12 OOP game assignment. It is very clear to me that the error happens in the section below. But I've been starring at it for a long time and just can't find the error. for(int ...
3
votes
2answers
69 views

Custom parser for named parameters in prepared statement

I'm creating a small extension to the JDBC API, with the hope of automating some common tasks and avoid boilerplate code. One of its features will be a basic support for named parameters in prepared ...
1
vote
2answers
58 views

Correct implementation for background task execution in web application?

I have a simple servlet which merely serves some cached data back to the user. I also have a background thread which runs at fixed intervals to refresh the cached data. Is this a reasonable ...
4
votes
1answer
66 views

Helper class to memoize DateFormats application-wide

Premise Consider the following method: static String formatMyDate(Date date) { return new SimpleDateFormat("yyyy-MM-dd").format(date); } It's often desirable to memoize DateFormat objects so ...
1
vote
0answers
31 views

Generic file parser design in Java using the Strategy pattern [migrated]

I am working on a product in which the responsibility of one of the modules is to parse XML files and dump the required content in a database. Even though the present requirement is only to parse XML ...
5
votes
2answers
145 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 ...
-1
votes
1answer
49 views

Implementation of a linked list using an array-based ADT in java [closed]

I am trying to write a linked list using an array-based linked list. So far i have the code to create the list and insert an element but i get an exception when the list is not empty and has elements ...
2
votes
1answer
51 views

Avoiding use of an initialized variable that will either be changed or ignored

Follow on from this question This is a follow on question from one I asked a few days ago. I am making (or rather have made) a recursive method that takes a list of ArrayList objects as its ...
6
votes
3answers
309 views

Two Key HashMap

Background Would like to create a two-key map that is fairly generic. In the existing system, there are a number of ways to name a parameter for a report. Rather than re-writing each report (too much ...
3
votes
3answers
146 views

Trying to make recursive code designed to find objects with even references tidier

As the title says, I'm trying to make my code less horrible looking! For a university practical, I've to use recursive methods to return the even references in a collection of Integer objects stored ...
2
votes
1answer
49 views

ORM Entity with many similar relationships

To provide some background context, I'm implementing a web-based solution (Java, Spring, Hibernate) that allows the creation/authoring of task-centric workflow documents. Basically a workflow ...
4
votes
2answers
73 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 ...
4
votes
3answers
169 views

interview question, friends, movies and likes

I was recently asked to implement an interface for a job interview. the class has methods to add customers and movies, the customers can watch or like movies and add friends. there are methods to get ...
1
vote
2answers
75 views

Code review for style, clarity and efficiency. Removing duplicates from linkedlist

import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; import java.util.List; class RemoveDuplicates { public static void main(String[] args) { ...
4
votes
1answer
48 views

Timing single operation to not be repeated for a fixed time

Sometimes "a" service does not respond and so we need to restart it. Usually it's a glitch in the network. We can have like 100 calls at the same time so the service cannot be restarted for 100 ...
1
vote
0answers
23 views

Calculating fields in a PERT diagram for different types of relationship

Consider this simple PERT diagram with simple End-Start-Relationships (the successor task can only begin after the predecessor is finished): ES Duration EF Cost LS Slack LS I have ...
4
votes
2answers
56 views

Merge sort in scala

I've implemented merge sort in scala: object Lunch { def doMergeSortExample() = { val values:Array[Int] = List(5,11,8,4,2).toArray sort(values) printArray(values) } def ...
0
votes
0answers
15 views

Should my login logic be part of the controller or a service in MVC webapp [migrated]

I'm using Shiro as my security manager for a Spring MVC web application. The login basically happens in these lines: Subject user = SecurityUtils.getSubject(); user.login(new ...
1
vote
1answer
78 views

Calculating sum of certain values in a list

I have two loops which I am using to create a file, if the clientID in the client loop is the same as the id in the valuation loop then create a row. Then if the month value is the same as the ...
3
votes
2answers
108 views

Need Advice and Review of my Hangman code

so I developed a code for a hangman game and what i need help in is basically simplifying, correcting and removing parts of the code that are not needed (or there is an easier way to do it). I think ...
3
votes
2answers
47 views

Passing multiple parameters from the command line in Java

I am working on a project in which I need to pass multiple arguments from the command line- Below is the use case I have- From the command line, I will be passing atleast four paramaters- ...
1
vote
2answers
92 views

Make code looks more cleaner in the run method

I am trying to insert into Database using JDBC and each thread will be inserting into database. I need to insert into around 30-35 columns. I wrote a Stored procedure that will UPSERT into those ...
3
votes
3answers
39 views

Simplify things in the run method to look cleaner

I am trying to insert into Database using JDBC and each thread will be inserting into database. I need to insert into around 30-35 columns. I wrote a Stored procedure that will UPSERT into those ...

1 2 3 4 5 16