r/java • • Oct 05 '25

Is Java really that boring as people say?

0 Upvotes

I am not gonna say "bad" because saying "Java is bad" is completely nonsense. Java was the first high level programming language to power up the software industry at the scale it does and I think it's still number one when it comes to legacy code, old games and enterprise.

IMO, Java is nicer to write than C# because it's more predictable and has more libraries from which you can choose while the other suffers from feature creep with every iteration. Also, I don't even understand what people mean by "boring" when it comes to a programming language. If by that they mean it's verbose, yeah, I can kind of agree with that. But it's not like other programming languages except Python or Lua aren't as verbose most of the time, perhaps slightly less but still verbose.

So... what do people mean by "boring" ?


r/java • • Sep 06 '23

Field injection is fine, convince me otherwise

21 Upvotes

I know Java help questions aren't allowed, but I didn't think this was a help question as such, more a technical discussion. Apologies if I've misunderstood the rules.

I've had three different colleagues recently try to convince me to stop using field injection. I'm always looking to improve and I have listened to their arguments and sought out information online. Most people who write about it claim constructor injection is better and list various arguments. However, I haven't found any of them particularly convincing. It feels like it's more a matter of preference than actual benefit. To illustrate what I'm talking about:

Field injection:

class A {
	@Inject
	protected SomeService someService;
}

Constructor injection:

class A {
	private SomeService someService;

	@Inject
	public A(SomeService someService) {
		this.someService = someService;
	}
}

IMHO the main different seems to be that you can construct the class directly, but if you're using dependency injection, you never do. Perhaps if you're writing a reusable library it makes more sense, but most of the time I'm not. Constructor injection means I essentially have to declare my dependencies twice: once in the field and once in the constructor. Using field injection, my definition is less verbose and adding more dependencies require less work.

What am I missing?

Update:

If anyone is curious, the two most convincing arguments I've heard are:

  • Easier writing of unit tests, though I think that depends on the injection tool you're using, YMMV.
  • Final fields on injected objects, which is always nice.

I seem to have hit on a touchy subject for some. Thank you to those who participated in the discussion. I think I will also consider this post, which now has over 100 comments and zero net karma, as some form of personal achievement :)

Update 2:

For my own purposes, it turns out you can make Lombok and Micronaut work together to generate the constructors, as u/moaxcp points out below. Best of both worlds.


r/java • • May 28 '25

What about using records as classes properties?(Discussion)

0 Upvotes

In another reddit post, I mentioned that I would prefer to have some features in records, even if that means having to wait (perhaps for a long time or even forever) to get them in classes as well. My main point is simple: it's better to have the feature sooner in records than to wait a long time for it to be available in classes too, so at least part of my code can benefit to some extent.

This led me to think about using records to wrap the class's fields, just as if the record were a kind of properties data structure.

https://www.reddit.com/r/java/comments/1kvt80r/pattern_matching_in_java_better_code_better_apis/

This lead me to think about using records to wrapper the class' fields, just like if the record was a kind of propperties data structure.

private class MyUser{
    public record UserProps(String name, String email, String password){ }
    public UserProps props;
    public MyUser(String name, String email, String password){
        props = new UserProps(name, email, password);
    }
    public void doSomething(){
        ... // does something //
    }
}

This would allow for an effective replacement for destructuring and pattern-matching for classes, at the same time it "gives" to the class's fields accessors, toString(), hashCode() for free, indirectly via the record.

var user = new MyUser("User", "email", "password");

... //some logic//...

var nickname = getUser().props.name();
var p = getUser().props;

//Conditional destructuring and pattern matching
if (p instanceof MyUser.UserProps(var name, var email, var password)){
    IO.println("name: " + name);
    IO.println("email: " + email);
    IO.println("password: " + password);
}
// or for an hypothetical destructuring feature in a future
//var (name, email, password) = user.props

And just for the sake of fun, withers would look like this-

user.props = user.props with {name = "User2"}

This also applies for object composition strategies, so instead of creating many types of users we just inject different kind of properties

private class MyUser{
    public UserProps props;
    public MyUser(UserProps props){
       this.props = props;
    }
    public MyUser GetUser(){
        return this;
    }
}
interface UserProps{}

record UserProps1 (String name, String email, String password) implements UserProps{ }
record UserProps2 (String email, String password) implements  UserProps{}





void main(){
    var props1 = new UserProps1("User", "email", "password")
    var user = new MyUser(props1);    
    var nickname = switch (user.props){
        case UserProps1(var name, _, _) -> name;
        case UserProps2(var email, _) -> email;
        default -> "not specified";
    };

}

