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 votes
1 answer
42 views

Best practice to execute Python code along with Java app [closed]

What is best practice to execute Python code along with Java app(Spring boot) So , I have a webapp written in Spring boot, I have some data analysis code written in python . There are two ways to ...
  • 107
1 vote
1 answer
107 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: ...
  • 123
-2 votes
1 answer
20 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, ...
  • 157
-1 votes
3 answers
243 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 ...
1 vote
1 answer
71 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; ...
1 vote
4 answers
188 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 ...
1 vote
2 answers
117 views

Implementation of variables in JVM / Java

I know that a lot of interpreted higher level languages like to abstract a lot of things and therefore cannot directly be compared with lower level constructs. For example in some languages primitive ...
  • 49
1 vote
1 answer
158 views

How to restrict the construction of a domain object to an external service?

I have this object RelativeFoo{int relativeCode, Origin relativeTo} And I want to map it to this other object AbsoluteFoo{int absoluteCode} In order to do this, I need to use a service whose ...
-1 votes
1 answer
80 views

Does my class violate the Single-Responsibility Principle? [duplicate]

Goal: I am learning about SOLID principles and trying to refactor Gilded Rose code, in order to make it fresh and clean. What I have done: I have created an AbstractItem class as follows, which "...
  • 11
3 votes
2 answers
237 views

Is this factory method implementation a bad choice because it tightly couples our class with its dependencies?

I had a discussion with a colleague and we don't seem to be able to agree. Can someone help me understand his arguments? Initial situation: We have an adapter in our application which queries other ...
1 vote
1 answer
146 views

Extract common code into own module

I'm finding myself in a situation where I need to define common behaviour and implement it depending on the environment (minecraft server or javafx runtime). The simple graph below describes my idea. ...
  • 11
8 votes
4 answers
396 views

Are there advantages to using an interface, rather than a class, for a Java application?

