Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [java]

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
0answers
25 views

Retrieve latest files from a directory using UUID or incrementing integer approach [on hold]

I have a download button in the UI, user clicks on it and download 3 files in a zip format. It's not necessary that the files are already there(on the server) when download button is clicked because ...
1
vote
1answer
100 views

Should an abstract class implement an interface, as opposed to defining its own abstract methods?

I'm defining a class structure for persisting to our cassandra database, and I'm unsure about using a combination of an abstract class and an interface. I have two concrete classes, one for persisting ...
3
votes
5answers
716 views

Should a class provide public mutators for all its private fields?

I work on refactoring an Java application based on a CAST audit. One of the criterion says that To respect OO encapsulation concepts, private fields should always be accessed through accessors ...
0
votes
0answers
90 views

dealing with too many DTO / Java

We are building an pseudo-rest API (because no body cares/funds for a full blown rest API for internal use - which is OK). So we have elements of Rest API (links for resources, API naming conventions ...
0
votes
0answers
24 views

How can I create a spring-boot application which can be easily extended with plugins?

I am planning a spring boot application that can be extended with plugins. However, I haven't found out yet whether spring boot meets my requirements in this regard. I imagine the following folder ...
0
votes
0answers
44 views

Passing data into different layers

Background: I am working on an application which needs to read data from different resources and produces a JSON file for each row. There are no user interactions and hence I am designing it like a ...
0
votes
2answers
71 views

How to separate responsibilities of a shared entity

Suppose I have game achievement class that stores achievement information like name, popup message, etc. class GoldMedal implements GameAchievement { @Override String getName() { ... } @...
0
votes
0answers
18 views

JSON-RPC Json Objects Best Practices

I am building a JSON-RPC over UDP socket API in Java. There are 6 objects that will be transmitted in JSON: jsonRequest jsonSuccessResponse jsonError jsonErrorResponse jsonNotification ...
0
votes
0answers
20 views

Actor Model In Java Using CompletableFuture and Executors

I am planning to implement an Event Driven system, based on the Actor model using CompletableFutures and individual Thread Pools for each actor. However my tasks are completely sequential in nature ...
1
vote
1answer
85 views

Should I use accessors or public static fields for global constants?

I have to work on some code that was CAST-audited. The report says that it is bad in Java to use public static and that accessors should be preferred. That is also what I was taught at school. The ...
-2
votes
0answers
21 views

Continuous Integration of dependent Development Artifacts [on hold]

I have transitioned companies, and so I, who have programmed in Python for the last 7 years work now with a Java stack. I wanted to improve the continous integration setup of the project I joined. ...
0
votes
2answers
89 views

Java - difference between constructor and calling the object multiple times [duplicate]

I read through a code example on github and instead of initializing the object using a constructor, they made every setter return the object itself to call it over and over again See, constructors ...
0
votes
2answers
132 views

What is the difference between singleton pattern using inner static “Holder” class and “Instance” variable

I have encountered two patterns to make a singleton class Holder class public class Singleton { private static final class Holder { private static final Singleton INSTANCE = new Singleton(...
0
votes
1answer
60 views

How to implement multi-layer stream processing in Java?

I need to implement a back-end service which conceptually is built in layers. One typical example could be as in the picture below: So you can see we have an input of type A which is sent to three ...
2
votes
1answer
112 views

Law of Demeter helper utilities

Do helper utilities like the one below violate the spirit of the Law of Demeter? It doesn't technically violate the law, since the doOperate method doesn't invoke C's methods itself. If so is there a ...
2
votes
2answers
192 views

Java: Is reflection bad for AOP situations?

Imagine the following situation: 1. Consume a 3rd party WSDL, out comes thousands of classes. 2. There's an opportunity to optimize performance by using a custom paralleled implementation. 3. Wsdl ...
3
votes
1answer
89 views

Automated Testing: where do I put Selenium?

I'm working on a Java application, it's a middleware between two ticketing webapps. I want to write end2end tests using Selenium to test functionality. Let's say my testing process goes like this: I ...
1
vote
1answer
309 views

Why is this valid boolean b = new A() {} instanceof A; if A is an abstract class? [closed]

I have trouble understanding why this boolean b = new A() {} instanceof A; is a valid statement and not boolean b = new A() instanceof A; and why the former is true knowing that A is an abstract class....
2
votes
6answers
178 views

The ID of an object is null at start. Does that make the object state invalid and violate encapsulation?

This question is related to How should an `Employee` class be designed? In the above question, to uniquely identify an employee, each Employee object has an id field as shown below class Employee { ...
1
vote
2answers
139 views

What are the bottlenecks for the Java build speed?

Which underlying system parameters have most influence on how fast a typical Java project (say dozens of classes and dependencies) builds? There is a lot information on JIT (bytecode to CPU ...
1
vote
0answers
32 views

How to manage cart details across various devices

Recently I was asked in a interview to implement to e-commerce site . One of the requirement was to maintain cart details across various devices .(i.e) if user adds a book from his iPhone , and when ...
1
vote
3answers
99 views

Is there a viable methodology for using a relational database without an Object-Relational Mapping tool

I'm beginning a small Web development project (maybe 20 tables initially). I would like to use a relational database for transactions, SQL, indexes, etc. I have limited needs for true objects, though. ...
0
votes
1answer
87 views

Common methods for swapping out a library

I am trying to come up with a solution to replace joda-time with java 8 time in our product. The code-base encompasses many projects of which some import joda-time directly and some transitively. To ...
0
votes
1answer
65 views

Injecting DAO dependencies into Service Class in Core Java

We don't have any frameworj like Spring where we can inject dependencies using annotations or xml file. We have handler classes, service classes and dao classes. Handler classes access service which ...
-2
votes
0answers
40 views

Creating AD module for application

I have application A, where i would like to add functionality for advertisement/collaboration. The module should have its own database, application A should communicate with its API to retrieve info ...
0
votes
1answer
145 views

Composite DTO or flattened DTO?

I'm having problem deciding which of these 2 structures to use from my DTOs: Option 1 is: @Data class Lines{ private final Line[] lines; } @Data class Line{ private final String[] specifiers; ...
2
votes
2answers
78 views

API Race conditions

I have an API in which we expect a emailID and a certain deal data. The case is we want to keep the dealId and contactId(email) to be unique. Creating a deal requires data insertion in multiple ...
-2
votes
2answers
48 views

Backtracking with big inputs

I'm doing a Magic Square problem, and I'm using backtracking tecnique for do it. So, the magic square asks you for an input which is the size of the square, and you generate this square, and you need ...
-4
votes
0answers
43 views

Design for Pages that starts for Different Purposes

At my company, we have different pages for different purposes and some of those pages has multiple starting points. According to that points, pages opens with different types. For examle: When clicked ...
5
votes
1answer
176 views

What is the best way to handle glue between different classicly OOP objects at the higher levels of abstraction?

In object oriented programming, it is commonly said that each class/object/instance should have a well-defined purpose. For example, there may be a Window class in a windowing toolkit, a ChunkLoader ...
1
vote
0answers
54 views

Third-party API wrapper in Java: how to design

Suppose, there's a site that provides an API, such as this: Users post questions, answers on that site You can make GET and POST calls There are two types of authentication: weak (only gives read ...
2
votes
2answers
226 views

Java 8 - When should I use java.util.Stream instead of java.util.Collection?

I started studying functional programming with JavaScript. After this, I started to study it with Java 8 (streams, lambdas and method reference) and I realised that I tend to use streams as much as ...
2
votes
1answer
178 views

Why did Java and C sharply dip in popularity around 2017 in the TIOBE index? [closed]

The TIOBE Programming Community Index shows Java and C dramatically falling in popularity between late 2016 and mid 2017 before rebounding by mid 2018. What is the cause of the volatility? Source: ...
0
votes
2answers
172 views

Java Constructor Syntax and Design [closed]

With regards to object-oriented Java constructor syntax and design, specifically parameterized or specific constructors, it is the accepted process, as describe in books, to build a parameterized ...
0
votes
2answers
199 views

Is using Objects.requireNonNull() in production bad practice?

Objects.requireNonNull is a helpful method to spot NullPointerExceptions effectively while developing. But in fact it's throwing a RuntimeException which could crash the application (the worst thing ...
7
votes
4answers
353 views

Advantages of HATEOAS based RESTful service

There is a scenario, where we have two commercial applications that are so called REST based(java) but not HATEOAS compliant. Development activity is out-sourced to vendor Development phase of ...
1
vote
1answer
33 views

How to Define the Bandwidth in Mean Shift Clustering?

I am making a program using Java todo colo quantization using mean shift clustering algorithm and the image is RGB with resolution of 512x512. I want to reduce the image file size by reducing the ...
3
votes
1answer
49 views

Externalized properties for an Java EJB application

I am not sure if this is the right place to post this question, but I think this might be better suited than Stack Overflow. I have got an online application, a Java EJB application. Requirement is ...
0
votes
1answer
53 views

Objectreference vs Equality [closed]

While coding I stumbled upon something like this (extremely simplified example): public bool Func() { Object[] array = new Object[] {false, false}; return array[0] != array[1]; } I was ...
-1
votes
3answers
234 views

Can an object in java have behaviour without having any state

I was just studying the interdependence of state and behavior exhibited by the state of an object and its behavior.was wondering if an object can have behavior without having state. Because i am very ...
108
votes
12answers
15k views

Rationale to prefer local variables over instance variables?

The codebase I'm working on frequently uses instance variables to share data between various trivial methods. The original developer is adamant that this adheres to the best practices stated in the ...
1
vote
4answers
93 views

filter + map api design

I am writing a library call that will allow you to filter and map in the same iteration of the loop, this is async/callback style in Java. The problem of course is that for filtering we usually return ...
0
votes
2answers
198 views

How best to avoid member implementation of class' Abstract/Interface instance variables

I'm sorry if the phrasing of the question is a bit unclear but let me try to clarify below. (If anyone can word it better, feel free to edit) I have a Map instance variable, groups, which is defined ...
1
vote
1answer
92 views

Have generic methods that transfer DTO's from different packages, but contain same fields

I have 3 services Service A, B, C which put and get data to/from Service D +============================================+ | Service A | Service B | Service C | +==============================...
2
votes
1answer
126 views

Do we include output space in space complexity?

For example. I have a function which generates an array with random numbers. int[] generateNum(int n) { int[] result = new int[n]; /* Logic to generate random number */ ............... ...
0
votes
0answers
25 views

Messaging engine architecture with front-end and ORM layer (spring)

I'm looking to push my first QuickFixJ messaging engine into production, and I would like to know the best way to do so. Bear with me. The gist of the responsibilities is as follows: Through ...
0
votes
3answers
225 views

Is it sometimes okay to intentionally violate the Dependency Inversion Principle?

I am doing some work to refactor a class. It currently a 'God class' and contains all different logic/operations solely in that class. One of my solutions is to extract all different parts of logic to ...
-1
votes
1answer
92 views

Best practice - Single or Multiple source code repository

As mentioned here: The main aim of CI is to prevent integration problems, referred to as "integration hell" Our project is a 3-tier web application, with frontend(Angular 6), backend(Springboot) &...
0
votes
0answers
48 views

Frontend JSON payload that defines which classes to use in the backend

Payload: { "selection": { "ids": [1,2,3,4,5] }, "image": { "backgroundColor": "#FFFFFF", "headlineColor": "#000000", "format": "PNG" }, "processors"...
0
votes
0answers
127 views

Decorator Pattern Java

This is an object-oriented design question that is specific to Spring Boot. I'm extending a Spring Boot application that has an interface that is being extended and used inside another service. The ...