Java is a high-level, platform-independent, object-oriented programming language originally developed by Sun Microsystems. Java is currently owned by Oracle, which purchased Sun in 2010.

learn more… | top users | synonyms

-1
votes
1answer
3k views

What is the best way to get a method name in runtime?

Here is a little background of my problem: I implemented a singleton logger class which is being called from several projects. I want to log the name of the class as well as the name of the method ...
1
vote
2answers
1k views

calculate complexity of LinkedHashSet

I have an ArrayList<LinkedHashSet<String>> setOfStrings for example this arraylist internally is composed like: positionX[hello,car,three,hotel,beach] positionY[.....] ... I want to ...
0
votes
2answers
96 views

Rectangle class java.lang.Object

Can someone please explain to me the difference or benefits rather to using the rectangle class ex. Rectangle r1 = new Rectangle(x,y,w,h); versus the graphics class drawRec method? ...
-2
votes
1answer
230 views

Swing component name suggestion for a specific interface [closed]

As a university project, I have to replicate Raptor. A flowchart interpreter. The interface looks like this But as I am not a experienced swing developer, I don't have much idea about which swing ...
2
votes
2answers
352 views

Is it better to draw my own graphics or import images?

I am about to start a Tetris clone using Java as my programming language. While I was designing how it'd be done, I've stumbled upon this question: What would be better, if any difference at all, ...
7
votes
6answers
4k views

How to avoid downcasting?

My question is about a special case of the super class Animal. My Animal can moveForward() and eat(). Seal extends Animal. Dog extends Animal. And there's a special creature that also extends ...
0
votes
1answer
269 views

Sortable listview using SQLite [closed]

I'm implementing a sortable listview using bauerca's library here. This works, but now I need to define some things where I need some help. This is the functionality of my app_ I can create up to 5 ...
6
votes
4answers
7k views

Is it safe to convert Windows file paths to Unix file paths with a simple replace?

