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
5 votes
2 answers
405 views

When the stack frames become computationally expensive

I've been experimenting with different data structures and algorithms in Python, Java and C to see in what circumstances function/method inlining could bring meaningful gains in terms of the execution ...
user1069483's user avatar
0 votes
0 answers
114 views

Global Variables State Management

Background: I am working in a Java environment using Spring Boot, where I often encounter scenarios where global variable state management is critical, especially within singleton services. I have ...
Muhammad Haris's user avatar
-2 votes
0 answers
51 views

Spring/Java multiple shared modules for different databases

I'm implementing a software based on the micro-service architecture using Spring/Java. Each micro-service connects to either a PostgreSQL or a MongoDB database. Is it standard practice to have a ...
Amirhosein Al's user avatar
11 votes
7 answers
4k views

How to maintain dependencies shared among microservices?

There is a dependency jar containing tons of service classes mostly used to retrieve data from database, and this jar is used among several different micro services in one cluster. There is a big ...
Rui's user avatar
  • 1,865
1 vote
7 answers
434 views

How do I cleanly keep track of the type of various objects implementing a common interface without reflection?

In my multiplayer game I keep track of each player's inventory. I have a class for each inventory action that extends the abstract class InventoryItem. I then polymorphically call use() on the ...
Marvin's user avatar
  • 222
2 votes
2 answers
227 views

What's the value in exposing the dependencies you used for your tests?

In Java, there's the fairly ubiquitous notion of a POM file which provides the dependencies of your modules. For example https://repo1.maven.org/maven2/org/typelevel/cats-core_2.13/2.12.0/cats-core_2....
daniel purdew's user avatar
6 votes
4 answers
1k views

How to avoid init methods when 2 objects need the reference of each other?

According to https://softwareengineering.stackexchange.com/a/334994/432039, I know init is a code smell and should be avoided, and one of the solutions is to use a builder to hold the state first ...
wcminipgasker2023's user avatar
2 votes
2 answers
172 views

Why does a Java lambda need to explicitly mention the method of the functional interface?

