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
0answers
6 views

How to eliminate an unnecessary interface?

I've inherited some Java code that has a bunch of unnecessary interfaces in it. Each one is only implemented by a single class and there are no plans for additional classes. What they do do is make ...
0
votes
3answers
39 views

How to design RESTful API for response object properties dependent on request parameter

I have a RESTful service where clients provide product codes, start date and end date. In response, the service returns a list of price metrics for the products over the date range. Start date is ...
-1
votes
0answers
39 views

Java: getXClass() vs getXType() [closed]

Please consider the following code: class Person {} class Student extends Person {} class Manager extends Person {} //#var 1 class Main { private Class<? extends Person> personType; ...
4
votes
1answer
58 views

Should operations on properties of list objects be encapsulated in a domain class that wraps the list?

I have a list of product price objects, List<ProductPrice>. @Value public class ProductPrice { Long id; LocalDate startDate; LocalDate endDate; BigDecimal value; } From ...
0
votes
1answer
36 views

Consuming Multiple resources from a single REST Service

I am developing a Spring Boot Application which consumes another REST service to get the User's Account information. The same service provides multiple operations like: GET: /userid/retrive -to get ...
0
votes
0answers
33 views

Overloading vs another method for concrete example [duplicate]

Suppose, we have a create method: public void create(MyEntity entity, Foo foo, Bar bar) This method creates entity. Now, we need a method to create entity and lock it. And I see two solutions here - ...
1
vote
1answer
105 views

Rock Paper Scissors with Visitor Pattern

