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
1
vote
5answers
144 views

Assertion statements: Remove or retain in production code

I'm working in a large company and am doing my first Java project here. We have certain code style guidelines. In the Java guideline, it is said that "assertions are only intended for debugging ...
-2
votes
1answer
55 views

Version naming for source code with multiple build targets

I have a Java library which is deployed automatically to Maven central. Right now this library has Java-1.8 target SDK, I want to continue releasing source code with this target and add new target ...
2
votes
2answers
143 views

Should function names describe their parameter types?

If you wish to perform the same action using different parameters, you can either make differently named functions: public Apple findAppleById(long id){ return repo.findById(id); } public Apple ...
-3
votes
0answers
29 views

New Mongodb based micro service advice requested [closed]

Coming from an Oracle and Java background... Have been asked to create a micro service using Mongodb. Not knowing mongodb well, I'm not certain what my best design choice is. In the Mongodb, I'll be ...
-2
votes
0answers
23 views

How to create, manage and use multiple dynamic database connections at run time?

As I am creating different database connections on the basis of database credentials (i.e. JSON or POJO with all the credentials required to create a DB connection). e.g. Imagine a Map containing ...
1
vote
1answer
59 views

Interactive and Batch traffic in one service

I am designing a workflow, and am trying to avoid parallel deployments of the same service. Thus I am looking to have one service that handles both interactive and batch traffic. My main concern is ...
-3
votes
0answers
71 views

How to implement state machine to card games such as poker or russian poker?

These are my class designs: I also have Controllers where I can create table, create users add users to table, deal hands simulate user bets using PostMan (Above classes are game engine classes, I ...
1
vote
4answers
278 views

Does the JVM compile bytecode into machine code and run it or does it just run bytecode directly?

Java source code is compiled into bytecode for the JVM. But, how does JVM convert bytecode into machine code? Does it re-compile bytecode into machine code and then run it? Or does it simply just run ...
0
votes
1answer
92 views

How to combine data from multiple sources into the same object?

I've been running into a common pattern when requesting data from multiple sources: Have a list of objects from one source (e.g. a list of Cars) with an id property and a few other properties ...
0
votes
0answers
34 views

Should we use a separate artifact repository for Maven snapshots?

Background We are currently using Maven for build and dependency automation. Our source code is in CodeCommit/Git. We are investigating CodeArtifact as our Maven artifact repository. We are using ...
-1
votes
2answers
133 views

Implementation of method differs only in one line

I have 2 implementation of the interface: public interface MyInterface{ void getCollectedData(MyData mydata); } public class MyImpl implements MyInterface{ public void getCollectedData(MyData ...
0
votes
2answers
180 views

Is it bad to use checked exceptions as API response?

Consider the following code: public class User { private String password; public void changePassword( String oldPassword, String newPassword) throws ...
0
votes
1answer
51 views

Exception handling with failure atomicity in desktop applications

When it comes to exception handling, there are many guidelines and best practices on the web. On of them is to throw early, catch late, or even Don't Catch. So when facing an exception, the current ...
1
vote
2answers
122 views

Granularity of a Method

I have a general design question. Suppose I have a List: List<String> list = new ArrayList<>(); list.add("Str 1"); list.add("Str 2"); list.add("Str 3"); I ...
1
vote
2answers
177 views

Concept/Design question: Alternatives to switch/conditional statements and Enums

I am practicing design patterns and OO concepts such as inheritance in java and I'm writing an application that represents a vending machine. I have two questions focused on ideal structure and design ...
5
votes
5answers
299 views

Java instanceof and Clean architecture

It seems to me that there is a conflict between clean architecture and the recommendation not to use instanceof. Consider the following code: class ParentEntity { } class AEntity extends ParentEntity ...
0
votes
0answers
91 views

Why does Protobuf generate outer classes for Java?

I googled this and found questions like "How to use Protobuf message as java class without a java outer class?" (https://stackoverflow.com/questions/60312156/how-to-use-protobuf-message-as-...
1
vote
2answers
351 views

Are experienced developers and software architects able to describe an entire software application in terms of design patterns?

Do experienced developers and software architects see entire application in terms of design patterns? In other words experienced developers and software architects able to describe an entire software ...
0
votes
1answer
94 views

Should I define a separate interface for clarity rather than implementing Supplier<T>?

Let's say you have to meet some prerequisites before doing something. For that, I think implementing Supplier<Boolean> is a great candidate since it's widely used, and quick to understand. But, ...
2
votes
3answers
151 views

Java design: there is two interface: B extends A. A and B have one subclass each, named ABase and BBase, can I make BBase extend ABase?

there is two interfaces A and B: public interface A { } public interface B extends A{ } A and B have one subclass each: public abstract class ABase implements A{ } public abstract class BBase ...
1
vote
2answers
79 views

Is using KDoc/Javadoc comments inside of a function considered bad practice?

I often find it helpful to use KDoc/Javadoc comments inside of a class or function instead of normal comments. IntelliJ colorizes them more obviously by default and, more importantly, allows ...
0
votes
2answers
147 views

Difference between Efferent Coupling and Dependency Injection

I am working on research that analyzes dependency injection (DI) in Java projects. The more I read, the more I get confused by DI in relation to other frameworks and even software quality metrics. I ...
1
vote
1answer
151 views

How do you pass enums between microservices, without need to have copies of enums in different services?

I'm working with microservices, and I see an issue. There are two services, that transfer info between each other via jsons. Because of this, we have to store our enums in strings, and serialise-...
2
votes
4answers
319 views

Alternative to using enum

The project I'm working on has a code dependency on a TeamNames enum. The problem with this is that the project needs to be recompiled and redeployed on any addition/deletion in TeamNames. How can I ...
2
votes
2answers
154 views

Should "add" methods return the update object? [Java - Clean Code & Best practices]

I'm following a course on Udemy and the teacher said that is a best practice return the update object in an add method. This is the example: public Recipe addIngredient(Ingredient ingredient) { ...
-2
votes
1answer
157 views

Why aren't constructors atomic? [closed]

If thrown exceptions in constructors can lead to memory leaks or partially-constructed objects, then why we don't make them atomic? so neither an object nor it's local variables will get created/...
1
vote
1answer
52 views

Wrapping methods without Decorator Pattern or AOP

I have a Dao interface which doesn't have any methods defined. Then I have multiple classes which implement this interface, like PetDao and HouseDao. For some of the implementation classes, and some ...
-1
votes
1answer
81 views

Locking a DB table and waiting for writing/reading it from a web application

I'm working on a web application using Spring (Java and JPA + Hibernate) and I was wondering if there is a way of locking a MYSQL table and then when another web service (or even another thread from ...
0
votes
0answers
31 views

Architecture with a login

I am on my first big solo task and I am required to create an application that allows companies to work with permits, fill them out, get them signed etc. This web-app is with invite only i.e. it is ...
0
votes
2answers
95 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 ...
6
votes
1answer
257 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; ...
0
votes
0answers
39 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 ...
2
votes
1answer
154 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 ...
0
votes
3answers
114 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, ...
1
vote
1answer
148 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 ...
8
votes
5answers
2k 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 ...
2
votes
2answers
112 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&...
0
votes
0answers
47 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 ...
2
votes
5answers
348 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), ...
0
votes
3answers
176 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 ...
6
votes
1answer
161 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
49 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
38 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
128 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
130 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
115 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
57 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
91 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
152 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 ...

1
2 3 4 5
96