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
0 votes
0 answers
20 views

Bean Custom Constraint Validator in multiple projects which common domain model

I have multiple maven projects ( rest services ) with common domain model. I would not say micro services. Structure is build this way to eventually move towards mircoservices. All the maven projects ...
Bhalchandra K's user avatar
0 votes
1 answer
74 views

Java Security, How important is the version of JDK for building vs running the Application

How important is the minor version of the Java Build SDK vs. the JDK version at runtime, is it a problem if the minor version is a bit outdated, if the run time version is still up to date? More ...
xyz1234's user avatar
  • 11
1 vote
3 answers
81 views

DTO vs POJO (Entity) on POST request

If I have for example a User POJO like the following @AllArgsConstructor public class User { @Id private final String id; private String username; private String password; private Date createdDate;...
iqueqiorio's user avatar
0 votes
0 answers
92 views

By creating an architecture, it is better to have many classes that handles different scenarios, or a single one that handles all? [duplicate]

During my limited professional experience, I have been involved in microservices projects with a common structure: The Controller takes a request and validates it using the jakarta.validation....
Paul Marcelin Bejan's user avatar
2 votes
5 answers
287 views

Refactoring Java class for a cleaner design

I inherited some code that I have spent some time reviewing to get a better handle on its design. There is one class that I came across that I have an idea for refactoring, but I am wondering if it I ...
user1154644's user avatar
-2 votes
2 answers
68 views

How to send non real time push notifications so that the servers aren't hogged?

Our android application is built on java. And while sending push notifications we're using tomcat as a server. And it is doing more harm than good. Currently all the push notifications (FCM/APN) are ...
barnyard9's user avatar
0 votes
1 answer
165 views

In python when is absolutely preferable use a class than a module?

Python is the language I use most in this period. My background in Java Before start learning Python I have programmed in Java language. In Java all code is written inside the methods of a class and ...
User051209's user avatar
0 votes
1 answer
56 views

Design a sequential processing of records

About 10 to 15 records are processed per day with the time interval of 5 minutes between each record. System A inserts a record in DB and sends id of that record to active mq. System B Listener ...
sunleo's user avatar
  • 119
-1 votes
0 answers
21 views

Random selection based on weightage and previous history

I have a spring boot application for a notification system. Consider sms notifications for which I have n vendors to select from. Every vendor has been promised a certain percentage of our business, ...
Anurator's user avatar
0 votes
5 answers
209 views

Comparing Java objects with different member variables

I have a base class "People" which two other classes inherit from: Employee and Student. The Student class includes a GPA (type double) and the Employee class does not. I have an ArrayList ...
Delta88's user avatar
  • 19
2 votes
1 answer
97 views

Declaring code style settings in a Java project

In a Java open source project built with Maven, is there a standard way to declare code style settings (such as indentation settings and import order)? I would like that people who import the project ...
pintoch's user avatar
  • 159
1 vote
4 answers
254 views

Is it a code smell to modify a data transfer object (DTO) within a loop in a Spring service controller?

I have a Spring service that acts as an adapter for another service in my company. The service receives a request to generate push notifications for a given user and needs to call the other service ...
VariabileAleatoria's user avatar
0 votes
0 answers
50 views

Is using @Transactional together with @Test annotation on the same test method a good practice?

In my current Java project, there is such style of integration test: @Test @Transactional public void testBusinessTransaction() throws Exception { //...complicate set up code and execution code ...
Rui's user avatar
  • 1,615
3 votes
4 answers
445 views

Does "declare the most abstract type" increase coupling actually?

According to Why define a Java object using interface (e.g. Map) rather than implementation (HashMap), I know I should declare the most abstract type possible, so for example: public interface Fruit{ }...
wcminipgasker2023's user avatar
1 vote
5 answers
428 views

How does inheritance lead to higher coupling than composition?

One major reason for using composition over inheritance is, that inheritance leads to higher coupling. How is that? In both cases members are exposed to the subclass (in case of inheritance) or ...
cobby's user avatar
  • 119
1 vote
3 answers
168 views

How to design an entity that has different fields depending on a type?

I have a specific domain entity that has a given type and some attributes. Based on the type, it can have another set of type-depending attributes. Normally, I would create a class for each type and ...
Fischer Ludrian's user avatar
0 votes
2 answers
481 views

Is Authentication a good use case for a checked exception according to Effective Java (Bloch)?

There's a section about use of checked exceptions in Josh Bloch Effective Java and I find it a bit abstract to understand what he means by saying "when a user can recover from it". ...
TMOTTM's user avatar
  • 109
0 votes
4 answers
274 views

Are "easier to search for the interface" and "avoid yo-yo to interface to find implementations to fix bugs" reasons to add prefix "I" on interfaces?

According to Should interface names begin with an "I" prefix?, I should not add prefix "I" to interfaces. However, I think prefix "I" in interface may be useful sometimes....
wcminipgasker2023's user avatar
0 votes
0 answers
51 views

Spring data exchange between components?

Please advise me what pattern to use in following case: I have a Java/Spring Boot application. There is a component with @KafkaListener method which receives Kafka Messages on CRUD of various subject ...
ALZ's user avatar
  • 107
2 votes
3 answers
242 views

Covering a NO-OP Condition

I have a Java project where a coverage analysis tool is being used (SonarQube). It rightly declared that code similar to this was a potential performance issue (Encode.forJava would still be called ...
Tibrogargan's user avatar
-1 votes
1 answer
179 views

Microservices architecture for spring boot application

I have a Spring Boot application which is containerized. The application has become huge with lots of complications and its difficult to maintain it. So I am thinking of breaking it into microservices....
Prasad Patil's user avatar
1 vote
1 answer
91 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
261 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
3k 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
0 votes
1 answer
103 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
54 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
140 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
  • 113
0 votes
1 answer
254 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
62 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
114 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
218 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
172 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
211 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
285 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
142 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
335 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
439 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
236 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
175 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
150 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
534 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,157
2 votes
1 answer
237 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
227 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
317 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
1k 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,157
1 vote
2 answers
341 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
  • 31
-2 votes
1 answer
78 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
137 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
86 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

1
2 3 4 5
99