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

0
votes
0answers
56 views

Embedding custom business logic using Javascript in Java application

We have an application where the front-end is completely rendered dynamically. The web page is stored as JSON in the database. A simple JSON to display input field with a label is as follows: { "...
0
votes
0answers
35 views

Inheritance and Parcels

In Android development, we have Parcelable interface. Since I wish to build Data Models that will run on multiple apps and services (not just Android), I would like to add two jar libs that will share ...
1
vote
1answer
73 views

Is this indexed approach to java rts game development valid and how can I improve it?

I have class GameState laid out to basically hold an Array of Players, an Array of StarSystems, and a few other fields that need to persist from save to save. Each GameObject keeps track of its own id,...
1
vote
2answers
76 views

Passing and returning domain object in create method

We have this bean with two properties: ContainerImage + name (final, not null) + id (null) Then there is this method: ContainerImage create(ContainerImage containerImage); It receives ...
0
votes
1answer
118 views

How to setup multiple queries with slight differences

I'm writing a page that will show the user statistical data about some of our products. Basically the user can get results between a specific time frame, and also add on other data to lookup by. For ...
0
votes
3answers
170 views

A very basic question about whether I should check for null and throw NPE? [duplicate]

Consider the below method- public void operationOnList(List<String> list) { list.add(1); } It is obvious that if l is null this method will throw a NullPointerException. My question is ...
1
vote
1answer
96 views

When we need to serialize an exception

I have been developing in Java since 8 months, and I didn't face a case where I went to serialize an exception, I'm asking because I saw the serialVersionUID and how Eclipse advise to add it ...
2
votes
2answers
135 views

Placing preconditions in the right place

I am trying to figure out the best way to define the responsibility of checking preconditions. Let's consider the following case: we have an Event class representing a sports event and a Matchup ...
2
votes
1answer
129 views

What are the limitations of Java exception approach to errors?

Please ignore performance issues, I am interesting in data flow, safety, modelling, reasoning. I wonder what are the limitations of exception approach to error reporting implemented like in Java ...
2
votes
1answer
140 views

Choice of variable names and types in graph algorithm

I am learning algorithms and data structures from this awesome resource Algorithms. Rather than doing dry reading I am trying to re-write all the code myself so that I can learn coding as well as ...
2
votes
5answers
350 views

Why do I need to declare virtual functions as such?

Example: We have a base class Base and three subclasses which all implement their own version of doSomething(). In an intermediate function f(Base b), we want to call the relevant version of ...
4
votes
3answers
116 views

Passing a private member collection to another class

Suppose I have a Map which is a private member variable of my class A. In the same class I create an instance of class B, call it objB, by passing the map to B's constructor. Obviously this is ...
0
votes
2answers
100 views

Best Communication strategy for monitoring dashboard

I have a requirement where I need to display certain stats on Admin Dashboard in my web application (Angular+Java). These stats (transnational data) are being generated on different servers (connected ...
2
votes
3answers
148 views

C++ vs Java: Pointing to Objects

In Java: private State current_state; As "State" is a superclass, I can then assign subclass objects to current_state, effectively making current_state point to a different object: current_state = ...
0
votes
0answers
33 views

Better way to model parallel implementations of specialised collection-like types

I am working with some wrappers for selection widgets on the web (in Selenium). They each have one "parent" type that represent the widget and another type for the options. Two interfaces are created ...
3
votes
2answers
94 views

Creating Instances from same SuperClass Object

I have 3 subclasses (LowState, MediumState, HighState) which derive from the same superclass (State). Within the superclass, State, I have declared several variables which need to be accessed and ...
0
votes
2answers
122 views

Could Java XYZ implement (limited) Operator Overloading without breaking backwards compatibility?

Recently, I've been learning a bit more of C++ and the dangers and uses of operator overloading, and the readability boost it provides to arithmetic types (like Complex numbers). A while ago, I was ...
1
vote
3answers
251 views

How to store many global variables?

I have around 30 not-changing "objects" (the amount of them is final, no more can be added or removed). Each object has an id as well as some booleans describing what the object is and what it isn't. ...
0
votes
3answers
148 views

Cyclic dependency in this project design

I have 2 modules (containing multiple classes). Let's call them Module A and Module B. Module B has a dependency on Module A: Module B -> Module A. Now, I have created an utility class C, which A ...
5
votes
1answer
70 views

Discoverable default implementation of an interface

I have a couple of simple classes that implement the Null Object pattern. To illustrate the hierarchy, let's define a Config interface with two classes implementing it ConfigItem and MissingConfig, ...
2
votes
1answer
155 views

Should I return Iterable or Enumeration in Java

In order to achieve better immutability, should my API return java.lang.Iterable<T> or java.util.Enumeration<E>? Since Iterable has a remove() method, one could say Enumeration is the ...
2
votes
4answers
289 views

Is it strange for a Builder object to have getter methods?

I have a fairly complex immutable data type that I'm using a builder object to instantiate. Currently, I have a setup where I parse a file, setting various fields in my builder, and then build the ...
1
vote
1answer
40 views

Redesigning schedule value hierarchy

I have a couple of schedule value classes that represent the value a schedule holds for a specific slot. First, there's the ScheduleValue class for schedules with two dimensions, where the first one (...
2
votes
2answers
186 views

Image resizing client side vs server side

When uploading a lot of images to a server, to minimize the space taken by the images, is it better to resize the images before sending to the server or upon receiving them? It seems to me that ...
5
votes
6answers
426 views

Dependency injection: should I use a framework?

I have recently worked on a Python project where we did dependency injection heavily (because we must in order for the app to be testable), but we didn't use any framework. At times it was a little ...
4
votes
3answers
229 views

Enums and single responsibility principle (SRP)

I have been experimenting lately with enums, and I found out that in Java they can do much more than simply representing a fixed set of constants. Now, I am thinking about creating a new enum for my ...
9
votes
3answers
231 views

Breaking API changes: how can I make the transition easy for library users?

In the past, I used the standard way of adding @Deprecated annotations to API methods which will be removed in a later version. Now I am preparing a major version for a library, with many API parts ...
1
vote
3answers
100 views

Xml Messages: One Type to Rule Them All?

My job involves a project that has a lot of different pieces that all need to communicate via XML messages. There are two schools of thought on how these messages should be organized. In reality ...
49
votes
10answers
11k views

Why would the 'final' keyword ever be useful?

It seems Java has had the power to declare classes not-derivable for ages, and now C++ has it too. However, in the light of the Open/Close principle in SOLID, why would that be useful? To me, the ...
1
vote
2answers
108 views

Get variable with accessor method or just use dot notation?

So, I recently noticed something on some code I was writing. I could get a variable for a different class/object using dot notation to get the variable: object.someVarable or I could do it the way I ...
0
votes
1answer
57 views

Splitting API and Implementation among packages/jars

I have a dilemma. How to do better? I have a bunch of API interfaces and their implementations which use some specific frameworks/librarys which I would not like to expose. I cannot make a decision ...
0
votes
0answers
81 views

What is a good design to couple/relate methods and references?

I am implementing a trigger system. There are objects that take the role of observers (this is not strictly an observer pattern because the observers are inter-dependent, see my question here). They ...
0
votes
0answers
41 views

How does Hibernate Cascade on OneToOne work under the hood

I have the following entities corresponding to tables into DB: User, UserAttempt; User has a FK to UserAttempt, and UserAttempt has no knowledge of User. If I do the following inside a transactional ...
0
votes
0answers
73 views

How did “Stub” and “Skeleton” get their names?

In Java remote method invocation, the abstract method on the client-side is called "stub", which communicates with the "skeleton" on the server side and gets back the results. But why the names? For ...
-1
votes
2answers
152 views

Class name in java should be camelcase - mandatory or not?

According to oracle docs: the class name in java should be nouns, in mixed case with the first letter of each internal word capitalized. Is this just a good practice rule or a mandatory rule? (I'm ...
5
votes
4answers
200 views

Idiomatic pattern matching equivalent in Java

I'm building a simulator which parses some events from STDIN and "runs" them. My background is mostly functional programming these days, so it seemed natural to do something like this: datatype Event ...
-1
votes
2answers
56 views

Parse expressions on custom interpreter

I'm currently developing my own (sort of) programming language. It currently looks something like this: asdf = 2; print(asdf); And print(2); And surprisingly, it works. (Both output 2) However, ...
3
votes
4answers
281 views

Having multiple main classes in a Java project?

Suppose that I have a Java code base and I want to be able to execute multiple tasks that are based on this same base: Run an embedded Jetty web server. Run a one-time initialization of database (...
2
votes
1answer
142 views

What are the advantages of Observables over an iterable of futures?

I recently came across the ReactiveX pattern for asynchronous data-flows. I studied the information provided there and also watched this talk by a Netflix engineer on how they used Observables to ...
6
votes
5answers
180 views

Modular Objects with conflicting implementations

I am working on a game framework that would allow users to use multiple mods/plugins to add additional features to the game. For the remainder of the post, I'll use the following definitions: mod: ...
1
vote
0answers
79 views

Find fastest connection to a certain point

What i'm trying to implement is a program that is searching for the fastest connection from one station to other at a given time of the day. I have a number of stations n, and a number m of lines ...
0
votes
1answer
63 views

Alert when size of continuous stream of events exceeds 1000

A friend of mine was recently asked this question in an interview. Lets say there is a continuous stream of incoming events E1, E2 each with timestamp of entry associated with them. Write a java ...
2
votes
1answer
187 views

Getting started with machine learning a zero sum game?

I have a simple zero sum, discrete, deterministic, complete information board game. I want to machine learn an evaluation function for an AI agent. Suppose each board state has ~20 identifiable ...
20
votes
5answers
1k views

Why would a type be coupled with its builder?

I've recently deleted a java answer of mine on Code Review, that started like this: private Person(PersonBuilder builder) { Stop. Red flag. A PersonBuilder would build a Person; it knows about ...
-4
votes
2answers
56 views

Cache repository violating the SRP [closed]

interface IRepository { Data getData(); } class BaseRepository implements IRepository { public Data getData() { ... } } class CacheRepository implements IRepository { private final ...
35
votes
5answers
3k views

When should I extend a Java Swing class?

My current understanding of Inheritance implementation is that one should only extend a class if an IS-A relation is present. If the parent class can further have more specific child types with ...
-1
votes
1answer
116 views

What is the proper or recommended way to save String[]'s, Array's, ArrayList's and int[]'s to Android?

I've looked up this question many many times but keep seeing different answers, what is the BEST way to save array's? It seems ludicrously infantile that there is no standard or easy way to save ...
2
votes
2answers
141 views

Sharing POJO between different handlers

I am trying to automate Business Process which can be characterized as a pipeline with distinct stages. Pipeline can be perceived as A->B->C, where A,B,C are distinct Business Steps that work ...
3
votes
1answer
81 views

Is there use case for implementing a callback if a future is returned?

If I have function which returns a future, is there any reason to also include a callback where the callback is simply called right before the future completes? The only advantage I can think of ...
8
votes
5answers
430 views

Inheritance vs additional property with null value

For classes with optional fields, is it better to use inheritance or a nullable property? Consider this example: class Book { private String name; } class BookWithColor extends Book { private ...