All Questions
Tagged with java programming-practices
135 questions
0
votes
1
answer
239
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 ...
2
votes
4
answers
3k
views
I wrote a class with "init" method. Should I call it from other class methods? Or leave it to the object user? (Code Design)
I have a java class with an init method. It's different from the constructor. The constructor just initializes the variables/fields. The init method connects to a database and performs some ...
1
vote
4
answers
341
views
Storing both a compiled service for a Docker container as well as the container in a repository. Good practice, bad practice or no precedent?
This has erupted from quite a turbulent meeting between two senior developers, a lead developer and an engineering lead, and after 90mins reached no resolution.
We create Spring Boot Java services ...
-1
votes
1
answer
16k
views
@Getter, @Setter vs @Data in lombok? [closed]
So I was sending code for review and approvals for some changes I made recently. that includes a class as below:
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class ...
2
votes
1
answer
1k
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.
...
-1
votes
2
answers
262
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 ...
3
votes
4
answers
780
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 = ...;
...
9
votes
2
answers
1k
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 ...
1
vote
2
answers
497
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 ...
3
votes
2
answers
207
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 ...
4
votes
3
answers
1k
views
Passing object or using the field
I would like to know what is a more appropriate way to code in Java. Is it generally better to pass entire objects in the method's parameters or just using the fields from the class?
Using the field:
...
-3
votes
1
answer
269
views
Is it good practice to use try/catch like Python in Java?
I mainly use Python and just started learning Java. For now, I've tried using try/catch for basic file read/write as follows
public String[] readFile(String fileName){
try{
// read file
} ...
0
votes
3
answers
202
views
When using a DSL to structure my application, should I favor coupling the code with the DSL, or trying to have majority of my code independent of it?
We're currently using the Apache Camel Java DSL to structure our application, but I guess this question can mostly apply to any DSL in general.
Now, amongst our developers, we are divided on two polar ...
2
votes
4
answers
2k
views
Separating data and behavior in Java
I am in the process of refining my code to adhere more to my current understanding of the Single Responsibility Principle (SRP). Originally, I had a class called Animal that had a set of methods and ...
2
votes
3
answers
1k
views
When is it appropriate to reuse a method for another method?
I am writing a program that describes different properties on a single Management Company's plot of land. For this program there are 3 overloaded addProperty method's. My question is I can reuse the ...