import java.util.function.Function; public interface Printable { public String print(String s); public static void main(String[] args) { Function<String, String> fn = p -> p +...
releseabe's user avatar
  • 539
22 votes
9 answers
6k views

Using commented dashes to divide up code chunks [closed]

I'm taking another crack at learning Java with the aim of getting a job. As I write code, I sometimes find it quite difficult to navigate my code using the formatting I often see in tutorials. ...
KanagawaPunk's user avatar
1 vote
2 answers
78 views

End2End/integration Testing in Java with Selenium - how to get a good test structure - looking for experiences [closed]

At work I am currently tasked to implement End2End/integration Tests for one application using Selenium. we have an project consisting of a frontend and multiple backends (spring-boot apis). The ...
KilledByCheese's user avatar
0 votes
2 answers
178 views

Should Value Objects be used inside the DTO?

After reading about Value Objects, I think they're pretty cool and should be used, but I am not sure if I am doing it the right way. Let's assume that I have a simple DTO to create a user, which ...
Mercury's user avatar
  • 71
23 votes
5 answers
16k views

Are "factory methods" anti-pattern now?

I consider Joshua Bloch's Effective Java the best book on the language that I read. However, I started to wonder about something One of the things he suggested was to prefer public static factory ...
demavi's user avatar
  • 347
0 votes
1 answer
110 views

Where to put getOrSave responsibility?

I have many repeated parts of service logic which just fetches object if it exists or returns a newly saved one. I want to move it from service because it just clutters up the logic. But I do not ...
DimitrijeCiric's user avatar
-1 votes
4 answers
293 views

Is setting a flag in a loop a code smell?

I have a loop that I am testing a condition in but if the condition is not met then after the loop is complete, I want to execute another code block: Boolean loopConditionNotMetFlag = true; for (List&...
Devlinite's user avatar
3 votes
4 answers
358 views

throwing an exception or returning Optional

In a service daemon coded in Java, we have services for getting various objects. When we use these services forgetting an object, I wonder if the method should return the object and throw an ...
kommradHomer's user avatar
9 votes
5 answers
5k views

How can an interpreter run code without translating into machine code?

I'm in my intro classes and trying to understand how a Java compiler works. Most posts said a compiler translates A to B (which could be machine code) to run, while an interpreter 'just' runs the code....
miiky123's user avatar
  • 241
4 votes
4 answers
690 views

How to do "Separation of concerns"

I understood(edit: I assume) the importance of seperation of concerns and benifits in an application, But struggling to identify what are considered to be a concern (developer, feature, consumer or ...
Karthi Fair Hawn's user avatar
0 votes
1 answer
199 views

Should a Java project use UTF-16? [closed]

Java, by default, uses UTF-16 to represent characters in the String data type. I inherited a JavaFX project which currently has some Strings in UTF-8 and others in UTF-16. This is causing bugs (in pop-...
chilliefiber's user avatar
1 vote
5 answers
185 views

End method in normal flow versus exception flow

Consider the two following examples: public Something fetchSomething(String key) { if(somethingsMap.containsKey(key)) { return somethingsMap.get(key); } throw new ...
steros's user avatar
  • 121
-1 votes
2 answers
188 views

Idempotency for a financial transaction API

Say you have a REST API endpoint like POST /move-money which transfers money from your main account to a savings pot. There are three path parameters accountId for the user's account potId for the ...
MZokov's user avatar
  • 101
1 vote
2 answers
121 views

How do I reduce number of FieldValidator derivations?

I am trying to write RSQL Parser which checks if the RSQL is logically correct. while the RSQL Java library checks whether the RSQL expression is grammatically correct, it doesn't check if the ...
Govinda Sakhare's user avatar
5 votes
6 answers
2k views

Is it a good idea to return a Builder from a Factory?

I would want to have a builder for creating a complex object, for example Employee. I would want to be able to create my objects in two ways: Case 1. Get Employee with default values Case 2. Get ...
CuriousGuy's user avatar
0 votes
1 answer
110 views

In Java's Fork/Join is the operation for combining results limited to addition?

As I understand it, the join() method merge/composes/combines the results from all subtasks. A simple example I saw was summing the numbers from 1 to N and the subtasks would simply sum a range of ...
releseabe's user avatar
  • 539
1 vote
3 answers
295 views

How can I avoid duplicate annotations when validating both Entity and DTOs?

I am using the Spring Boot framework to create a RESTFUL API and I need a way to avoid the duplication of validation rules when using multiple DTOs as request/response objects for my endpoints. Using ...
Marco Pierre White's user avatar
0 votes
3 answers
327 views

How to refactor "init()" into "physically make them two separate classes"?

According to https://softwareengineering.stackexchange.com/a/334994/432039, I know "init()" method is a code smell, and "physically make them two separate classes" is a way to ...
wcminipgasker2023's user avatar
0 votes
1 answer
148 views

Is immutable objects over POJO in general?

Lombok is used in the legacy project where I am currently working for since last year. The project is legacy with 10+ years, and POJO/JavaBeans, i.e. @Data annotated classes, have been widely used for ...
Rui's user avatar
  • 1,865
19 votes
6 answers
7k views

Is utilizing a singleton for a cache an antipattern?

I'm currently writing an MVC application and I need a class that can: A: get, add and remove data(specifically a TreeSet of sorted strings that I want stored in memory, but I doubt the data itself is ...
Tyler Del Rosario's user avatar
0 votes
3 answers
346 views

Would you test this piece of configuration code? How do I determine which code is worth testing?

We have a piece of code that decorates an interface to transparently add retry logic. Inversion of Control configuration service.AddOurRestApiClient() .AddResilienceHandler("Retry", ...
LostInComputer's user avatar
14 votes
5 answers
5k views

How to "Tell, don't ask" when 2 objects involves in the condition and the decision at the same time?

According to Explanation on how "Tell, Don't Ask" is considered good OO, I know the following is bad: if(a.isX){ a.doY(); } public class A{ public boolean isX; public void ...
wcminipgasker2023's user avatar
0 votes
3 answers
343 views

Does turn "global state" into "passing parameter" increase the whole system coupling or not?

As far as I know, coupling is about counting number of other classes in a class, so for the following program that emulates a UI program that shows "WelcomePage" at start and also pops a ...
wcminipgasker2023's user avatar
1 vote
5 answers
604 views

How are strings simultaneously objects and primitive data types in C#?

In C#, strings can be used like objects with methods, properties, and other features of objects. At the same time, strings are treated the same as primitive data types like int or float in numerous ...
AcinonX's user avatar
  • 613
1 vote
1 answer
102 views

Non blocking algorithm for invalidating and reloading cache in concurrent environment using Redis (with Redisson)

I'm trying to come up with a peace of code that would fetch centralised cache shared across multiple threads/app instances. Callers might come in swarms. The data is a large set, reads during ...
FoxMulder's user avatar
0 votes
3 answers
320 views

How to solve a circular dependency with a composition relation?

For a game I'm making I have two objects; Gun and ReloadSystem. At the moment, these two object reference each other. Gun tells ReloadSystem to perform a reload when the gun gets clicked, and ...
Boudebouz1's user avatar
0 votes
1 answer
344 views

Clarification on using timestamp without time zone and LocalDateTime in UTC-centric systems

I'm seeking clarification regarding the usage of timestamp without time zone in a database and its corresponding Java type, LocalDateTime. The current setup I'm working on involves servers and (...
user avatar
2 votes
3 answers
480 views

Should I still "replace conditional with polymorphism" if the condition is from dynamic load data?

I know there are already some questions about replacing if else with polymorphism, for example: Applying Replace Conditional with Composition in functional programming Is it wrong to use any type of ...
wcminipgasker2023's user avatar
-2 votes
2 answers
268 views

How does Java and other managed languages achieve any performance, if everything is allocated at random places of the heap? [closed]

Prelude Recently, I helped a friend of mine in coding him a problem for his university Algorithms course, where problems are submitted in Java. I sent him code with good O notation complexity, ...
blonded04's user avatar
  • 105
0 votes
1 answer
166 views

How to correctly extend runtime exception?

We have a GraphQL server which sends data to the front end client. We have other tenants who will use our sever and host their code. I want to create a system where they all can create any custom ...
user415612's user avatar
7 votes
9 answers
8k views

Why just "interface segregation principle" but not "method segregation principle"?

According to one definition of "interface segregation principle" that states currently in Two contradicting definitions of Interface Segregation Principle – which one is correct?, a client ...
wcminipgasker2023's user avatar
1 vote
2 answers
450 views

Does Java keep stream objects in memory after mapping them?

Say I have the following stream: List<Other> list = Stream .of( new MyObject(), new MyObject() ) .map(this::mapToOther) .collect(toList()) ; So after this is ...
user1589188's user avatar
-3 votes
1 answer
120 views

Learn a framework on a project, or mix languages between backend services [closed]

I am designing my next project, which will do various domain-specific tasks, but all that will be controlled and used via a generic crud web app. I have been professionally using Java with Spring for ...
rafal.sz's user avatar
3 votes
4 answers
1k views

Representing vectors as arrays of points vs. as data structures

I'm writing a program in Java where I need to represent the position, scale, and other 3-dimensional properties of objects in a world using vectors. I can use either of these two approaches: ...
AcinonX's user avatar
  • 613
1 vote
0 answers
81 views

Package-by-feature within maven multi module package-by-layer project

As a consultant working for multiple companies that are using maven multi modules I have made the same discovery with all of them that I find strange. Lets say they want to build a webapp for a ...
olimtrail's user avatar
1 vote
3 answers
231 views

Java design approach for "duplicated" class that are identical, except the import sources are different

So I have two identical classes, say ClassA and ClassB. In both classes, they operate on the same kind of data classes, and the method bodies are exactly the same. The only difference is that the ...
kroger9's user avatar
  • 25
2 votes
1 answer
101 views

impacts on splitting web application (java) for reducing memory & compute footprint on primary user-facing app

TLDR; what if you are tasked with taking out a feature and making it app 2 to reduce memory/compute foot print from app 1? Making an API contract between app 1 & 2 would defeat the purpose ...
veritas's user avatar
  • 131
0 votes
0 answers
31 views

Bean Custom Constraint Validator in multiple projects which common domain model

I have multiple maven projects ( rest services ) with common domain model. I would not say micro services. Structure is build this way to eventually move towards mircoservices. All the maven projects ...
Bhalchandra K's user avatar
0 votes
1 answer
138 views

Java Security, How important is the version of JDK for building vs running the Application

How important is the minor version of the Java Build SDK vs. the JDK version at runtime, is it a problem if the minor version is a bit outdated, if the run time version is still up to date? More ...
xyz1234's user avatar
  • 11
1 vote
5 answers
471 views

DTO vs POJO (Entity) on POST request

If I have for example a User POJO like the following @AllArgsConstructor public class User { @Id private final String id; private String username; private String password; private Date createdDate;...
iqueqiorio's user avatar
0 votes
0 answers
94 views

By creating an architecture, it is better to have many classes that handles different scenarios, or a single one that handles all? [duplicate]

During my limited professional experience, I have been involved in microservices projects with a common structure: The Controller takes a request and validates it using the jakarta.validation....
Paul Marcelin Bejan's user avatar
2 votes
5 answers
358 views

Refactoring Java class for a cleaner design

I inherited some code that I have spent some time reviewing to get a better handle on its design. There is one class that I came across that I have an idea for refactoring, but I am wondering if it I ...
user1154644's user avatar
-2 votes
2 answers
78 views

How to send non real time push notifications so that the servers aren't hogged?

Our android application is built on java. And while sending push notifications we're using tomcat as a server. And it is doing more harm than good. Currently all the push notifications (FCM/APN) are ...
tuck_y's user avatar
  • 181

1
2 3 4 5
99