Skip to main content

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
2 votes
1 answer
389 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
77 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
0 votes
5 answers
860 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
133 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
2 votes
4 answers
667 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
58 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,865
3 votes
4 answers
491 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
599 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
2 answers
311 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
532 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
340 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
73 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
329 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
676 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
104 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
1 vote
1 answer
500 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
  • 71
0 votes
1 answer
111 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
60 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
306 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
618 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
77 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
145 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
243 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
  • 222
1 vote
3 answers
219 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
245 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
342 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
269 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
521 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 ...
minseong's user avatar
  • 460
4 votes
2 answers
2k 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
  • 43
1 vote
4 answers
255 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
317 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
187 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
3 answers
945 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 ...
CPlus's user avatar
  • 1,189
2 votes
1 answer
407 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
346 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
323 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
3k 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), ...
CPlus's user avatar
  • 1,189
1 vote
2 answers
2k 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
87 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
163 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
118 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
316 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
2k 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
315 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
74 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
431 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
1 vote
4 answers
3k 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
  • 213
0 votes
2 answers
103 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
2
3 4 5
99