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.

Filter by
Sorted by
Tagged with
1 vote
1 answer
53 views

Exposing DB table to other Microservice via a Library

Consider I have 4 Services . Account Order Items Customer Now a External Partner Service calls all these services , by passing an External customer id ( EXT_CUST_ID) in the request. Our platform has ...
Dev-vruper's user avatar
0 votes
1 answer
64 views

Designing Clean Architecture(Hexagonal) for a Spring Boot Application : Project Layout and Class Organization

I'm currently in the process of integrating Clean Architecture into my Spring Boot project and I'm seeking advice on the ideal project structure and the types of classes and projects that should be ...
shiningStar's user avatar
2 votes
9 answers
2k views

Is it an anti-pattern to use interface for entity?

I read an article about that using an interface for an entity is an anti-pattern for these reasons: Your interface signature is identical to your class. There’s only one implementation of your ...
Mercury's user avatar
  • 53
-1 votes
0 answers
31 views

Spring Reactive Restful APIs - Is it really a non-blocking model?

I know that is possible to build my entire Spring boot application in reactive way. So if my application uses R2DBC, I can do something like: @Repository public interface PersonRepository extends ...
Vitor Nilson's user avatar
-1 votes
0 answers
63 views

Design of Complex Java Filters

I have a collection of DTOs and would like to filter the collection on a complex set of criteria. For example: //modelIds is a Collection<String> cars .stream() .filter(car -> { modelIds ==...
James's user avatar
  • 283
-1 votes
0 answers
64 views

Array Indexing Using Wrapper Classes

Is there a reason why we, as software developers, do not use specialized types for array indexing? Typically, I use the "int" primitive type to perform array indexing, but I was thinking ...
TTCUSM's user avatar
  • 19
0 votes
1 answer
96 views

Should I use method overloading or method overriding when creating converter service

In a Java Spring API, I'm implementing GeoJson Conversion Service to convert different types to geojson, I have GeoJsonConversionService interface, and one implementation is ...
zyydoosh's user avatar
  • 103
0 votes
0 answers
51 views

Java - How to build a library to record runtime data?

I'm working on building a library in Java which could provide the ability to record runtime data. For instance consider the below code: public interface ItemElement { public int accept(...
user762421's user avatar
1 vote
1 answer
96 views

package by feature and common parts of code

I built an app in the way that one context is closed in one package. However, as code grows there are more situations in which the code is duplicated. As I understand the package should contain ...
MyWay's user avatar
  • 111
0 votes
1 answer
147 views

Interfaces vs abstract classes for immutable DTOs

At my org we extensively use @Value.Immutable annotation to generate Immutable classes (usually with builders) for our internal data transfer objects (DTOs). In our codebase I've seen both interfaces ...
y2k-shubham's user avatar
-2 votes
1 answer
50 views

How to Implement Spring Boot Endpoint for Confluent Cloud-Like Batch Payloads?

I'm currently working on a Spring Boot application where I need to create an endpoint similar to the one mentioned in the Confluent Cloud documentation (link). The cURL example provided in the ...
Manupriya Logus's user avatar
0 votes
2 answers
91 views

Best way of creating different instance types(facotry method) with business logic?

Say I am trying instantiate an instance of a Table. Table here denotes a restaurant table used for eating. Say I have 3 different table types enum TableTypes { SMALL, MED, LARGE } I have ...
curiousengineer's user avatar
6 votes
7 answers
7k views

How to avoid repeating "a==b" when comparing "condition a" and then "condition b" and then...?

For example, I have an object: public class Obj{ public int a; public float b; public String c; } I need to find best "Obj": largest a and then largest b and then longest c: int ...
wcminipgasker2023's user avatar
2 votes
3 answers
211 views

Should edge cases be part of one test, or each their own case?

I am writing tests TDD-style for a cryptography package containing encryption and decryption methods. I test my methods with various kinds of inputs, including multiline strings, mixed case, calling ...
Marvin's user avatar
  • 195
1 vote
3 answers
144 views

To enforce column limits on long strings? [closed]

We're trying to update our style guide (using google's guide as a starting point) and I'm currently in the middle of a debate with my colleagues about column limits. I believe we're all in agreement ...
Zachary Coffin's user avatar
1 vote
2 answers
195 views

Is "declaring most abstract type" suffers from the same problem as "primitive obsession"?

According to Why define a Java object using interface (e.g. Map) rather than implementation (HashMap), when creating objects, I should declare the most abstract type, eg : Map hashMap=new HashMap(). ...
wcminipgasker2023's user avatar
1 vote
1 answer
281 views

Why is "Diffie-Hellman Key Exchange" secure?