I've been going over the Visitor Pattern to try to understand it. Is this a correct implementation of the Visitor Pattern for RPS?? Here's the implementation code: public enum ResultEnum { WIN, ...
2
votes
3answers
69 views

Do I have LocalDTOs? If yes, what is a good approach to keep encapsulation of the domain model?

LocalDTO term refers to Fowler's article. Say I have a domain entity Person: public class Person { private String id; private String name; private int age; } This entity has its own ...
28
votes
7answers
6k views

How does this switch statement do “multiple things”?

This doubt is about Switch Statements from Chapter 3: Functions of the book named Clean Code Here we have a function: public Money calculatePay(Employee e) throws InvalidEmployeeType { switch (e....
2
votes
2answers
95 views

Exposing methods for polymorphic children from the aggregate root

Consider the following fictitious toy example: There is an aggregate root DayChecklist that holds a list of Tasks planned for the day: class DayChecklist { String id; DateTime today; ... ...
-1
votes
1answer
47 views

Optimizing methods with multiple if checks on getter values

I have a method where I fetch user input, check if certain values exist, and based on that build my own custom input object that I would use to search in a database. The code for the search method is ...
1
vote
2answers
70 views

Best Practice: Unit test coverage vs. in-method sanity checks [duplicate]

I have a code-coverage requirement of of a certain percentage, and face the following tradeoff: Should I sacrifice in-method sanity checks and error handling for ease of (unit-) testability? Lets ...
0
votes
3answers
81 views

DDD - storing and retrieving entities of an aggregate from the outside

In my doctor's appointment booking system, I identified the following entities: Doctor Patient Appointment I also identified an aggregate, which is Doctor (aggregate root) and Appointment. It's an ...
8
votes
5answers
2k views

What does “If a function does only those steps that are one level below the stated name of the function, then the function is doing one thing” means?

This doubt is about function doing one thing from Chapter 3: Functions of the book named Clean Code Here Uncle Bob is talking about this function: public static String renderPageWithSetupsAndTeardowns(...
0
votes
0answers
34 views

Architectural design for sending large amount of analytics data from production servers to s3 without impacting request performance

Lets say we have a server getting upto 1000 requests per second, serving them at p99 of 20ms (strong business case for not increasing this latency). The server gc parameters have been carefully tuned ...
0
votes
1answer
15 views

How best to structure my Service/Repository layers when persisting a Many to One object?

I'm working on a project where I need to do CRUD operations on Book and Library objects. Naturally the relationship between Book and Library is Many to One, like so: @Entity @Getter @Setter @...
-1
votes
1answer
162 views

Binary search is not fast

I am trying to put in practice an algorithm for binary searching and compare it with linear searching: linear search: public static int linearSearch(ArrayList<Book> books, int searchedId) { ...
2
votes
1answer
128 views

Composition or Inheritance for classes with almost similar implementations but different input and outputs for methods?

I have the following classes, which have quite similar method implementations. Only the classes' method inputs and outputs seem to be of different types. When I put it like this, it sounds like a case ...
1
vote
1answer
56 views

Feature Store Design for input data like JSON, CSV and Excel

I need a design approach for a feature store which accepts input data in the forms of CSV, EXCEL, JSON etc. The backend stack we support is Java, Spring boot and oracle DB. Note : Each file ...
0
votes
0answers
25 views

Synchronising OIDC Provider and User Table

I asked this question on SO which is related to this. In this question, I propose exchanging a token from my OIDC provider for a token in my own custom OIDC provider, which becomes the ultimate token ...
0
votes
1answer
140 views

Design pattern for two inputs?

First of all, I had task 1 and it was about rest API, requesting calls using httpclient in order to use the functions of an API. We get an input from a user, either "Online" or "Offline&...
1
vote
2answers
71 views

Are the exceptions used in BeanValidation/JAX-RS's ExceptionMapper an anti pattern?

I am reading a lot about patterns and code structure and something that bothers me is BeanValidation's way to handle errors. I like Java and think that BeanValidation is easy to use, but it seems to ...
4
votes
7answers
481 views

When to use a class with a constructor vs using a method returning an object

I've been working in a rather large codebase filled to the brim with small classes such as class Person { public string name; public int age; public int height; } As a mainly front-end ...
0
votes
2answers
156 views

What is the best practice to name a method that must either return saved result or resolve it?

Consider the following java code: public class Foo { private Bar bar; .... public Bar xxxBar() { if (this.bar == null) { //resolve bar this.bar = ...
4
votes
3answers
269 views

What about Utility-Classes, but without hard dependencies?

The average utility class: A stateless class that provides some functionality by exposing static methods. Its default constructor is private to avoid instantiation. When ever the average utility class ...
1
vote
2answers
109 views

Designing UI module for an application

I have an UI module that will expose only one class - UserInterface. The class will be responsible for collecting user input and providing output (command line UI style). From logical way of thinking, ...
0
votes
0answers
39 views

Choosing proper design for modular application

I'm creating an application using the jigsaw modules system. The app will just perform some tasks in multithreaded environment. In my mind the app architecture (modules) looks like that: Work (the ...
-4
votes
1answer
58 views

Calculate math function depend on N value [closed]

I have method with the following prototype : R[] = method(k,n) which : n = ordinal value 0 <n <10^9 k = math function depend on n value : i.e n^6 R = array of computed values For example : n = ...
0
votes
2answers
106 views

Which design pattern to use to make a mix of in-sequence and parallel HTTP calls?

We have to make a bunch of HTTP calls from Java/Spring-Boot application which will be mix of in-sequence and parallel. Level 1 : We make 3 parallel calls to Services 1 , 2 and 3 Level 2: After service ...
-1
votes
1answer
91 views

If I have 2 different implementations of the same interface but with the same methods should I have 2 interfaces? [closed]

I have 2 different implementations of the same interface, but each one of those objects have different implementations, however they have the same methods, should I create one interface for each type ...
4
votes
2answers
123 views

Why were the get/contains, remove operations on Collection and Map designed without generic types but add/put/ operations with generic type

According to the Java API documentation, the Collection<E> has: boolean add(E e) Similarly Map<K,V> has: V put(K key, V value) Among these methods, generic types like K, V, E are used ...
1
vote
1answer
54 views

MVC: Should my domain model look like this?

Consider the following GUI screen (Java Swing) with a list of persons where the user can select a person and delete it. According to MVC, the view observes (observer pattern) the model and updates ...
1
vote
1answer
93 views

Java REST services - What are best practices regarding DTOs?

I've been working on a project that communicates with a service which sends very complicated REST responses. Current "best practice" on this team is that we use POJO DTOs to handle all data ...
-3
votes
1answer
68 views

Should you use your own implementation of inversion of control instead of a dependency injection container? [duplicate]

I have a small project that has 6 service classes and a main class. Since they are service classes and does not store any state in it, I declared one static method in each one: class Main calls A....
0
votes
1answer
105 views

java threading model for scale up

I need some advice on the scale-up issue. we have a java application currently it works as below the current system is using the Thread Per Request Model. each client connection (long-running and ...
1
vote
4answers
133 views

Architectural problem for class combination (cartesian product) for save format strategy

Hello to everyone and thank you for any suggestion. I have a family of subclasses of Track (Track is abstract). Every concrete Track has a different number and types of fields (attributes) that extend ...
0
votes
0answers
60 views

Best choice for a holding large number of objects in java

I have a set of array, containing a large number of objects (products), which has lately grown so large, searching in it takes about a minute, which is considered too long, since one search is ...
2
votes
2answers
96 views

Checking the user in almost all use cases

I have a web application that has Users that belong to Companies. A User can only belong to 1 Company at a time and they can manage their own company information. I'm using java spring and I'm ...
0
votes
1answer
64 views

How to use single Spring-Boot instance to cater to multiple environments?

We have a Spring-Boot Web application currently deployed to 7 environments (DEV, SIT, UAT, Pre-Prod, Prod, etc.). This application connects to other REST services, which has different URLs for each of ...
1
vote
2answers
90 views

Efficient and correct way to store image data in Java? [closed]

To clarify, I'm having to develop a GUI application that stores information about clients (for a course) where one of the fields is the logo of the client. I'm currently using serialization to persist ...
-1
votes
1answer
82 views

Design Pattern for accessing data over RestAPI calls

I am looking out for a general design strategy or pattern designing various components in my client application. Here are high level details: The data is accessed my making a RestAPI call. The data ...
0
votes
2answers
112 views

Is there any benefit testing only with mocks/fakes/doubles?

Say I want to test the behavior of the GUI while I follow a PassiveView approach. I also use the command pattern to handle the actions of the user. So given a PersonView and a PersonService with a ...
-1
votes
2answers
86 views

Payment Processor using polymorphism?

I am writing a payment Processor class, then will take different payment objects in input and talks to external services to process payment.My class is designed using polymorphism as follow: public ...
15
votes
4answers
3k views

Should entities contain information about their amount?

Can I get some thoughts on the entity design? Let's say I have an entity called Book. Let's say I create a specific instance of that book. It has a title A and an author B. Since there can be multiple ...
0
votes
0answers
50 views

Designing a unique id reliably based on a String date?

I am creating an Android application that sets alarms based on the String date of a list of Objects (PendingIntents, with each taking in an id, that is an integer). In order to cancel the ...
0
votes
2answers
101 views

Where should I put the initialization validation of a Value Object?

Hi I am making a Value Object. public class Age { public Age(int age) { Value = age } public int Value { get; private set; } } I want to check ...
-2
votes
2answers
68 views

Where to place exception handling while using Decorator design pattern

How to design a service layer structure that will be resistant to exceptions. Let's say I have a simple OrderService service, this service performs basic operations - saving an order. public interface ...
0
votes
3answers
129 views

Map same POJO values to different variables based on Key value without switch case

Based on the string "key", I want to get the latest and previous values assigned without using the Switch case. I need some mapper method that it get the key value as input and map the ...
0
votes
1answer
96 views

Does it make sense to create a WAR anymore?

This is more specific to spring boot projects and applications whose main USP is its APIs. Now that we can simply create a JAR file deploy it anywhere, what is the point of WARs? Is there a specific ...
2
votes
2answers
97 views

Foreign Keys and Eventual Consistency

We have a project that loads metric data from various etls and services into an AWS SQS queue, where that data is processed and inserted into a metrics database, also running on AWS RDS. When we ...

1
2 3 4 5
95