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
vote
1answer
166 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 ...
1
vote
3answers
104 views

Best way to find whether a collection does or does not contain an element with a specific desired quality

It seems to be a very common thing to have to tell whether some list or set contains at least one object matching a given condition, yet my prior searching and reading have never found a satisfactory ...
1
vote
3answers
184 views

Is it appropriate to remove redundant code explicitly assigning the default values?

Sometimes while I'm editing something I see some useless code added by other developers, probably due to habit. Editing this code will not make any difference, so is it appropriate? In my specific ...
4
votes
2answers
241 views

Why are there no function pointers in Java? [closed]

Lately I started studying about different interesting concepts that exist in languages other than Java. Since the only language I've ever programmed with is Java, a lot of these concepts are very new ...
4
votes
5answers
463 views

Why is there no deterministic object destruction in Java? [duplicate]

I understand and enjoy the benefits of the Garbage Collection in Java. However I don't understand why there is no way in Java to explicitly (and quickly) destroy an object. Surely this could be useful ...
2
votes
1answer
98 views

Separate Action from Assertion in Unit Tests

Setup Many years ago I took to a style of unit testing that I have come to like a lot. In short, it uses a base class to separate out the Arrangement, Action and Assertion of the test into separate ...
3
votes
3answers
252 views

If I unite many web apps into one, will I save resources?

I'm comparing 2 different approaches of J2EE application architecture: Divide independent parts as modules of one big web app. Divide independent parts as different web apps running on same server. ...
2
votes
2answers
81 views

Retried Operation with generic Exception

I am looking for a way to get the logic of retrying an operation in a single method while keeping the exception types of the operation. I.e., the implementation to retry an operation could look like ...
1
vote
1answer
283 views

Should we push for more JavaScript on the JVM, alongside Java and Scala? Or, if not, why?

With JavaScript becoming one of the most widely used languages around, I began asking myself why people do not find ways to use it extensively on the JVM. As a programmer who spends half day writing ...
2
votes
2answers
261 views

When should you use Local Classes in Java?

I learned about local classes on the Oracle Java Tutorial page. Not nested classes. I don't see myself using local classes. It makes the code look messy and you can easily do what local classes do ...
2
votes
1answer
202 views

How to design the relation between a Game and a Player in a game?

