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

2
votes
1answer
204 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
41 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
261 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
113 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
163 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
96 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
165 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
137 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
140 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. ...
5
votes
4answers
534 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
84 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
98 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 ...
7
votes
2answers
265 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
240 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
91 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
73 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
147 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
119 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
88 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
227 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
546 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
151 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
426 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
175 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
93 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
370 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
98 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
219 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
94 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
61 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
98 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
182 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
164 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
350 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
163 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
276 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
76 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
241 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 ...
2
votes
1answer
139 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 ...
1
vote
0answers
123 views

Should we encapsulate everything in a try{} block in a Try object?

Why can't I make a class for a Try including what I try and then run that in the try {} block? Why is it impractical? class DBConnectTry extends Try { TryResponse response[] attempt(TryObject ...
11
votes
6answers
592 views

alternatives to nested try-catches for fallbacks

I have a situation where I am trying to retrieve an object. If the lookup fails I have several fallbacks in place, each of which may fail. So the code looks like: try { return ...
3
votes
5answers
608 views

How should I handle exception that *should* never be thrown? [duplicate]

What is the best way to handle errors that shouldn't ever happen? My current way to do this is to throw an exception if the 'thing that shouldn't happen' does happen, like so: /* * Restoring from a ...
1
vote
2answers
99 views

Design for reusable java module which uses DB connections

I'm tasked with changing some procedural Java code into Object Oriented re-usable module. It's an XML generator utility which uses velocity for XML generation. There are also business rule ...
0
votes
1answer
150 views

Using JDBC to asynchronously read large Oracle table

What strategies can be used to read every row in a large Oracle table, only once, but as fast as possible with JDBC & Java ? Consider that each row has non-trivial amounts of data (30 columns, ...
2
votes
2answers
95 views

Is retaining intermediate objects as member fields a good idea in this case?

I'm currently writing a series of classes in java that are meant to translate a regular expression (written with the formal definition, not language-specific shortcuts) into a deterministic finite ...
1
vote
4answers
758 views

Why do C# developers newline opening brackets? [closed]

I've spent most of the last several years working mainly with C# and SQL. Every programmer I've worked with over that time was in the habit of placing the opening brace of a function or control flow ...
2
votes
3answers
135 views

How to test state of the object

I have a class DataImport with only two public methods public void fromStream(InputStream inputStream); public ImportCommand getImportCommand(); When I test it I send some test data to fromStream ...
2
votes
2answers
263 views

Dalvik + Java licensing question

This is a licensing question about the Dalvik and J2SE core libraries. In particular the license governing java.util.concurrent.SynchronousQueue. The license header of the class in the JDK source ...
0
votes
3answers
85 views

Checking for the presence of optional properties of an object

I'm designing a class that holds several types of data. Some of the properties are optional. For example, let's say I have a class that represents a person, and one of the properties is occupation. ...
6
votes
2answers
725 views

A new i/o library: a good idea or a really bad one?

For a long time I worked almost exclusively with input/output streams in java. However a few years ago I started exploring async I/O as well (e.g. running on jboss netty). However when working in the ...