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
1 answer
80 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 ...
Trace's user avatar
  • 185
2 votes
4 answers
2k 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 /...
Pitto's user avatar
  • 141
-2 votes
2 answers
3k 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 ...
Mickael Bergeron Néron's user avatar
-1 votes
1 answer
1k 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. ...
vancan1ty's user avatar
  • 109
0 votes
2 answers
729 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 } ...
Jae Bradley's user avatar
0 votes
1 answer
101 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. ...
reign's user avatar
  • 125
0 votes
1 answer
43 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 ...
dnak's user avatar
  • 3
0 votes
2 answers
514 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, ...
don's user avatar
  • 1
0 votes
0 answers
36 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 ...
Conner's user avatar
  • 1
0 votes
1 answer
89 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 ...
Saran's user avatar
  • 11
0 votes
0 answers
368 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 ...
thebluepandabear's user avatar
-2 votes
1 answer
532 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 ...
Renjith's user avatar
  • 97
0 votes
0 answers
47 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 ...
Siddharth Trikha's user avatar
3 votes
2 answers
431 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 "...
SadClown's user avatar
  • 139
0 votes
1 answer
876 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(); ... } } @...
ch271828n's user avatar
  • 181
1 vote
1 answer
645 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. ...
Warlock's user avatar
  • 49
3 votes
4 answers
604 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 ...
Arjun's user avatar
  • 139
0 votes
1 answer
570 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 ...
Tetra's user avatar
  • 3
-1 votes
2 answers
208 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 ...
Wiktor's user avatar
  • 33
1 vote
4 answers
2k 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/...
Rui's user avatar
  • 1,615
-1 votes
1 answer
232 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 ...
once's user avatar
  • 109
2 votes
2 answers
270 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) ...
holmis83's user avatar
  • 137
-4 votes
1 answer
506 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 ...
nirega's user avatar
  • 3
0 votes
1 answer
1k 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, ...
nanotek's user avatar
  • 301
1 vote
3 answers
5k 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 ...
kosa's user avatar
  • 159
-1 votes
2 answers
618 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 ...
Wiktor's user avatar
  • 33
1 vote
1 answer
393 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 ...
RamPrakash's user avatar
0 votes
1 answer
63 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 (...
Abhijeet Shukla's user avatar
3 votes
3 answers
2k 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 ...
cidra's user avatar
  • 321
1 vote
1 answer
529 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 ...
cidra's user avatar
  • 321
1 vote
3 answers
149 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(...
walen's user avatar
  • 355
0 votes
1 answer
201 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 ...
Regyn's user avatar
  • 149
1 vote
1 answer
74 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); } }...
cidra's user avatar
  • 321
0 votes
3 answers
148 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 ...
ismarlowe's user avatar
0 votes
1 answer
306 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 = ...
cidra's user avatar
  • 321
35 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 ...
Nikolas Charalambidis's user avatar
1 vote
1 answer
173 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 ...
sininen's user avatar
  • 129
1 vote
2 answers
375 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 ...
user3334871's user avatar
-1 votes
1 answer
221 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 ...
notphilphil's user avatar
-3 votes
1 answer
124 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 ...
Scott Adamson's user avatar
0 votes
1 answer
207 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 ...
Thomas Herondale's user avatar
-3 votes
1 answer
93 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 ...
Dypso's user avatar
  • 231
0 votes
1 answer
36 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 ...
Lucas T's user avatar
  • 753
-1 votes
2 answers
1k 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 ...
andrybak's user avatar
  • 113
0 votes
1 answer
84 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 ...
torez233's user avatar
  • 101
3 votes
2 answers
533 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, ...
Mike Warren's user avatar
1 vote
1 answer
2k views

How to remove unused code from a jar file? [closed]

I have a jar file, for example foo.jar. My code contains a lot of libraries (almost 75 jar dependencies). I am not using anything like maven or gradle, I'm just using pure java with pure jar files as ...
Day Trip's user avatar
0 votes
3 answers
517 views

Is it a code smell to have a static factory method on the base class?

Suppose we have a BaseModel, which has a type enum, and derived models with same constructor signatures to each other, whose implementations are like : public DerivedModelJ(Object arg1, ..., Object ...
Mike Warren's user avatar
3 votes
4 answers
662 views

Is it a bad practice to have an interface method to tell whether it can handle an object?

interface Resolver { boolean canResolve(SomeInput input); SomeOutput resolve(SomeInput input); } public static void main(String[] args) { List<Resolver> resolvers = ...; ...
Martin Tarjányi's user avatar
1 vote
4 answers
1k views

Are static classes/methods good for pure business logic?

I have a service class that performs some operations. One of the operations is a piece of code long enough to warrant extracting to a new class and unit test it in isolation: @Service public class ...
KidCrippler's user avatar

1 2
3
4 5
99