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

How do you deal with NULL values while creating jsonObject?

I am learning java and jsr-353. My question is quite forward. Having the method below: public JsonObject createJsonObject() { return Json.createObjectBuilder() .add("address", this....
1
vote
1answer
53 views

Parameter objects place holder?

If a method has too many parameters, the suggestion is to convert them into a parameter object. Where to place such parameter objects? in domain/entity classes package? or if I have a separate package ...
0
votes
0answers
22 views

Concept analysis: using a Java ServerSocket to let an Android phone and server communicate?

I have an idea for an application that will not be published to the public Play Store. My friends will need to be able to log in from their Android phone to view certain data that cannot be viewed by ...
-2
votes
2answers
88 views

Java Ellipses Signature for Multiple Parmeters

Firstly, I am studying function with new type of signature and body, and in this code, I want to know, what type of object is values? It doesn't appear to be an array of strings based on my ...
4
votes
4answers
236 views

JSON API or Plain JSON

There is a debate in my company on whether we should use the JSON API specification or stick to plain JSON for developing APIs that will be consumed by mobile apps, mainly iOS and Android. One ...
4
votes
1answer
196 views

Should use case/interactor `execute` method accept parameters

In most examples of clean architecture (Android projects mostly, though) I've noticed that the use-case/interactor classes (units that encapsulate a feature) often share base class/interface, like ...
0
votes
0answers
48 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
30 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
72 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
75 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
85 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
162 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
84 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
134 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
127 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
137 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
339 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
115 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
71 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
2answers
96 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
32 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
87 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
115 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
238 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
109 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
64 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
122 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
275 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
27 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
126 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
392 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
217 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
227 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
99 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
93 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
47 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
32 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
72 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
147 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
191 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
264 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
133 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
75 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
62 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
176 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 ...