Skip to main content

All Questions

296votes
16answers
30kviews

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
283votes
6answers
168kviews

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
276votes
14answers
125kviews

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
87votes
10answers
111kviews

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
84votes
8answers
73kviews

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
59votes
9answers
49kviews

Should the methods of a class call its own getters and setters?

Where I work I see lots of classes that do things like this: public class ClassThatCallsItsOwnGettersAndSetters { private String field; public String getField() { return field; }...
Daniel Kaplan's user avatar
56votes
3answers
74kviews

Which is a better practice - helper methods as instance or static?

This question is subjective but I was just curious how most programmers approach this. The sample below is in pseudo-C# but this should apply to Java, C++, and other OOP languages as well. Anyway, ...
Ilian's user avatar
49votes
7answers
48kviews

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
46votes
6answers
7kviews

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
45votes
6answers
14kviews

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
38votes
5answers
9kviews

When should I extend a Java Swing class?

My current understanding of Inheritance implementation is that one should only extend a class if an IS-A relation is present. If the parent class can further have more specific child types with ...
Paras's user avatar
36votes
9answers
15kviews

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
34votes
8answers
15kviews

Is throwing an exception an anti-pattern here?

I just had a discussion over a design choice after a code review. I wonder what your opinions are. There's this Preferences class, which is a bucket for key-value pairs. Null values are legal (that'...
Konrad Morawski's user avatar
33votes
6answers
13kviews

Is throwing new RuntimeExceptions in unreachable code a bad style?

I was assigned to maintain an application written some time ago by more skilled developers. I came across this piece of code: public Configuration retrieveUserMailConfiguration(Long id) throws ...
Sok Pomaranczowy's user avatar
27votes
6answers
34kviews

Is it a bad habit to (over)use reflection?

Is it a good practice to use reflection if greatly reduces the quantity of boilerplate code? Basically there is a trade-off between performance and maybe readability on one side and abstraction/...
Random42's user avatar

153050per page
close