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.
0
votes
1answer
66 views
Message driven architecture and horizontal scaling
During working on a pet project in microservice event driven architecture, I've faced a problem of delivering responses to a client.
Each microservice (API Gateway etc) has many replicas and has it's ...
1
vote
0answers
128 views
Design elevator system algorithm and classes? [on hold]
Here are the main classes I can think off the top of my head. All business objects will follow the abstraction (implement interfaces). I have not mentioned interface names
to avoid verbosity. I have ...
2
votes
1answer
99 views
Are there only 2 places you can declare new generic type parameters in Java?
It's confusing because type declaration and usage both use the <T> syntax. I think there are only 2 places where you can declare new generic types in Java:
1. In the definition of a class or ...
-1
votes
0answers
35 views
How to get coverage numbers for JDBI DAO interface
In a project I'm working on we are using dropwizard and JDBI to implement a set of web services. We're using annotated interfaces for the DAOs which JDBI will create an implementation for at runtime. ...
0
votes
0answers
84 views
What is the first proposal of a middleware pipeline? [on hold]
To the best of my knowledge both node.js express and OWIN are based on Middleware. I found that notion for the first time in node.js connect module, and the following description clarifies the idea ...
-1
votes
0answers
119 views
Best way to let user wait for his turn [on hold]
my situation:
I've created some internal service for my co-workers and me.
I want to implement following scenario:
When user is pressing the button "Download" it waits for resource been generated, ...
0
votes
0answers
41 views
Reuse of java beans for REST acceptance tests
We have acceptance tests for our REST endpoints using rest-assured. The tests currently have they're own fluent JSON builders. They help us remove noice from our tests. For example.
.body(someUser()....
3
votes
4answers
152 views
Indicating the end of a stream when null is a valid return
I have two kinds of data streams that both implement the same interface:
public interface DataReceiver {
public Data getData();
}
public class DeviceDataReceiver implements DataReceiver {
// ...
7
votes
4answers
522 views
What are the responsibilties of the main in object oriented programming?
I'm new to object oriented programming and I don't understand what's the purpose of the main.
Yes, I read that it's the "entry point" of the program but what I don't understand is what should be in ...
1
vote
0answers
42 views
Pattern for retrieving batches of Objects?
This seems to be a recurring requirement for me, so I'd like to get some feedback on how to implement it and what sort of test code makes sense. I need to retrieve batches of data and stitch it ...
6
votes
0answers
98 views
I need to write my own version of a bounded queue [closed]
I need to write my own version of a bounded queue. It must be thread safe. The consumption of this queue is based on a priority system, where a consumer makes a request for an object in the queue.
...
2
votes
1answer
69 views
Is avoiding having the fields representing the same object in different communicating classes reasonable?
I'm developing a program which does communication to different types of devices (with respective protocols). It should concurrently acquire messages from devices and write them to a file with specific ...
-2
votes
1answer
101 views
MVC with several MVC-patterns and gameloop
I made a small program using several MVC-patterns. So far I havnt got to much stuff to put in the model so I havnt got any model yet.
My idea is to make one MVC pattern for each panel. And looping ...
-2
votes
0answers
50 views
what design pattern can I use to create an object that implements a specific interface or multiple or any combination among the available interfaces? [closed]
what design pattern can I use to create an object that implements a specific interface or multiple or any combination among the available interfaces? for Example say I have the following
interface A {...
0
votes
0answers
17 views
Minimum cost perfect matching (Using General graph)
This is a continuation of the problem described in this topic: Optimized algorithm to match entities together based on heuristics. I've come a little closer as to what might be the best solution.
I'...
0
votes
1answer
118 views
Workflow when using generated code
I'm working with Swagger to generate the API of my application. Swagger is an API specification language that can be used by a code generator to generate code stubs for your application. Obviously you ...
5
votes
4answers
196 views
Is there a better way to break Java services down into containers
I'd like to decompose a number of Java REST services (WAR files) into individual container-ised "MicroServices" - so that I can scale services ondemand, insulate the applications, have loose couplings,...
63
votes
10answers
14k views
Why do languages require parenthesis around expressions when used with “if” and “while”?
Languages like C, Java, and C++ all require parenthesis around an entire expression when used in an if, while, or switch.
if (true) {
// Do something
}
as opposed to
if true {
// Do ...
-1
votes
0answers
45 views
Representing block of time for course scheduling
I am working on a class scheduling problem. For part of this, I am writing a java class called block that has 2 x 5 array which represents a two hour block which is a block of time for class to be ...
1
vote
1answer
74 views
Override method with subclass as argument
When you want an overrided method to take as argument a subclass of the argument of the overridden method, you usualy accomplish that with generics (as discussed in Template pattern with varying input ...
2
votes
1answer
54 views
Architecting Service, Manager and Model classes for concurrency in a web application
Let's say that I have a chatroom application that manages rooms, users, and messages. I'm building this out as an opportunity to practice some service/manager/web separation and teach myself good ...
0
votes
0answers
56 views
Java application - When should we use multiple threads and possible ways to schedule thread?
I write a simple Java app that plan to run once weekly. I designed it as following:
QueueA<>
QueueB<>
Thread1 :
some class
QueueA.add()
Thread2:
Check QueueA every 10 second
then, ...
6
votes
2answers
180 views
In Java 8, is it stylistically better to use method reference expressions or methods returning an implementation of the functional interface?
Java 8 added the concept of functional interfaces, as well as numerous new methods that are designed to take functional interfaces. Instances of these interfaces can be succinctly created using ...
0
votes
0answers
40 views
concurrency in hierarchical filesystem databases
I am writing a small program that is a client of some protocol. I wanted this program to have a filesystem database. the main directory would contain one directory for a server that is configured, and ...
1
vote
2answers
67 views
Java application - How to optimize database calls and space & time which is more important?
I am writing a simple Java app to run weekly. The app need call database to get data, check it and update.
The flow I need is little as following:
select configure,orgID where status=true from orgs; ...
7
votes
2answers
316 views
Why does Java use :: for method references instead of .?
I often wonder why Java uses :: for method references instead of ., e.g. why write
System.out::println
instead of
System.out.println
Of course, one might simply answer: "because the designers ...
47
votes
6answers
5k views
What would be the disadvantage to defining a class as a subclass of a list of itself?
In a recent project of mine, I defined a class with the following header:
public class Node extends ArrayList<Node> {
...
}
However, after discussing with my CS professor, he stated that ...
20
votes
7answers
5k views
Should “Set” have a Get method?
Let's have this C# class (it would be almost the same in Java)
public class MyClass {
public string A {get; set;}
public string B {get; set;}
public override bool Equals(object obj) {
...
1
vote
5answers
289 views
Do increment and decrement operators decrease readability? [closed]
I understand what increment and decrements operators are (++ and --) and the difference between post and pre (i++ vs ++i) but should they be avoided as they do increase the difficulty of reading the ...
4
votes
2answers
102 views
Whether and how to test façades
In my application I have quite a few service classes that act as a façade and delegate most calls to one or more underlying manager classes. I've read very different opinions on how to test such ...
6
votes
9answers
797 views
Are init() methods a code smell?
Is there any purpose for declaring an init() method for a type?
I'm not asking whether we should prefer init() over a constructor or how to avoid declaring init().
I'm asking if there is any ...
1
vote
1answer
82 views
Design a java based menu so that it's easier to add new options
I am trying to create a java console program which displays a Menu with few options. Each option selection performs some independent operation say executing a script or performing some db operation, ...
3
votes
1answer
83 views
Algorithm to check for legal moves in Cluedo boardgame
I'm making a Clue(do) board game in Java to improve my programming skills. I've done a lot of work so far, but now I'm stuck at finding an algorithm to make sure if a player can make a certain move.
...
0
votes
1answer
87 views
Is the -Impl suffix a legitimate naming convention for a Hook method in Java?
I was going over some old code and found the following peculiar naming convention at a template method implementation.
// TEMPLATE METHOD
// Checks condition and fail fast if condition is met.
// ...
4
votes
4answers
229 views
Evolving an interface that is not supposed to be implemented by the client
I'm about to write a Java library. Basically, this library provides something like this to its user:
interface Foo {
void doA();
boolean aWorked();
void doB(int value);
}
The user is not ...
0
votes
2answers
257 views
Sending push notifications to iOS devices from a Java server
I have a seemingly standard task of sending push notifications to Apple devices from a server written in Java. I have never done that in the past, so I went to tutorials and Apple documentation.
1) ...
1
vote
1answer
60 views
How to look for wrappers (decorators) of specific classes?
I had a job interview recently and I was supposed to do an exercise where one part of the coding was using the ExecutorCompletionService. Well, there were other ways, but this would have been the ...
0
votes
0answers
40 views
How could I learn spring/hibernate from an existing system [duplicate]
I am working with an existing J2EE web application in a company. I don't know spring/hibernate but I don't this web application has employed some features of them.
Everyday I am assigned different ...
0
votes
1answer
83 views
Design pattern for java service class
Java service classes...
I have two service classes one for 'store'(save) data, another service for 'load' to display content.
It was implemented , now new requirement - depends on user input for load ...
0
votes
3answers
211 views
Why not make everything private or public? [closed]
In code there are private and public declarations. Why shouldn't I make everything private or make everything public?
1
vote
1answer
59 views
detecting website opening in new tab/window?
So, as part of my final year project, I'm writing a web crawler in Java to gather website data that I will then process. One of the attributes I need to gather is "number of popups". I know a pop-up ...
0
votes
3answers
107 views
What is a good strategy for reading XML like hiearchical text data?
I want to read data in a format like the following using Java.
[scenario]
id=my_first_scenario
next_scenario=null
name=_"My First Scenario."
map_data="{~add-ons/my_first_campaign/...
4
votes
1answer
74 views
The bound mechanism by generics for a type variable to appear in its own bound
From Programming Languages: Principles and Paradigms
By Maurizio Gabbrielli, Simone Martini
The bound mechanism for type variables is fairly sophisticated and
flexible. In particular, a type ...
0
votes
1answer
61 views
Find best subcombination from given combination
Each component has multiple possible states and any number of them can be active at a time. Some combinations of states have a value associated with it. At any given point, it wants to be able to get ...
0
votes
1answer
139 views
Is it OK to use class names in an interface definition?
I am creating interface in Java for custom error handler.
Want to pass an argument error object but I need it to be child of Exception class.
Is it okay to use my defined class name in an interface ?...
3
votes
2answers
113 views
How to build a class for comparing words in a lexical dictionary?
I'm wanting to create a class that stores words in a set so that I can see if a word belongs to that set or not. I'm not wanting to build ever set every time I instantiate the class, so I'm using what ...
-2
votes
3answers
82 views
How is typecasting an array different from typecasting an individual element?
is the following code snippet:
String[] str = {"Abc","Ghi","Def","Mno"};
Object[] obj = str;
String[] p = (String[]) obj;
same as :
String[] str = {"Abc","...
1
vote
0answers
51 views
How is memory modeled in projects like Apache Spark or Druid?
In the past couple of months I've worked with both Apache Spark and Druid for some projects. As I've gone through the process of learning how to use these tools, I've spent some time reading through ...
0
votes
0answers
26 views
Implementing my own Integer.toBinaryString(int n) method [migrated]
Our senior developer gave us (trainees/jr. developers) a small exercise and that is to make our own Integer.toBinaryString(int n) implementation. This is the answer I came up with. I would just like ...
3
votes
2answers
146 views
Design pattern for free / premium user role
this question is actually about a complex java project I am doing at university, but it is possible to find a simple case which is really similar to the problem I am facing.
In this scenario, we have ...