I am currently attempting to make a Trading Card Game and I have got a whole array of features working already, yet I am stuck now at the portion where one player can attacker another player (more ...
0
votes
0answers
40 views

A 'task' system which has an ending, to get ready for next task

I want to make a system, so that there are certain tasks. For example, let's talk about a game. I want to make it so there are 100+ tasks doing different things, but when the player's magic level is ...
-1
votes
4answers
248 views

Why is Java not 'pure' OOP? [duplicate]

Java is designed in a very OO approach, and somewhat even 'forces' programmers to program within the OO paradigm (which can be considered good or bad, a matter of opinion). However while almost ...
0
votes
1answer
104 views

Type Safety of Spray.io

Yesterday I read a tweet disparaging Jersey with JAX-RS due to run-time errors. Spray.io was mentioned in the tweet: Not even 5 minutes using Jersey / JAX-RS and already a runtime error due to a ...
2
votes
1answer
123 views

Calling static method from instance of class

As a developer I am fan of static methods. Recently I come across difference between OOP languages about this static methods. All OOP language use static method to access any method without ...
3
votes
1answer
90 views

Managing resource paths in source code

I suspect this is something that many of you guys have dealt with, and I'm certain there's articles on how to do it, but I cant seem to find them. My problem is that my various constant classes in ...
0
votes
2answers
156 views

Benefits of Java in education? [closed]

I hope this isn't too off-topic and/or opinion based. I'm looking for examples and reasons why Java is an acceptable language for education purposes. Here's why: I learned programming on my own in C ...
0
votes
2answers
134 views

Is using interfaces on internal code a good idea? [duplicate]

I'm working on a set of automated tests that we use internally at work. Lately, we've been designing classes that implement interfaces in addition to inheritance. As I understand it, interfaces in ...
0
votes
2answers
132 views

How other thread can show the incremented value unless the 1st thread reaches the return statement?

My code is given below. In the for loop I am getting unexpected output i.e. before completing the execution of for loop by 1st thread the 2nd thread comes in for loop and shows incremented value. ...
4
votes
4answers
516 views

Why do arrays in Java not override equals()?

I was working with a HashSet the other day, which has this written in the spec: [add()] adds the specified element e to this set if this set contains no element e2 such that (e==null ? e2==null : ...
1
vote
1answer
72 views

How to migrate an XML serialization framework in Java in a tightly coupled system?

I work for a company that uses XML for storing a bunch of serialized Java classes. The framework we use is Apache Betwixt (abandonded in 2008) and it's kind of pain to maintain and extend (it seemed ...
2
votes
1answer
81 views

Passing multiple errors back from service layer

I am using Spring for a web application. To validate a user's input in a form such as for creating a Person entity I user JSR 303 validation to check for not null/empty or valid patterns etc.. Some ...
6
votes
1answer
217 views

How to hide AOP implementation dependency without breaking encapsulation?

I have the concept of a SlowLoading thing: public interface SlowLoading { boolean hasLoaded(); } I also have a component MyComponent: public interface myComponent{ void doSomething(); } My ...
1
vote
2answers
199 views

Generating PDF files using individual template components

EDIT: Updated flow diagram to better explain the (likely unnecessary) complexity of what I'm doing. We at the company I work for are attempting to create complex PDF files using Java iText (the ...
0
votes
2answers
88 views

When one thread out of four is executing first line in run() then at the same time what will remaining three threads do?

I have four thread instances and they are executing run() code given below: public void run (){ System.out.println("1st line :"+Thread.CurrentThread().getName()); System.out.println("2nd line ...
2
votes
1answer
71 views

How to present domain model exceptions thrown through validation

In domain model of my web application I've an entity Foo which can be created only by a pojo FooBean: Foo.newInstance(FooBean fooBean) (Might have been better a Builder-pattern.) In the factory ...
2
votes
2answers
143 views

Is there any reason not to use Optional as a method argument in the case where you know the argument is something that may or may not be needed?

With Java 8, I've seen more and more articles about the use of Option/Optional. I understand what they trying to represent, and I see many examples of them being used as returns. However what I don't ...
1
vote
1answer
109 views

From a DDD perspective is a report generating service a domain service or an infrastructure service?

Let assume we have the following service whose responsibility is to generate Excel reports: class ExcelReportService{ public String generateReport(String fileFormatFilePath, ResultSet data){ ...
2
votes
2answers
76 views

static set and non-static get method

I've the following Interface. public interface ValueInterface { long getValue(); } And the class: public class ValueCreator implements ValueInterface { private static long value = 0; ...
2
votes
1answer
223 views

Why does Java support brackets behind variables and even behind method signatures? [closed]

Java allows this: class X{ int i,j[]; // j is an array, i is not } and even worse, it allows this: class X{ int foo(String bar)[][][] // foo actually returns int[][][] { return null; } ...
3
votes
2answers
537 views

Should I use initializer blocks in Java?

I recently came across a Java construct I have never seen before and was wondering whether I should use it. It seems to be called initializer blocks. public class Test { public Test() { /* first ...
0
votes
2answers
149 views

How to debug weak references? [closed]

How can I test (what tools do I use) if my reference graph is correct and if objects are released at appropriate times (and there are no memory leaks)? In my case I'm using Java, but answers related ...
4
votes
2answers
380 views

Why prefer non-static inner classes over static ones?

This question is about whether to make an inner class in Java static or not. I searched around here and on StackOverflow, but couldn't really find any questions regarding the design implications of ...
0
votes
1answer
154 views

Why does storm not supply a mechanism for supplying topology necessary dependent jars other than the fat jar?

Following is a question that I had posted at the incubator-storm-user mailing list (verbatim). I had decided to open up the question here as well, because it also contains a conceptual side to it, ...
2
votes
1answer
91 views

What's the right OO way to create a counter/inventory class that works for both differentiated and undifferentiated countables?

You are writing a videogame about trading beans. Red beans, black beans, pinto beans, you name it. As everybody knows all beans are the same. You write the "Inventory" class for a trader in that ...
-2
votes
3answers
220 views

High Level design vs Low Level design? [closed]

Folks i am not sure what actually comes under HLD and what under LLD? . I did google but most of the answers are contradictory and theoritical. Say i need to design the login process in web ...
1
vote
1answer
83 views

Accessing a remote server from desktop application

Web applications (.jsp / Java) have the advantage that they can be run from any client browser by putting a single URL into the address bar, and off you go. However, the average web application is ...
3
votes
4answers
213 views

Why is there no 'subclasses-only' access modifier in Java?

In Java, there are four available access modifiers for methods: public - any class can use this method. protected - classes in the same package and subclasses in any package can use this method. ...
0
votes
3answers
90 views

Wrapping a map with instance or static method

I have a java.util.Map<String, Object> object which different types of values in it. I don't want to cast whereever I do a get operation over this. To do this, I created different classes ...
-4
votes
1answer
58 views

How do we call database table entity in Java? [closed]

For each database table, I create an entity (object) which contains all columns of the database as Class fields. Now, how do we call these entities in Java? I could not find an official term so I ...
1
vote
1answer
91 views

Serpent Algorithm thats implement Cipher

How must i change the Standard Implemplementation of the Serpent Algorithm that i can use it with the javax.crypto.CipherInputStream or javax.crypto.CipherOutputStream? I must implement/extends the ...
0
votes
2answers
173 views

.properties files in regular src folder okay? [closed]

I work on a Java project with a suggested structure (separate src folders for java files and resource files). After moving the message / text related properties files to that folder, the externalize ...
1
vote
1answer
163 views

Where should I put bindings for dependency injection?

I'm new to dependency injection and though I've really liked it so far, I'm not sure where bindings should go. I'm using Guice in Java, so some of what I say might be specific to just Guice. As I see ...
7
votes
3answers
349 views

Object Identity and Mutability

I was reading a proposal for value types in Java, and I came across this sentence: "Object identity serves only to support mutability, where an object’s state can be mutated but remains the same ...
-4
votes
2answers
159 views

Java FOR loop - don't understand this example [closed]

I am currently teaching myself Java. I have working through a book but there is this example below which I am not sure what is happening... class Elements { public static void main (String[] args) { ...
0
votes
2answers
262 views

How to enforce good coding style in team? [duplicate]

Even if I don't like enforcing people to do things (and I believe that it may decline the productivity and cause anger), I really want to enforce good coding style. Is there a way to set up ...
0
votes
1answer
67 views

Making the server request with high priority

I need to connect to a server and do manipulation with respect to HTTP GET and POST for my application and the server is generally used to handle multiple users with heavy load and many users might be ...
1
vote
4answers
234 views

Alternatives to null values and option-like types

Related to this question i want to know if there is a concise way to eleminate null values out of code in general or if there is not. E.g. imagine a class that represents a user with birthday as ...
-10
votes
1answer
119 views

Unable to write the content to a file in Java [closed]

I am unable to write the contents to the file in Java. The program compiles and executes well, file gets created but content is not written. Here is my code: import java.io.*; import java.util.*; ...
2
votes
1answer
135 views

Naming test methods in Java [closed]

Over at codereview a comment hinted that using snake_case to name test methods is a good idea. This contradicted my views and I did some research and there seem to be a lot of examples that actually ...