Skip to main content

All Questions

276 votes
14 answers
125k views

Should we avoid object creation in Java?

I was told by a colleague that in Java object creation is the most expensive operation you could perform. So I can only conclude to create as few objects as possible. This seems somewhat to defeat ...
Slamice's user avatar
  • 2,657
296 votes
16 answers
30k views

Grokking Java culture - why are things so heavy? What does it optimize for? [closed]

I used to code in Python a lot. Now, for work reasons, I code in Java. The projects I do are rather small, and possibly Python would work better, but there are valid non-engineering reasons to use ...
Mikhail Ramendik's user avatar
283 votes
6 answers
168k views

Choosing between Single or multiple projects in a git repository?

In a git environment, where we have modularized most projects, we're facing the one project per repository or multiple projects per repository design issue. Let's consider a modularized project: ...
Johan Sjöberg's user avatar
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 ...
Rui's user avatar
  • 1,925
84 votes
8 answers
73k views

Is modifying an incoming parameter an antipattern? [closed]

I am programming in Java, and I always make converters sort of like this: public OtherObject MyObject2OtherObject(MyObject mo){ ... Do the conversion return otherObject; } At the new ...
CsBalazsHungary's user avatar
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 ...
joker's user avatar
  • 131
45 votes
6 answers
14k views

Is it better to check `c >= '0'` or `c >= 48`?

After a discussion with some my colleagues, I've a 'philosophical' question about how treat the char data type in Java, following the best practices. Suppose a simple scenario (obviously this is only ...
wyr0's user avatar
  • 585
87 votes
10 answers
111k views

How many lines per class is too many in Java? [closed]

In your experience, what is a useful rule of thumb for how many lines of code are too many for one class in Java? To be clear, I know that number of lines is not even close to the real standard to ...
Michael McGowan's user avatar
36 votes
9 answers
15k views

Why do schools teach arrays over List? [closed]

Most of the assignments in my school for the initial programming classes required me to use arrays. I work full time now, and I never used an array for any project that I have worked on. Even in the ...
Howls Hagrid's user avatar
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 ...
Bar Akiva's user avatar
  • 217
-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 ...
Brooklynn99's user avatar
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 ...
Crazy Dino's user avatar
46 votes
6 answers
7k views

How necessary is it to follow defensive programming practices for code that will never be made publicly available?

I'm writing a Java implementation of a card game, so I created a special type of Collection I'm calling a Zone. All modification methods of Java's Collection are unsupported, but there's a method in ...
codebreaker's user avatar
  • 1,754
49 votes
7 answers
48k views

Is it a bad practice to have an interface to define constants?

I am writing a set of junit test classes in Java. There are several constants, for example strings that I will need in different test classes. I am thinking about an interface that defines them and ...
FabianB's user avatar
  • 932
8 votes
6 answers
5k views

What is more important? SOLID or KISS?

What is more important? SOLID or KISS? To be consistent with SOLID I would have to inject Decorator and Footer classes and create interfaces for them. public class HelloService { String name; ...
cimlihor's user avatar

15 30 50 per page
1
2 3 4 5
9