Java is often (rightly IMHO criticized) for overusing the class keyword, as it can denote: a factory to instantiate objects (traditional classes) a collection of global methods (when all methods are ...
  • 1,265
0 votes
1 answer
80 views

Optimal way Implement a Session Cache

I have an App that connects with Salesforce and do different operations. So I'm trying to implement a Session Cache for the Application to avoid repetitive login calls. So far what I have done is I ...
1 vote
1 answer
103 views

Pattern to convert different types of similar unchangeable objects to the same object

I have an existing system that inserts books into a library database, and I want to generalize it to include other media. The other media is similar, but not exactly the same, and all media are third ...
  • 23
-3 votes
1 answer
153 views

What's the right data structure to combine iteration of key-value pairs, and iteration of values

I'm looking for a pre-existing or easy-to-build data structure available in Java, which can do these 2 things efficiently: Fetch all the values stored in the collection quickly. Iterate over the data ...
  • 157
0 votes
1 answer
99 views

How to design my API that interacts with a third party API and persists to a database

I'm building a web app that will integrate with the Etsy REST API and persist information in a database for things like order information, listings, etc. Essentially a panel to manage Etsy orders and ...
2 votes
2 answers
322 views

Can access modifiers be completely replaced with programming to interfaces?

If we program to interfaces various parts of the implementation can be effectively hidden. We can define multiple interfaces for a single implementation and use them as needed, instead of 4 fixed ...
0 votes
0 answers
72 views

How to generate idempotency token for remote cache

We are using a client library over Memcache. This library has a lot of logic for Memcache client and is indispensable in current form. One of the API of the library is put which internally just uses ...
0 votes
2 answers
153 views

How to handle a new method in the interface that is not applicable for all classes?

I am faced with an interesting OOD problem: I have an interface with 3 methods: interface TestInterface { String action1(); String action2(); String action3(); } and 3 classes that ...
  • 109
3 votes
4 answers
338 views

Should I implement one interface with two methods or two interfaces?

NOTE: This question is reposted from SO because it violates community guidelines for being opinion-based. I have two classes that are similar in nature but they have different functional signatures. I ...
  • 155
-1 votes
1 answer
107 views

How to abstract version switching using feature flag?

I have two versions of an API with similar but slightly different response structure. We are currently using V1 of the API and will gradually move to V2 soon. The switch has to done using a feature ...
2 votes
2 answers
632 views

Dependency Injection vs Static Dependencies

I am building a wrapper for a library that requires little complex logic. The whole project is 8 builder classes, 4 classes for doing some pre-processing, and a couple visitor classes. Essentially I ...
6 votes
5 answers
1k views

How to refactor this code to obey the ‘open-closed’ principle?

The UML is listed below. There are different products with different preferential strategies. After adding these products into the shopping cart, the caller needs to call the checkout() method to ...
  • 71
7 votes
4 answers
795 views

Is the fluent interface pattern suitable in casual scenarios?

In a recent PR, a developer, whom I will call Alice, came across a lot of resistance by a coworker (Bob) because she wrote a utility code unit in a fluent style rather than in a classical style. In ...
20 votes
4 answers
4k views

How do non-RAII languages free resources during stack unwinding?

C++ features deterministic order of calling destructors up the call stack until the exception is handled somewhere. To my knowledge, neither Java nor (object oriented) Python provide this. In those ...
  • 6,985
1 vote
3 answers
221 views

Java Library - How to do Pure Dependency Injection When State is a Factor?

To set the stage, I am trying to do pure dependency injection for a Java Library I am creating to make it more testable. As it is a library, I want to do pure dependency injection without creating a ...
0 votes
0 answers
71 views

Is there a standard for describing information about Java Beans (Bean Introspections)

In many situations we need access to meta information about Java Beans. The Java Reflection API itsself does not work for projects were performance matters so the bigger Frameworks like Spring or ...
  • 207
0 votes
1 answer
80 views

Approaches to 'promoting' release candidates in Java projects

Is there a standard procedure for producing some jars, having them tested downstream, and then promoting these jars to the actual release? By promotion I really mean taking already publish artefacts ...
2 votes
3 answers
179 views

how to leverage overloading while keeping business logic out of models

I am running into a conflict between two best practice principles- overloading should be used instead of long chained if/else statements models should not contain business logic I am working on a ...
  • 139
0 votes
2 answers
273 views

Is MVC a sensible design choice for a CLI application?

I am working on a CLI chess game that only involves 2 human players, I decided to make it follow the MVC architecture to ensure separation of concern and to make the possibility of a GUI/web ...
  • 51
-1 votes
1 answer
2k views

@Getter, @Setter vs @Data in lombok? [closed]

So I was sending code for review and approvals for some changes I made recently. that includes a class as below: import lombok.Getter; import lombok.Setter; @Getter @Setter public class ...
-2 votes
3 answers
139 views

Should I do dependency inversion on the same layer level

I'm working on an accounting service. I have to generate invoice for a user and upload it to the file storage. So my service would have to use a service from file storage team. File storage service ...
  • 123
0 votes
0 answers
373 views

How does Spring boot and Postgres handle the concurrent updates?

I want to understand how does Spring Boot and Postgresql DB handle the concurrent requests for updating a value in DB. Consider this example of facebook likes, if there are multiple instances of ...
0 votes
1 answer
150 views

Should mocks used in unit tests represent entireties or subsets?

I was working on a unit test that has a mock object looking something like: public class TestMock { static { Doodad a = new Doodad(0); Doodad b = new Doodad(1); Doodad c = ...
  • 1,037
1 vote
2 answers
94 views

Java OOP Philosophy/Design: Mutable classes

I do know that the best practice these days is to model immutable classes in Java. An ex: below // It makes sense to model this in an immmutable fashion class 2DPoint { private int x; private int ...
  • 119
2 votes
1 answer
109 views

Best method to differentiate between two REST methods with the same pathparam (in Quarkus)

I have an issue regarding the differentiation between two Rest methods that have the same amount of path parameters: @GET @Path("image/{ratio}/") @Produces("image/png") ...
  • 249
0 votes
0 answers
61 views

Dispatch based on ENUM/String value

I've the following classes: TypeAHandler, TypeBHandler,... Each handler can turnOn or turnOff a list of object ids (e.g. handler for type A calls microservice, handler for Type B modifies DB entry). I'...
  • 157
0 votes
4 answers
365 views

Should I design a factory that returns a singleton?

I design a common API for selected printers of different brands in Java. Each printer uses a different underlying SDK with different functions, but any hardware my code runs on will have only one ...
7 votes
2 answers
1k views

How to generate java class files with framework boilerplate in a project?

The Java project I am working on currently has a complicated folder structure, and to add a new functionality, one needs to add many .java files in different places in order to let it work in our ...
2 votes
2 answers
281 views

In what language does a method not return a value and a function does?

I don't know from where I got this but in my head a function returns a value and a method does not. I know that with OOP a method is a function related to a class. But I am trying to remember where I ...
1 vote
2 answers
92 views

Standard Maven approach for large, non-Java dependencies needed for build?

I'm interested in modernizing an existing codebase for a commercial software package written in Java, in part by moving it to Maven. The primary motivator here is to shrink our git repo, which is ...
0 votes
2 answers
637 views

Simple Java Spring Boot Cache for multi-container system

I have a requirement to cache some static data as it is being consumed by our system. There is a static API that gives a map of records and we are fetching the corresponding record based on request. ...
0 votes
0 answers
100 views

Which design to follow to override a flag from a jar in the application using it?

At my workplace, there are lot of Java/Spring/Spring-Boot based applications which have a common jar added as maven dependency. This common jar is always used as a SNAPSHOT dependency and I am not ...
  • 119
0 votes
2 answers
86 views

Designing class for fixed-size data structure backed by ArrayList

Say we want to write a Java class that represents a fixed-size list. Let's call it Chunk.java (as in, it represents a chunk of data to be processed or sent somewhere). My implementation of this class ...
0 votes
1 answer
66 views

Expose api to third parties to send PDF files (invoices)

Our system needs to process PDF invoice files from generic external third parties. Using HTTP is the most obvious, but this isn't the greatest of ideas in case we need to deal with bulk uploads. Even ...
  • 185
2 votes
4 answers
680 views

Code smell java:S115 - Constant names should comply with a naming convention

In my Java 11 / Spring Boot codebase I have enums that don't respect the convention to have all uppercase constants because when we move to frontend the data there has to be camelCase (or even random /...
  • 141
-3 votes
2 answers
283 views

What are the possible *root causes* of a SocketTimeoutException?

I understand that a SocketTimeoutException (I'm in Java, but I guess it's the same in just about every major language) happens after a server or client doesn't respond after a period of time, let say ...
-1 votes
1 answer
473 views

Why is Java AOT compilation (using graalvm native-image) so much slower than golang compilation?

I followed the guide here https://quarkus.io/guides/building-native-image to set up a minimal quarkus webservice graalvm native image. Ran command 'time quarkus build --native' to compile the example. ...
  • 109
0 votes
2 answers
236 views

What are the tradeoffs between a Union type or a wrapper Class to represent a formatted string argument representing multiple types

Assume there's a public void process method on a Java class called A that currently takes a single String argument id. class A { public void process(final String id) { // Some implementation } ...
0 votes
1 answer
73 views

Command pattern across layered architecture without shared interfaces?

I have three layers. I wish to reduce coupling between them and other modules. I wish to use the command pattern between all layers. A command should be able to be passed from one layer to another. ...
  • 25

1
2 3 4 5
98