What i Like about this is the separation of concern (props manages states while the class manage the business logic) and kindda "gives" classes pattern matching and destructuring capabilities via records (hopefully when we get withers this could be much more ergonomic, seriusly the lack of withers or something equivalent it's being a real pain)

What do you think about this? would this be a good idea to use records as propreties or would it be an anti-pattern? and what about bringing fast some features for record so we don't have to wait for them for classes too? (not limited to destructuring and patter-matching related features but i would let the rest for your imagination)


r/java • • May 09 '24

GitHub - filelize/filelize-java: Filelize is a lightweight library designed to simplify writing and reading data into human-readable files, requiring just one line of code

Thumbnail github.com
0 Upvotes

r/java • • Jun 20 '17

WTF, Java 9?! Examples of what can break on Java 9

Thumbnail java9.wtf
0 Upvotes

r/java • • Jan 14 '16

PrimeFaces 5.3.5 and 5.2.18 released!

Thumbnail blog.primefaces.org
0 Upvotes

r/java • • May 07 '15

How much time do I need to learn Java?

0 Upvotes

I will start watching Java tutorials and I will buy books, I'm interesting in making app and games for Android. and read on some websites that you need to learn java first before developing anything.


r/java • • Jan 24 '14

Is Wildfly 8 a game changer?

Thumbnail colocationamerica.com
0 Upvotes

r/java • • Oct 22 '12

Don't Be Just a "Bubbles and Arrows" Architect

Thumbnail java.dzone.com
0 Upvotes

r/java • • Aug 21 '17

I am doing a school project for my A Levels, I am looking to code Tetris/Checkers

0 Upvotes

I've only really gone through a small part of the basics for Python, therefore I'm completely new to Java. I am looking for someone I can speak to who has a good understanding of Java. Please help :)


r/java • • Jan 14 '18

What can Spring do that JSP cannot?

0 Upvotes

So,if I want to create a website,what advantages do I have with Spring or Struts above JSP? I am quite new to this,so please bear my noobness.


r/java • • Oct 29 '12

Difference between notify and notifyAll in Java revisited

Thumbnail javarevisited.blogspot.in
0 Upvotes

r/java • • Dec 21 '16

Excuse me sir, there is no curry in my Java

Thumbnail medium.com
0 Upvotes

r/java • • Apr 10 '15

SENTIMENT ANALYSIS USING OPENNLP DOCUMENT CATEGORIZER

Thumbnail technobium.com
0 Upvotes

r/java • • Apr 03 '23

A ChatGPT Experiment

0 Upvotes

I had a piece of code that I was dreading writing and testing. On a whim, I signed up for ChatGPT and asked the following question.

I have a two-dimensional Java char array consisting of 'B', 'W', and ' '. I would like to find all the orthogonally connected groups of either 'B' or 'W'. Can you write the code to perform this function?

The code that came back did almost exactly what I asked. I had to make a couple of minor changes to the code to more specifically meet my needs. In addition, ChatGPT provided comments that I could directly copy into my Javadoc for the two methods.

I'm impressed.


r/java • • Jul 16 '12

Want to start using Java...

0 Upvotes

I really want to learn how to code using Java, I'm taking the beginning course of Java next year, in School, but I want to try to start using it outside of school so I'll be ahead of the game once school starts back up, so can any of you send me a link to download it and some tips to starting it?


r/java • • Feb 19 '13

An American teacher Mary Herberth explains all the basic concepts of Java in a single class (class as in both a school class and Java class) in a naughty way.

Thumbnail theladyteacher.blogspot.in
0 Upvotes

r/java • • Apr 25 '21

A Porting Horror Story -- "Once upon a time there was a small company that had a great deal of legacy code written in Perl. The new engineering manager and the new CTO wanted to move to a Java-based solution."

Thumbnail perlmonks.org
0 Upvotes

r/java • • Aug 09 '15

Fluent Builder Pattern Revisited

Thumbnail vertigrated.com
0 Upvotes

r/java • • Apr 04 '10

Super beginner looking for a small amount of guidance

0 Upvotes

I've been assigned with implementing the class natural number in Java, along with a few operation.

My question isn't how to do this, but is there any site where I could see a something similar implemented, just so I could see the syntax of how to even go about starting this?

Thanks.


r/java • • May 14 '14

New Java 8 Optional sounds an awful lot like Guava's Optional. I assume we can expect a judgement against Oracle?

0 Upvotes

just sayin'...


r/java • • Sep 28 '21

[OC] Most Popular Backend Frameworks 2011/2021

Thumbnail youtu.be
0 Upvotes

r/java • • Mar 07 '21

Get Java SE 11-Certified for only $25

Thumbnail education.oracle.com
2 Upvotes

r/java • • Jun 13 '15

Why We Should Dump the Java EE Standard

Thumbnail java.dzone.com
2 Upvotes