I'm not sure if I misunderstood these codes. First Alice generate her keypair and sent the public key to Bob. Then Bob uses the parameter in the public key to generate his keypair and sent the public ...
Kimi Chiu's user avatar
  • 113
0 votes
1 answer
74 views

How to write custom implementation of a service/flow for a tenant in a multi-tenant microservice system?

I have a Java Spring boot microservice in production which supports multi-tenancy and the tenants are isolated at database level. This microservice exposes REST APIs for communication. During a ...
ashish.g's user avatar
  • 129
2 votes
1 answer
316 views

How to implement interface on Java class I don't own?

I want to allow some Java objects to be translated into a string representation which matches Python or JavaScript objects. I thought that I could tag all compatible classes with compatibilising ...
theonlygusti's user avatar
3 votes
2 answers
175 views

Should a method modifying object passed as a parameter return the modified object? [duplicate]

I have some incoming request - it's an instance of class generated from api specification - POJO with public getters/setters. I would like to normalize some values. For example dimensions (to use ...
Shaolin's user avatar
  • 33
1 vote
4 answers
229 views

What is the difference between polymorphism and instanceof?

this is my code: System.out.println("--------------------------"); if (person instanceof Student) { Student studentPerson = (Student) person; System.out.println("GPA: " + ...
raven kumar's user avatar
-1 votes
1 answer
138 views

Using a shared enum across 15 nanoservices [closed]

Originally posted here, moved to code review, redirected from code review back here as there is no code to review. I think the question is enough abstract to be asked here. I have a mono repo with ...
Alexander Petrov's user avatar
1 vote
2 answers
144 views

Choosing a strategy for representing and handling errors (or more generally status codes) in java 8

I asked this questions on StackOverflow but it's definitely a bit too broad. Even for this website, although the question is about software design, it might not be enough "focused". I am ...
lux_piromani's user avatar
0 votes
2 answers
402 views

What prevents Java from having immutable primitive arrays?

Java never had immutable primitive arrays. However Java does have an immutable List or Map or other collection classes and of course final primitive fields and variables. In Java if you try to make an ...
user16217248's user avatar
  • 1,113
2 votes
1 answer
202 views

Should a library or an application exclude logging libraries and include SLF4J bridges?

The SLF4J documentation says that it's best practice for libraries to not include a concrete logging binding. I'm wondering what to do about transitive dependencies though. Let's say my library A ...
Lars Francke's user avatar
1 vote
1 answer
179 views

The recommended Spring Boot project structure leads to repetitive code

When implementing projects in Spring Boot (especially CRUD applications), I often find myself writing a lot of repetitive code that just calls functions and services from lower layers. For example, ...
Win32's user avatar
  • 13
2 votes
4 answers
315 views

Buggy auto conversion to string : In which code-smell would it fall and how should avoid one?

Consider this Java code: int rowIndex=8; int offset=0; libFuncCall.populate("B"+rowIndex+offset, data); Here I mistakenly missed the fact that, resulting argument is a String though I had ...
MD. Mohiuddin Ahmed's user avatar
0 votes
3 answers
566 views

Getting an enum value by a unique property in Java

I can write an enum with properties besides the name and ordinal. A very generic example would be: public enum ExampleEnum { EXAMPLE0(Example.example0), EXAMPLE1(Example.example1), ...
user16217248's user avatar
  • 1,113
0 votes
2 answers
216 views

How to represent the absent of a field value in json response?

I am a react developer and writing the client on pure JS. I have sometimes missions to received data from server and send data to server. Now between the client team and backend rough discussion ...
Brk's user avatar
  • 21
-2 votes
1 answer
70 views

what are MVC benefits for my case?

I'm trying to design my new open source project I want to launch. I want to be very careful with design/projecting because I had trouble maintaining software in the past. I have code that works and ...
gabrielsalvador's user avatar
-1 votes
3 answers
132 views

Choosing an Approach for Microservice Communications

I'm developing a doctor-patient system that consists of two microservices, namely the "doctor" and "patient" microservices. Both doctors and patients share some common attributes, ...
omid's user avatar
  • 1
0 votes
1 answer
76 views

How to persist Objects with the same parent

I am trying to build a "world" consisting of Fields for simplicity lets say there is a water and town field i created two classes @Entity @Inheritance(strategy = InheritanceType....
Tator's user avatar
  • 103
3 votes
2 answers
205 views

Best approach to microservice shared databse architecture

I have two microservices, one Flask (python) and one Spring (java), they currently share a database. The Flask microservice handles processing json files (~40mb) for each user (could be 100's or 1000'...
MSmith's user avatar
  • 31
1 vote
4 answers
714 views

I wrote a class with "init" method. Should I call it from other class methods? Or leave it to the object user? (Code Design)

I have a java class with an init method. It's different from the constructor. The constructor just initializes the variables/fields. The init method connects to a database and performs some ...
joker's user avatar
  • 121
1 vote
1 answer
174 views

Hexagonal architecture and object instantiation

I don't have enough experience to understand how hard object instantiation and garbage collection really hit. So I tend to write code where I don't just spin up objects for the sake of it. However, ...
Kalec's user avatar
  • 210
-1 votes
2 answers
72 views

Java: Autogenerating documentation for Strategy Pattern with lambdas

Situation Object MyObject needs to be sent to one of our downstream systems depending on the enum value of its field myField. public class MyObject { private MyEnum myField; public MyEnum ...
downwash's user avatar
0 votes
0 answers
147 views

What is the Best Practice for handling multiple Entities that behave identically?

Because I have multiple entities with unique fields, I need multiple repositories for each one even though each Entity will be handled exactly the same. What is the best way to handle these separate ...
dbrewster's user avatar
  • 139
0 votes
1 answer
1k views

Multithreaded processing of single REST requests

Background: We're providing an API that provides information about all users within a given group. Our API is a high level facade over another low-level REST API. To gather those information we first ...
das Keks's user avatar
  • 203
0 votes
2 answers
94 views

Logical architecture based on modules and SPI

I'm looking for the most proper way to design a modular application with ServiceLoader. --MAIN IDEA-- module app.view | exports app.view.View interface that defines UI api module app.engine | exports ...
SmallDevice's user avatar
1 vote
1 answer
140 views

Gradle/Maven project splitting: interfaces and implementation

Assume we have a single large JVM project (the example is in Kotlin), containing code. As part of a refactoring effort, we are decoupling pieces of the code by splitting the code into multiple modules,...
Hidde's user avatar
  • 170
5 votes
5 answers
874 views

Java Exception Error Enumerations Anti-pattern

Over the years I've many times seen folks enumerate error codes for exceptions in Java. I generally have felt this leads to more tedious code and does not provide value. For example, there will be an ...
Kirby's user avatar
  • 271
1 vote
1 answer
92 views

Client-Server-Architecture: Move computation logic from client to backend - Algorithm needs certain new values while running (User input) and continue

Background: At work I was tasked with developing a new demo web client to replace our Windows Form application in the future. Our back-end is developed in Java and works stateless as REST services. ...
drake76722's user avatar
0 votes
0 answers
61 views

Refactoring: where should master data reside?

I inherited a backend project and want to refactor the management of master data. The master data consists of a couple of database tables that contain fields like year, rebate_in_percent or category. ...
user15110545's user avatar
1 vote
1 answer
112 views

Is it an acceptable pattern to put derived classes inside an abstract base class in Java?

Suppose I have some Java code such as the following (in this case, the use of the name "interaction" is referring to interacting with an object in a video game): public abstract class ...
micheal65536's user avatar
0 votes
1 answer
177 views

Is it secured to accept and execute user provided CURL commands

Assume you have to figure out a dynamic way where the user can provide an API call to hit in the backend for example, user to provide a webhook to call on his end server So, An idea for users to ...
Youans's user avatar
  • 441
2 votes
1 answer
459 views

How to manage immutable objects (specifically Java records)

With Java record being immutable, I don't know how to use them properly in the context of something like a CRUD application. If we take a very simple example of a "Organization" record: ...
Chris's user avatar
  • 133
-1 votes
1 answer
400 views

What is the recommended approach for loading a Java Keystore from memory in a SpringBoot application running in a Docker container?

I am looking for a solution to load a Java Keystore dynamically from memory instead of from a file on disk. Can you suggest any libraries or best practices for this scenario in the context of Java, ...
goodspeed's user avatar
  • 167
-1 votes
3 answers
285 views

Is it ok to save all fields of an entity as a string if it should not be changed?

I have a complex object that has several fields can be updated until it is locked. Is it proper to save this locked entity as another entity which has no object child, only string data. complex object ...
AhuraMazda's user avatar
1 vote
1 answer
119 views

Refactoring instanceOf, moving logic to POJO when it has database interaction

I'm refactoring some old code, I have a lot of istanceOf in the business part: if (record instanceof RecordA) { RecordA recordA = (RecordA) record; ...
Accollativo's user avatar
1 vote
4 answers
225 views

Storing both a compiled service for a Docker container as well as the container in a repository. Good practice, bad practice or no precedent?

This has erupted from quite a turbulent meeting between two senior developers, a lead developer and an engineering lead, and after 90mins reached no resolution. We create Spring Boot Java services ...
Crazy Dino's user avatar

1
2 3 4 5
98