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
2 answers
68 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 /...
user avatar
  • 111
-4 votes
2 answers
61 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 ...
user avatar
-2 votes
1 answer
99 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. ...
user avatar
0 votes
2 answers
80 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 } ...
user avatar
0 votes
1 answer
48 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. ...
user avatar
  • 25
-1 votes
0 answers
31 views

Integration test for java based command line tool

I am working on a Java-based command-line tool that interacts with many services and returns results back on the terminal. Going forward I want to deploy this command-line tool as a java microservice. ...
user avatar
  • 1
0 votes
1 answer
39 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 ...
user avatar
  • 3
0 votes
2 answers
102 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, ...
user avatar
  • 1
0 votes
0 answers
34 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 ...
user avatar
  • 1
0 votes
1 answer
77 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 ...
user avatar
  • 11
0 votes
0 answers
51 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 ...
user avatar
-2 votes
1 answer
85 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 ...
user avatar
  • 97
0 votes
0 answers
15 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. ...
user avatar
0 votes
0 answers
43 views

Refactor conditional multiple AND OR operations? [duplicate]

I have a piece of code where two objects (incoming request object and a profile object) are to be checked for matching conditions. So the first method is as below where I check whether the profile ...
user avatar
2 votes
2 answers
151 views

What is the alternative to checked exceptions in API/interface design?

Despite checked exceptions being generally bad practice and anti-pattern, I find one feature very useful: having list of checked exceptions part of function signature. Checked exceptions are "...
user avatar
  • 129
0 votes
1 answer
132 views

Mock a bean with 10 methods when I only use one?

I face some situations similar to the following simplified one: @Component class ServiceOne { @Autowired ServiceTwo two; void act() { ... two.a(); ... } } @...
user avatar
  • 181
1 vote
1 answer
95 views

Does it make sense to use byte instead of int in Java? [duplicate]

Recently, I had to implement a business rule in a certain project. The rule basically consisted of checking a range between 1 and 12, values that would be used later, in some way, with Bootstrap. ...
user avatar
  • 49
2 votes
4 answers
223 views

What are the advantages of externalizing application configurations?

I was learning about micro services with spring boot and came across spring cloud config server which is used to exernalise application configuration.The advantage it state is that one can change the ...
user avatar
  • 129
0 votes
1 answer
143 views

Unit testing parts that use a Value Object that is being created by a Factory

Here is the conundrum, I have a fairly complex Value Object and I don't want to expose it's internals. It should not be an Entity since there is no need for attaching an identity to it. According to ...
user avatar
  • 3
-1 votes
2 answers
111 views

Do I really need TaskManager class? [duplicate]

Background: I'm coding an app, the core idea is simple - I can choose a 'Task' (consists of name, code to perform aka Runnable, progress) through GUI, start it, stop it, start all 'Task's and stop all ...
user avatar
  • 35
1 vote
3 answers
144 views

Should test resource files be stored inside the Java class source directories?

In a TDD (Test-Driven Development)-based Java project built by maven, lots of classes needs to be tested with text-based input files such as .csv. At the beginning, I put them into the src/test/...
user avatar
  • 1,487
-1 votes
1 answer
80 views

API request and response from event consumer

How to expose an API using the traditonal request-response style while internally it handles it in event driven way (pure or partially event driven), given that if callback style may not be possible ...
user avatar
  • 109
2 votes
2 answers
228 views

"Returns true if changed" pattern [closed]

The Collection interface in Java has, among others, these methods: boolean add(E e) boolean addAll(Collection<? extends E> c) boolean remove(Object o) boolean removeAll(Collection<?> c) ...
user avatar
  • 137
-4 votes
1 answer
84 views

Pass a value to a class via a constructor or a method? [closed]

I'm newbie in Java and I have question. Pass a value to a class via a constructor or a method? public class HelloWorld{ public static void main(String []args){ TextModifyFirstVersion ...
user avatar
  • 3
0 votes
1 answer
298 views

Java: Is there a performance difference between variable assignment vs. inline usage?

Is there any performance detriment to assigning variables vs using them inline. I'm guessing this WOULD be worse if a method was returning primitive and I was 'boxing' it (e.g. method returning int, ...
user avatar
  • 287
0 votes
3 answers
263 views

Efficient way to merge two similar objects (where only a few fields are different)

I am being challenged (or confused) by this problem: I have a List<CustomObject> in which each element has around 20 fields/attributes. In this list I might have sort of duplicate items. Four ...
user avatar
  • 111
0 votes
1 answer
109 views

Dealing with multiple application instances

I'm developing an application (Java & JavaFX) that writes/reads data (a file). The problem is I don't want to restrict user to run only one instance (of my app) at a time, as I really can't think ...
user avatar
  • 35
1 vote
1 answer
111 views

Shared mutable object in Multithreading

I have a class like this. (My actual class is different. I am using this to explain the problem). This class instance is shared between 2 threads. However those 2 threads (thread1 and thread2), call ...
user avatar
0 votes
1 answer
52 views

Design a non replayable endpoint for a service

