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
357 views

How Should I Process A CSV To REST?

The client wants to put a CSV file on an FTP server, have it processed then have an error file put back in a different directory. We are only a small company so we can only afford to support Java as ...
opticyclic's user avatar
6 votes
1 answer
689 views

How does Dependency Inversion solve switch cases?

I want to understand how Dependency Inversion gets rid of switch cases. Consider a service that needs to communicate with several databases. class StockUpdater { private final DataStore datastore; ...
A.Dumas's user avatar
  • 262
0 votes
0 answers
81 views

How should I handle keys in production

I'm creating an authorisation service, which does signing using a key. For local development I was randomly generating a key on application start-up. Now I'm deploying to the cloud (currently going ...
Tobi Akinyemi's user avatar
2 votes
2 answers
810 views

GetOrCreate method for a database operation

I have read this thread: Is it bad coding practice to create something in a get if it does not exist? But, my question involve a method which gets a record from a database or creates it if it doesn't ...
MrChudz's user avatar
  • 129
0 votes
3 answers
1k views

How should an abstract class require a value that will be constant for each subclass?

Let's say I have an abstract class A exposing a method called getE() which returns an object of type E which is an enum. The value returned by getE() will be defined per subclass. Put differently, ...
cegredev's user avatar
  • 111
1 vote
1 answer
160 views

Good approaches when one needs to access private variables in production systems

At my company we needed access to some variable to call a method on it, this variable is hidden about 6 layers down of different libraries code and each time it is behind a private variables (that ...
JustSomeGuy's user avatar
8 votes
5 answers
3k views

Interface implementation where one method body remains empty

I have producers that take data A, produce data B and send it public interface Producer<T>{ void produce(T data); void flush(); } public class DataBaseProducer ...
Johnyb's user avatar
  • 407
4 votes
2 answers
2k views

Factory pattern where some classes require additional paremeter(s)?

We have multiple publishers, that publish the data somewhere. For example, we have ElasticSearch publisher, AWS S3 publisher, or file publisher. Now the interface looks like this interface Publisher&...
Johnyb's user avatar
  • 407
1 vote
0 answers
89 views

Best Practices for multiple development efforts, different versions of Java

I'm the sole developer working on multiple projects on different versions of Java, plus some Microsoft Sharepoint front end projects. I REALLY need to figure out a better setup for my development ...
headlikearock's user avatar
2 votes
5 answers
1k views

How can I write an enum for date periods where not all periods have a static number of months?

I have an enum that works very well to represents date periods and the number of months in those date periods: public enum StandardDatePeriod { ONE_MONTH(1), SIX_MONTH(6), ONE_YEAR(12), ...
James's user avatar
  • 285
0 votes
3 answers
1k 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 ...
James's user avatar
  • 285
6 votes
1 answer
413 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 ...
user8297969's user avatar
-1 votes
2 answers
997 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 ...
codingpartners's user avatar
1 vote
1 answer
380 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, ...
shulito's user avatar
  • 121
3 votes
4 answers
667 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 ...
George Z.'s user avatar
  • 705
28 votes
7 answers
7k 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....
The Chinky Sight's user avatar
2 votes
2 answers
462 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; ... ...
Cosmica's user avatar
  • 87
-1 votes
1 answer
134 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 ...
AnOldSoul's user avatar
  • 173
1 vote
2 answers
263 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 ...
MPIchael's user avatar
  • 219
0 votes
3 answers
2k 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 ...
lamb_bd85's user avatar
11 votes
5 answers
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(...
The Chinky Sight's user avatar
0 votes
0 answers
46 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 ...
AzureMinotaur's user avatar
0 votes
3 answers
202 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 @...
hfg124g76g1's user avatar
-1 votes
1 answer
271 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) { ...
Celdor's user avatar
  • 128
2 votes
1 answer
269 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 ...
AnOldSoul's user avatar
  • 173
1 vote
1 answer
174 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 ...
crazy_code's user avatar
0 votes
0 answers
38 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 ...
Tobi Akinyemi's user avatar
0 votes
1 answer
450 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&...
CompSydBoi's user avatar
1 vote
2 answers
130 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 ...
Apollo's user avatar
  • 121
4 votes
7 answers
1k 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 ...
FreshOuttaTheBag's user avatar
0 votes
2 answers
236 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 = ...
Pavel_K's user avatar
  • 175
4 votes
3 answers
3k 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 ...
Diggi55's user avatar
  • 51
1 vote
2 answers
120 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, ...
Wiktor's user avatar
  • 33
0 votes
0 answers
47 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 ...
Wiktor's user avatar
  • 33
-4 votes
1 answer
65 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 = ...
whiteRice's user avatar
0 votes
2 answers
687 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 ...
Smile's user avatar
  • 111
3 votes
2 answers
409 views

What to do when putting logic into the database seems to be the only option?

I am currently working on an application that models a complex business process that consists of many steps, each having a 1:n relationship with subsequent steps. The software is written Java using ...
xgb84j's user avatar
  • 149
-1 votes
1 answer
3k 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 ...
Pedro Gouveia's user avatar
4 votes
2 answers
153 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 ...
Rui's user avatar
  • 1,691
2 votes
2 answers
312 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 ...
George Z.'s user avatar
  • 705
1 vote
1 answer
707 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 ...
Astrum's user avatar
  • 143
-3 votes
1 answer
91 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....
Alperen Üretmen's user avatar
1 vote
1 answer
380 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 ...
london tom's user avatar
1 vote
4 answers
211 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 ...
Marco's user avatar
  • 27
0 votes
0 answers
90 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 ...
kry's user avatar
  • 101
3 votes
2 answers
162 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 ...
Jordi Pagès's user avatar
0 votes
1 answer
349 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 ...
Smile's user avatar
  • 111
1 vote
2 answers
1k 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 ...
Jack Avante's user avatar
0 votes
1 answer
4k 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 ...
theimpatientcoder's user avatar
0 votes
2 answers
213 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 ...
George Z.'s user avatar
  • 705

1
3 4
5
6 7
99