Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now

Questions tagged [java]

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 bytecode and run in a virtual machine (JVM) enabling a "write once, run anywhere" (WORA) methodology.

Filter by
Sorted by
Tagged with
1
vote
1answer
117 views

Refactoring Java transmitter delegate implementation

I have 3 classes: a transmitter, a view for displaying and a recording view for flushing the screen contents into a file. The view and the recording view classes register themselves from their ...
4
votes
3answers
4k views

Design Strategy of CSV Parser

I wanted to review my design strategy for CSV parser. I have 4 CSV files, which have different layouts as shown below. Each row of a CSV file will be mapped to a class. For example, if ...
3
votes
1answer
620 views

I made a BigFraction class in Java. It's a bit slow

Thanks for looking it over. I'm still pretty new to programming. I thought this would be a good exercise in addition to making the Project Euler fraction problems easier ...
1
vote
3answers
815 views

Code Review for Adding two numbers without using the + operator

Here's my code. Please review it for correctness, readability and efficiency. If you think it can be improved also let me know. This code works fine for positive numbers but doesn't for negative. How ...
1
vote
1answer
3k views

Java concurrent Map of List

I need concurrent HashMap of List as value with following behavior: count of read/write ops approximately equals support add/remove values in lists thread safe iterations over lists After some ...
2
votes
1answer
5k views

Regular expression for application version

Only these formats are accepted. 1.1.1 1.1.1-r 1.1.1-b 1.1.1-r1 1.1.1-b1 I wrote this code. What don't I like in it? I used parentheses and now I have two groups. In fact, I don't need to do ...
2
votes
2answers
619 views

What to do with the Exception when you fail to close() a resource?

I am happy to receive all recommendations for improvement. But below I am mostly interested in a review of my handling of the exception thrown by the close() ...
14
votes
3answers
560 views

Return explicitly or implicitly?

Consider the following two code examples: 1. void foo(boolean cake) { if (!cake) return; // TODO some work. } 2. ...
-2
votes
1answer
98 views

Review of the following methods of a binary tree which contains positive integers as it's elements [closed]

I have to write methods for a binary tree that has positive integers as values. These are not full methods. They are supposed to be written in pseudocode. a) Count number of nodes in a Tree ...
3
votes
1answer
2k 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....
1
vote
3answers
77 views

Implementation of an UniqueIdentifier class

I have a requirement to implement a generic UniqueIdentifier which can cover identifiers like OrderId, TrackingID, scannableId and other Ids. The ids, as they are now, are either ...
1
vote
1answer
426 views

Opinions on my Command pattern design - is it extensible?

I am implementing a program that takes commands from a user and based on those commands, drives a Robot on a grid. To implement this program I have used the Command pattern. I have used this pattern ...
6
votes
5answers
1k views

Java screengrab

This is a short class to take screenshots on mutltiple monitor systems, I made some modifications to the solution at https://stackoverflow.com/questions/10042086/screen-capture-in-java-not-capturing-...
2
votes
2answers
334 views

TDD Approach and Simple Solution

How many tests could you write for the enum class below. I am looking for the following output given the following command: ...
1
vote
1answer
291 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:...
5
votes
2answers
1k views

Is this a correct way to use Factory Pattern?

I have an abstract class which implements the IDataCreator interface: ...
1
vote
1answer
86 views

Help creating a workable design?

I received the following feedback for my code: "I still do not see a design here that will work. It is a very bad idea to have the big switch and loop at this point. All you need in your ...
5
votes
4answers
3k views

Command line Contact Management

Can you please review the following code and give any suggestions for improvment? Class ContactList.java ...
3
votes
1answer
394 views

Enums with different methods, useful or abuse?

I'm wondering if the way I wrote our TextHelper class is a really a proper way to do it. We have products that are interlinked in different ways and every product has multiple text fields that might ...
2
votes
1answer
522 views

DAO Layer Code Review

Please review my following code for DAO layer. ...
2
votes
1answer
69 views

Merit of a “Search” class similar to a “Builder” class

I have a class something like the following: ...
1
vote
1answer
1k views

Recursive java.util.Properties references

Background A subclass of java.util.Properties attempts to recursively resolve configured properties: ...
4
votes
1answer
2k views

Java thread safety and caching techniques

This is my first Java multi-threading code. It is part of an Android application that is a client to a webpage that serves books. Each page of the book is in a separate PDF, and the Book class ...
1
vote
1answer
2k views

Partition a linked list arround an element

This is my code to partition a list into two parts according to a value. I.e. nodes smaller than value x should precede nodes larger than the value ...
4
votes
4answers
168 views
0
votes
2answers
144 views

Oriented-object approach on how to control different classes cleanly

I'm currently creating a client/server application (using Java) and I want to make it fully controllable by an input stream (currently the console). At the moment only one class have to be controlled, ...
3
votes
2answers
69 views
3
votes
3answers
2k views

Creating students and instructors

It's simple. Person is a superclass. Student and Instructor are its subclasses. The program ...
3
votes
4answers
4k views

Iterator pattern/iterator class

I have implemented a simple iterator. Just want to check if I have missed anything. ...
3
votes
3answers
2k 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? ...
3
votes
2answers
204 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: ...
1
vote
3answers
7k views

How should I read coordinates from a text file? [closed]

I have a text file with lines that look like this: ...
7
votes
1answer
129 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. ...
6
votes
1answer
258 views

Looking for a better way to define and use constants

In a custom Ant task, I have the following constants: ...
1
vote
1answer
13k 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 ...
5
votes
3answers
121 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 length)....
2
votes
2answers
2k 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 ...
1
vote
1answer
132 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 ...
7
votes
3answers
14k 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 ...
2
votes
1answer
71 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 ...
1
vote
2answers
3k 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
2answers
8k 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 ...
0
votes
2answers
2k views

Spotify's “Reversed Binary Numbers” Problem [closed]

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
126 views

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

...
4
votes
2answers
299 views

Shortening System.out - which is better? [closed]

Oftentimes people will shorten System.out to just out and make an analog called in (e.g. <...
3
votes
1answer
84 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 ...
4
votes
2answers
2k 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 ...
3
votes
2answers
2k 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- ...
5
votes
1answer
63 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 ...