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

Showing images in web application [closed]

A customer has to upload images and needs to be stored in application server. The images should be shown in the their pages The image will differs from one customers to another customer. Option1: ...
-4 votes
1 answer
49 views

What aspects of an application would you consider if you have to choose between JVM and V8 for your backend technology? [closed]

Please delete my question as no one else seems to be interested in answering it but just down voting, very frustrating to be honest -- i'm working on comparing Java (JVM) and NodeJS (V8) within a ...
5 votes
0 answers
229 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,235
-1 votes
0 answers
28 views

How many cores should i use to model this data in solr?

Data The raw data is in json format and it is close to 2 TB. Each entry in the ndjson file contains all the data below in a nested format. Example: People, with 75 attributes. Field examples: income ...
0 votes
1 answer
66 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 ...
0 votes
0 answers
50 views

Mixed usage of both Spring @Service AND Singleton classes

Point 1) I am checking some code into the app that I am working on in my job and I'm looking at some weird (at least that is how it looks to me) usage of both Spring based @Service classes and ...
  • 1
0 votes
1 answer
89 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 ...
  • 13
-3 votes
1 answer
93 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
-1 votes
1 answer
67 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
304 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
66 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
139 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
304 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
104 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 ...
1 vote
2 answers
332 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
774 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,965
0 votes
3 answers
175 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
1 answer
49 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
78 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
167 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
247 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
902 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
131 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
285 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
128 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 = ...
  • 997
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
1 vote
1 answer
74 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") ...
  • 239
0 votes
0 answers
55 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'...
  • 149
0 votes
4 answers
303 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 ...
1 vote
2 answers
258 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
77 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
407 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
95 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
-1 votes
2 answers
75 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
65 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
508 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
-4 votes
2 answers
114 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
330 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
170 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
66 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
0 votes
1 answer
41 views

How to check for docker specific code and APIs in an application for later migration to containerd?

So I have a couple of Java RESTful microservices, and since the past few years I have basically been using Docker to build them and deploy them over to a Kubernetes cluster. Our team is upgrading ...
  • 3
0 votes
2 answers
197 views

Microservices - create post for logged in user

I am working on a small project with microservices architecture in Spring Boot. As to not make unnecessary calls to users-microservice, I have duplicated some necessary User data (id, name, summary, ...
  • 1
0 votes
0 answers
35 views

Design a Program which Forwards Work Pieces to Corresponding Modules

I am working on a program that will listen to a queue of incoming message and will process each message differently depending on the metadata of that message. The messages must be processed in order ...
  • 1
0 votes
1 answer
80 views

Help required in the right data structure for faster look up of data

I have the below given data model itemid - name - collectionitemid example: itemid |name | collectionItemId ------------------------------- 101 | abc | null 102 | def | 101 103 | ghi | 101 ...
  • 11
0 votes
0 answers
139 views

Is splitting Android activities/classes into many Kotlin extension functions a good or bad practise?

I have been working on an Android application for some time, and ever since the beginning I've developed a practice of splitting my class's (mostly activity/fragment) code up into multiple files. This ...
-2 votes
1 answer
409 views

Best way of handling concurrent requests

I am working on an Authentication system (java based) that will authenticate users and create a session for them. This session is valid for 5 hours. I do not want the same user to have multiple ...
  • 97
0 votes
0 answers
27 views

Keycloak duplicate registration page

I have a case where I need to separate the users by type in Keycloak.Basiacally the entire application is separated by two user types. For the purposes of the example let's say a seller and a buyer. ...

1
2 3 4 5
97