I am trying something out in Springboot and stuck with a weird issue where I want to send some data from my frontend (react app) to backend (SpringBoot) and make that request non replay able by users (...
user avatar
2 votes
3 answers
348 views

In vertical slice architecture, how can I deal with entities/repositories that are used in multiple slices?

I'm trying to group the components of my system by funtionality. This is the analysis class diagram of my system model. A service class that involves a Post entity might necessarily interact ...
user avatar
  • 299
1 vote
1 answer
131 views

How to define vertical slice in a system whose horizontal slices are defined by Java modules?

For the project I'm working on I was thinking to create a Java Module for each layer of my system: servlet-presentation defines the implementation of the presentation layer. It is composed by Java ...
user avatar
  • 299
1 vote
2 answers
91 views

Ensuring run-once behavior in a multi-threaded environment via volatile lambdas?

I'm coding an enum strategy pattern where one of the strategies makes use of an ScheduledExecutor: class ControllerImpl { //... boolean applyStrat(StratParam param) { getStrat().apply(...
user avatar
  • 345
0 votes
1 answer
149 views

How can I split tightly coupled code in an OOP language?

So I've a class that is some kind of wrapper of a state machine for a multipart upload and it's database writes/reads. Everytime something is uploaded via REST basically the following happens ...
user avatar
  • 141
1 vote
1 answer
56 views

How to represent CDI interceptors in class diagram?

I have the following classes: public class MyCaller{ @Inject private MyService service; private void callerMethod(int arg1, String arg2){ service.serviceMethod(arg1, arg2); } }...
user avatar
  • 299
0 votes
3 answers
89 views

Communicating error conditions in client API for remote RESTful server, what's the best way?

I'm writing an application based on a RESTful API located in a server (written in Python). An Android app will access the API endpoints to get, post, put or delete data. The usual. The server has a ...
user avatar
0 votes
0 answers
61 views

What is the correct approach to test CDI classes in service layer?

My app has a service layer which is composed by CDI @ApplicationScoped beans. This is a class extracted from my project: @ApplicationScoped public class PostService { @Inject private ...
user avatar
  • 299
0 votes
1 answer
172 views

Should i specify that my methods "throws ConstraintViolationException" if the exception is actually thrown by a CDI interceptor?

Here is a sample method: @ApplicationScoped public class MyClass{ public void getUser(@Min(1) int id){ //get User logic } } I'm in a CDI environment with @ValidateOnExecution(type = ...
user avatar
  • 299
34 votes
3 answers
5k views

What is the point of repeatedly executing the same test?

I have recently learned about the not-well-known and not-widely-used annotation @RepeatedTest that, as the name implies, repeats the very same test n-times. Baeldung provides a short guide to this ...
user avatar
1 vote
1 answer
97 views

How to implement visitor if not all functions are supported for each Element?

I have two Visitor classes in my code Visitor1 and Visitor2 that execute functions on the classes ElementA and ElementB (both implement the interface Visitable that defines accept(Visitor)). I do not ...
user avatar
  • 129
1 vote
2 answers
210 views

Java - Is this a good use case of Java object optimization?

I recently joined a new project that is written in java. The project has been worked on for a few years by different developers, so there are many different code styles across different classes, and ...
user avatar
-1 votes
1 answer
98 views

Building a function call tree at runtime

Edit #1 I believe that I misrepresented my intent when writing this question by focusing too much on the issues that have arisen from our misuse/misunderstanding of locks. I am making this edit to try ...
user avatar
0 votes
0 answers
29 views

Handling logging through a java class and its dependencies

I have a method that depends on object creation from a different class, as well as some helper methods that come from a third class. The specific needs of this project mean that the logger is required ...
user avatar
  • 135
-3 votes
1 answer
93 views

Using braces on new line convention, but should I do this for one-line methods? [closed]

I've been using the braces on a new line convention for my java project: public String class() { something; { However I have quite a few methods, like getters, that could be written on one line ...
user avatar
0 votes
1 answer
140 views

Excessively verbose and cryptic comparisons in Java

I don't know if this is the right place to ask more of a "philosophical" question. The more I code in Java, the more I have to bear with Comparable<T>. And the more I bear with this ...
user avatar
-3 votes
1 answer
91 views

What is the correct collection to use in JAVA for indexing arrays of byte by a string in ordered way?

I am very new to the Java world (c# dev) and I have as asked the requirement to store some arrays of byte that should be indexed by a string and I have to keep the initial order of the collection. So ...
user avatar
  • 221
0 votes
1 answer
31 views

Is there a set of guidelines on how to handle/code execution of Spring Microservices RESTful API calls?

I'm building a RESTful web api using Spring Microservices. I am following the Controller/Service/Repository Structure. Where can I find some guidelines on what the responsibility of each class should ...
user avatar
  • 753
-1 votes
2 answers
222 views

How to access version of a Java application programmatically when running from an IDE?

As far as I understand, the best practice for programmatic access to the version of a Java application is to: Specify version via build system (e.g. in Gradle). Include the version string as a ...
user avatar
  • 113
0 votes
0 answers
35 views

For a SpringBoot REST API + React frontend independent CORS project, best method to implement messaging between users?

I have been looking into adding the messaging functionality to my application and I have been struggling to figure out the best approach to take. Everything seems very heavy and complex, I have been ...
user avatar
0 votes
1 answer
63 views

Interface design for container that holds different instances derived from a common type

I'm currently designing an interface for a container that is supposed to store references of different instances that derived from a common supertype. An analogy of it would be as following: Suppose ...
user avatar
2 votes
2 answers
230 views

Is it a code smell to have two different implementations of the builder design pattern, for the same model?

Shoutout to David Arno for teaching me about the builder design pattern via this thread! I have since used that pattern althroughout the code base to abstract out creating models from data stores, ...
user avatar

1
2 3 4 5
97