So for example say I had it so that all of my files will be transferred from a windows machine to a unix machine as such: C:\test\myFile.txt to {somewhere}/test/myFile.txt (drive letter is irrelevant ...
8
votes
4answers
663 views

What complexity do DI frameworks add?

The currently most upvoted answer to a very recent question states that DI containers are an "enterprise software" pattern, used when the object graph is very large and complex. I suspect that 95% ...
5
votes
2answers
457 views

I don't know how to understand the Wildcard type in Java

I am reading the Core Java (9th edition) by Cay S. Horstmann and Gary Cornell. After making an effort, I cannot still understand the ? super Manager. Here are some materials relating to this question. ...
1
vote
1answer
107 views

Reference wind directions to texture space?

I have a 2D array filled with a simple class: class Tile { boolean N,E,S,W; } I also have a tilesheet representing all possible outcomes except all false (12 + crossroad). Now i need to ...
2
votes
2answers
3k views

Where to start when designing an application that allows plugins [closed]

I'm building an application, and I'm thinking long-term I would like to be able to allow plugin support. The application I'm creating is a Java based application. How could I allow plugins using a ...
0
votes
1answer
219 views

Why/how does Java use a controlled mechanism to pause threads for GC?

I know that Java uses a controlled mechanism to allow threads to be paused. If I understood correctly, they put a read from a protected page at the end of e.g. loops, and change the protection of that ...
20
votes
7answers
4k views

Is there a more intelligent way to do this besides a long chain of if statements or switch?

I'm implementing an IRC bot that receives a message and I'm checking that message to determine which functions to call. Is there a more clever way of doing this? It seems like it'd quickly get out of ...
14
votes
2answers
7k views

Can someone explain in simple terms what is the disruptor pattern?

I would like if you could explain to me in a simple way how does the disruptor patter work. This concept has been elusive to me as of know. Perhaps with your help I could comprehend it.
0
votes
1answer
446 views

Object Oriented Design of a Small Java Game

This is the problem i am dealing with. I have to make a simple game of NIM. I am learning java using a book so far i have only coded programs that deal with 2 classes. This program would have about ...
0
votes
1answer
514 views

How can I write byte[] to socket outputstream and specify the end of file?

I've googled 2 days straight and I can't find how to do this. I have an open stream between client and server, and client will send a JSON string (encrypted to bytes) to the server each 3 to 5 ...
2
votes
2answers
290 views

blurry lines between web application context layer, service layer and data access layer in spring

I'll admit I'm a spring newbie, but you can correct me if I'm wrong, this one liner looks kinda fishy in a best practices sort of way: @RepositoryRestResource(collectionResourceRel="people"...) ...
5
votes
2answers
251 views

Can decoupling hurt maintainability in certain situations?

Can the fact that the business logic is mapped to interfaces instead of implementations actually hinder the maintenance of the application in certain situations? A naive example with the Java's ...
0
votes
2answers
432 views

Java best practice Interface - subclasses and constants

In the case where a couple of classes implements an interface, and those classes have a couple of constants in common (but no functions), were should I put this constant ? I've had this problem a ...
2
votes
4answers
5k views

Regex to String generation

Let's say that we have a regex and an index i. If we suppose that the set of strings that match our regex are sorted in a lexicographical order, how could we get the i element of this list? Edit : I ...
2
votes
1answer
492 views

Access Token Verification

I have spent quite a few days reading up on Oauth and token based security measures for REST API's and I am currently looking at implementing an Oauth based authentication approach almost exactly like ...
1
vote
1answer
359 views

Are there theoretical reasons why arrays in C take less RAM than Java?

My experience is that Java requires about twice as much RAM compared to C (comparing char arrays or other comparisons). I also read in a hardware book that Java takes about twice RAM than C. Is is ...
0
votes
0answers
797 views

Multidimensional multiple-choice knapsack problem: find a feasible solution

My assignment is to use local search heuristics to solve the Multidimensional multiple-choice knapsack problem, but to do so I first need to find a feasible solution to start with. Here is an example ...
0
votes
3answers
200 views

In which object should I implement wait()/notify()?

I'm working in an Android project with multithreading. Basically I have to wait to the server to respond before sending more data. The data sending task is delimited by the flag boolean ...
4
votes
1answer
313 views

Declarative Transactions in Node.js

Back in the day, it was common to manage database transactions in Java by writing code that did it. Something like this: Transaction tx = session.startTransaction(); ... try { tx.commit(); } catch ...
2
votes
3answers
914 views

Software architecture for two similar classes which require different input parameters for the same method

I am writing Java code to simulate a supply chain. The supply chain can be simulated in either an intermediate stocking or a cross-docking configuration. So, I wrote two simulator objects ...
0
votes
0answers
103 views

Appropriate design / technologies to handle dynamic string formatting?

recently I was tasked with implementing a way of adding support for versioning of hardware packet specifications to one of our libraries. First a bit of information about the project. We have a ...
0
votes
1answer
199 views

Interconnect nodes in a Java distributed infrastructure for tweet processing

I'm working in a new version of an old project that I used to download and process user statuses from Twitter. The main problem of that project was its infrastructure. I used multiple instances of a ...
0
votes
2answers
2k views

Best Practice: What can be the hashCode() method implementation if custom field used in equals() method are null?

What is the best practice to return a value for hashCode() method if custom field used in equals are null ? I have a situation, where equals() override is implemented using custom fields. Usually it ...
5
votes
1answer
885 views

Why are most GNU's software written in C [closed]

I am a Java developer, and I rarely write GUI program in C. However, I noticed that many GNU's projects, such as PSPP, R, Dia, etc., are written in C, instead of Java or C++. I personally don't mind ...
1
vote
1answer
962 views

Session serialization in JavaEE environment

Please consider the following scenario: We are working on a JavaEE project for which the scalability starts to become an issue. Up until now, we were able to scale up but this is no longer an option. ...
2
votes
3answers
989 views

How can I be certain that my code is flawless? [duplicate]

I have just completed an exercise from my textbook which wanted me to write a program to check if a number is prime or not. I have tested it and seems to work fine, but how can I be certain that it ...
-1
votes
3answers
428 views

Condition to use polymorphism

is polymorphism only possible when there is a scenario of inheritance or is the implementation of polymorphism not dependent on inheritance. Or is polymorphism mainly usefull when there is ...
-1
votes
2answers
264 views

what's the point of method overloading? [duplicate]

I am following a textbook in which I have just come across method overloading. It briefly described method overloading as: when the same method name is used with different parameters its called method ...
6
votes
3answers
327 views

How to refactor my design, if it seems to require multiple inheritance?

Recently I made a question about Java classes implementing methods from two sources (kinda like multiple inheritance). However, it was pointed out that this sort of need may be a sign of a design ...
4
votes
1answer
587 views

The purpose of using a constants pool for immutable constants

I come across the following code with a lot of frequency: if (myArray.length == Constants.ZERO_INT) or if (myString != null && !myString.equals(Constants.EMPTY_STRING)) Neither of ...
2
votes
1answer
624 views

Why are interfaces called interfaces? [closed]

From what I understand so far, an interface is a list of methods that need to be implemented by whoever wishes to use that interface. If so, would it make any difference to call it a specification ...
5
votes
0answers
298 views

How can I make a universal construction more efficient?

A "universal construction" is a wrapper class for a sequential object that enables it to be linearized (a strong consistency condition for concurrent objects). For instance, here's an adapted ...
0
votes
0answers
89 views

How to structure my java packages [duplicate]

I have a Java library, quite a huge one. I'm asking regarding Best Practices of structuring the source. For example, the logging sybsystem: Option 1: All in one package, named to sort nicely Log ...
4
votes
4answers
2k views

Is it feasible and useful to auto-generate some code of unit tests?

Earlier today I have come up with an idea, based upon a particular real use case, which I would want to have checked for feasability and usefulness. This question will feature a fair chunk of Java ...
1
vote
1answer
374 views

How does an optimizing compiler react to a program with nested loops?

Say you have a bunch of nested loops. public void testMethod() { for(int i = 0; i<1203; i++){ //some computation for(int k=2; k<123; k++){ ...
27
votes
4answers
7k views

Builder Pattern: When to fail?

When implementing the Builder Pattern, I often find myself confused with when to let building fail and I even manage to take different stands on the matter every few days. First some explanation: ...
1
vote
1answer
921 views

Store scores for players and produce a high score list

This question is derived from an interview question that I got for a job I was declined. I have asked for code review for my solution at the dedicated Stack Exchange site ...
5
votes
2answers
906 views

Where to store global enterprise properties?

I'm faced with a crowd of java applications, which need different global enterprise wide properties for operation, for example: hostname of the central RDBMS, hostname and location of the central ...
0
votes
2answers
5k views

Question about casting a class in Java with generics

In Java 6 Class<? extends ArrayList<?>> a = ArrayList.class; gives and error, but Class<? extends ArrayList<?>> b = (Class<? extends ...
4
votes
3answers
1k views

Inheritance vs containment while extending a large legacy project

I have got a legacy Java project with a lot of code. The code uses MVC pattern and is well structured and well written. It also has a lot of unit tests and it is still actively maintained (bug fixing, ...
1
vote
2answers
726 views

java.util.HashMap lock on actual HashMap object compare to lock on object that encapsulate the HashMap

The below Javadoc is an snippet of HashMap documentation. Why authors would emphasize on putting a lock on the object that encapsulate a HashMap? Lock on the actual HashMap Object makes for sense. ...
2
votes
1answer
201 views

How to fix poorly designed software? [closed]

I am working on large project solo as a hobby, and I made a mistake in the very beginning: I jumped right into programming without giving a second though to design. Now I am nearly 6 months in and ...
2
votes
1answer
356 views

How to avoid overhead while still implementing null object pattern?

I am implementing a binary search tree in java. Inside the BST class I have a protected class Node (in case I want to extend to an AVL tree). The code is below. I had a problem, both conceptually and ...