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

CPU under full load java web app (tomcat)

I've tomcat running on my Macbook pro and a web application. Making a request to a servlet (below i'm showing post method code) and tipping top command in terminal show a java process with 200/300% ...
3
votes
2answers
506 views

My first OOP piece… how have I done?

This is my first OOP coding project and I would appreciate any constructive criticism as to how I could have used the benefits of Java and OOP to better effect. How would you have implemented this ...
1
vote
2answers
208 views

Question on where to put code logic

I am developing a small compiler like tool. In the process, I wrote a Class<?> wrapper, JavaClass: ...
8
votes
1answer
2k views

Parse Java source code

I have a bunch of simple interfaces like this one (pretty enough formed, but not guarantee) ...
5
votes
1answer
768 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 ...
2
votes
2answers
183 views

How can I improve this code to display contact numbers?

I am making an Address Book like application . I have a contactType enum. public enum ContactType { //just a cut down version MOBILE,PHONE,FAX,EMAIL; } ...
2
votes
1answer
113 views

Externalize to a function

I have the following code block which I'd like to refactor into a method, I just don't see a good way to get the following code into a method which doesn't have multiple responsibilities. Here is the ...
4
votes
1answer
5k views

EPUB reader for Android

How do I improve this code for reading an epub file? The code is as follow: ...
10
votes
4answers
1k views

Vegetable factory

I'm new to Java. I'm trying to build a simple hierarchy of classes. ...
5
votes
1answer
5k views

Singleton class extending a parent class to utilise shared functionality

I have a singleton class which extends from an abstract java class. Two singleton classes extend from ItemImageThreadManager, the reason for this is to use shared ...
6
votes
1answer
188 views

Determine which level of the text that it is currently parsing

So I have this code in my program, and there are multiple variations of it. Just looking at it, I feel like there must be a way to make it more efficient, but I can't think of anything. Just looking ...
2
votes
3answers
10k views

Exception handling continuing the excecution

This code is for continuing the execution after an exception, and this is ugly: ...
7
votes
1answer
2k views

Java Slick StateBasedGame managing resources across states

I was wondering if it's normal/efficient to have this many static collections in my state based game? I started doing it for ease of access but it looks sloppy to me and I was just wondering what ...
1
vote
1answer
335 views

Java API code with Spring

Model: ...
2
votes
1answer
5k views

Getting permutations of a set

I'd like some feedback on my implementation to get all the permutations of a set. Eg: ...
3
votes
1answer
3k views

Writing to an HttpURLConnection in a loop

I have this method which sends binary data to server. The code works fine, but still, it's structure is kinda stupid: output and input connections are opened like thousands times (depends on data size)...
2
votes
2answers
98 views

applyFactors refactoring

I have inherited the Java function below, and it works the way it should, but you have to look at it for a minute to figure out exactly what is going on. Is there a more succinct or elegant way to ...
3
votes
2answers
1k views

Java: Worries about my implementation of MVC in a GUI Application

This is a question I have in regards to my implementation of the MVC design paradigm that I came up with. The MVC type I am using is where everything must go through the controller. No communication ...
5
votes
2answers
345 views
6
votes
1answer
122 views

Refactoring code duplication so the same textArea is not used in 4 different classes

Looking for the best way to do this. Currently in 4 different classes I have: ...
2
votes
4answers
209 views

looking for OO input , is any of this code good OO or am i doing it all wrong?

Some code im working with for a stock system , i have two ways to do this, looking for review on if any of them are correct and if so which one is better OO than the other ...
2
votes
1answer
310 views

How can i clean and organize up my View (MVC) better

So i got the grip on the basic MVC patterns in java using Observer / Observable method. Now in interest of keeping it clean and readable i would like some pointers before i move on regarding how to ...
6
votes
1answer
3k views

Can this simple percentage calculator be further optimized?

public double getValueWithPercentage(double number, double percentage) { return number + ((percentage / 100.0) * number); } Are there any tricks to optimize ...
3
votes
2answers
6k views

Boolean flags encoded as integer implemented with EnumSet

I'm a beginner in Java so I would appreciate a review of following simple class - in fact it's my first real usage of enums. The background: I'm parsing MySQL internal client-server protocol. One of ...
6
votes
5answers
659 views

Simple function in Java

This is a JUnit asserts for this function: ...
1
vote
2answers
5k views

How to delete last element in java.util.Set efficiently?

...
3
votes
2answers
12k views

Queue Implementation

First time I'm using stackexchange. I'm in 8th standard. I tried to implement Queue in Java. I wrote something like this> Right now I'm not able to test it because I don't have JVM in my machine. So I ...
3
votes
3answers
325 views

connect in a background until success

We have some required services down temporarily when our server start. So we need some reconnection logic for them until they are finally up. There is a requirement to have also syncronious way for ...
4
votes
5answers
700 views

Synonymiser refactoring

I am interested in seeing how people would refactor this code to make it more readable, remove local variables, etc. The code checks a string against a number of arrays. The first (0) field of each ...
2
votes
1answer
149 views

Improvement of this method

I'm coding a small web app with no real functionality. It's like a pilot program for something bigger. What I want is construct a program that works as a clock on/off for a restaurant. Actually I'm ...
3
votes
3answers
242 views

Struggling to refactor code to remove duplication

I really need some help removing some duplicated code. I've linked the methods causing me issues. http://pastebin.com/cZJihM4J As you can see each method does similar things but retrieve different ...
3
votes
1answer
1k views

Concurrent event counter/averager utility classes

For a personal project, I'm working on a Java profiler that specifically targets ThreadPoolExecutor and its subclasses and provides statistics about throughput of executed tasks. To support this I've ...
2
votes
1answer
109 views

Separate construction phase from constructed phase

I am sure you can find many weak spots, please let me know about them. My main question is if this is a sensible approach to separate the construction phase from the constructed phase. Basically I ...
2
votes
1answer
430 views

Converting timezone for date using java

I have written this method for converting a date time zone. How do i reduce the execution time of this method further. ...
6
votes
1answer
325 views

Does this code fall into a design pattern?

CustomDialog is the parent abstract class for OkExclamationDialog and ExclamationDialog with ...
6
votes
1answer
393 views

Merging two array of classes

I have this function that should merge two array of classes when id of array1 is equal to id of array2. For simplicity I ...
2
votes
2answers
2k views

How to make a int not be used twice when it randomly generates them? [closed]

I've coded a simple quiz game for Android, and currently Im having troubles with making questions not appear after they've been shown, i.o. I dont want it to ask me the same question twice.. This is ...
2
votes
1answer
7k views

Validating files and returning errors messages/boolean values

I am writing simple file validator for my java ee app and I am stack with my class api. I need specific error descriptions, but also I would like to have boolean values indicating whether file is ...
5
votes
1answer
204 views

Indented if/else approach

I have a flow where if a certain condition is true then I should take another approach. That condition can be triggered by different scenarios. But each condition test must be done only if the last ...
1
vote
2answers
14k views

Bouncing ball - for swing event handling tutorial

This is a sample program that I intend to post as part of a series of beginner level Java tutorials. Please provide any feedback on improvements that would make example more clear or illustrate/...
4
votes
1answer
248 views

Super class knowing the type of its children? Surely there is a better way

I'm working on a small project that does mathematical calculations based on selected data in a JTable. The goal is to make the program fairly adaptable for adding new mathematical calculations in the ...
2
votes
2answers
8k views

reorder a list in java

I have three ways of reordering a list (think baseball order) and I am sure you can come up with more. What is a the best way? For example if input is list is 1,2,3,4 and current is 3 then the ...
2
votes
1answer
3k views
1
vote
1answer
644 views

Use generic to prevent duplicate code in this case

I have this class hierarchy. I want to apply generics to it but don't know how to do. AddWikiTask, ScanTask and RescanTask are subclasses of AbstractWorkerTask. DictionaryScanner has 3 functions to ...
6
votes
3answers
997 views

Is using java enums to store filepaths good practice

I'm working on an android application, but this is basically plain 'ole java. The aim is to do the right thing and not repeat myself. ...
3
votes
1answer
238 views

What improvements can I make to avoid these If statments?

I have Model Object Car. public class Car { private String colour; private String make; private String yearOfMake; } Then a managed bean ...
6
votes
2answers
2k views

What constructor implementaton follows best practice in Java

I am looking for best practices as they apply to constructor usage in common Java class construction. Example 1 ...
5
votes
1answer
186 views

Ternary gate handling - more succinct way then a bunch of if statements

I have classes representing gates (OR, XOR, AND etc) with the following method that is called whenever a property changes. Here is the XORGate code: ...
4
votes
5answers
813 views

Request for Comments: Singleton pattern implemented in Java

I have several utility classes who should only ever have one instance in memory, such as LogHelper, CacheHelper, etc. One instance to rule them all. I've never implemented Singleton in Java before, ...