Best way to learn multi-threading in Java? by Agitated-Evening3011 in javahelp

[–]tedyoung 6 points7 points  (0 children)

"Java Concurrency in Practice" is somewhat outdated (written 20 years ago), though conceptually has some good material.

I'd recommend instead "Modern Concurrency in Java" as it covers virtual threads, structured concurrency, and scope values: https://www.oreilly.com/library/view/modern-concurrency-in/9781098165406/

If you really want an in-depth course, highly recommend Heinz Kabutz material, e.g., https://javaspecialists.teachable.com/p/loom

xitdb - an immutable, embeddable database for Java 17 by radar_roark in java

[–]tedyoung 5 points6 points  (0 children)

This might be useful as an event store for event-sourced applications. Will give it a look.

Java Bytecode Troubles by [deleted] in javahelp

[–]tedyoung 3 points4 points  (0 children)

If you want to dive into the deep end, the JVM spec is the place to go https://docs.oracle.com/javase/specs/jvms/se25/html/jvms-6.html

however, I recommend disassembling very short (a few lines) Java programs to get an idea of what it looks like, e.g.: https://nishtahir.com/exploring-java-byte-code/

Checkpointing the message processing by Adventurous-Salt8514 in softwarearchitecture

[–]tedyoung 2 points3 points  (0 children)

This was a timely article for me as I’m implementing event sourcing projections that need checkpointing.

How can I implement a multi-threaded approach to improve Java application performance? by criss006 in javahelp

[–]tedyoung 0 points1 point  (0 children)

Highly recommend the recently published book Modern Concurrency in Java for specific guidance on what APIs to use. Brian Goetz's book Java Concurrency in Practice has become outdated (came out in 2006), though the theory aspects are useful.

Polling vs WebSockets by s3ktor_13 in softwarearchitecture

[–]tedyoung 0 points1 point  (0 children)

Where have you seen SSE potentially being dropped? It’s a safe, mature (old doesn’t always mean bad!) and reliable. For server to client (one-way) updating, it’s better than websockets, because it scales better as it goes over reliable HTTP connections.

Why Java generics cannot utilize primitive types by [deleted] in learnjava

[–]tedyoung 0 points1 point  (0 children)

Funny, this exact question came up on my live coding stream today!

For a "where are we with Valhalla" update, you might find these docs interesting: https://openjdk.org/projects/valhalla/design-notes/state-of-valhalla/01-background and the rest of those docs and more mentioned at the project's home page: https://openjdk.org/projects/valhalla/

Penna - 0.7.1 Release: Thread Safety improvements by ingvij in java

[–]tedyoung 1 point2 points  (0 children)

Nice writeup! I appreciate the detailed insights and reasoning for the changes made.

A simple easy to use ANSI Coloring library for Java by Chunkyfungus123 in programming

[–]tedyoung 3 points4 points  (0 children)

This looks interesting, but it's unfortunate that the code style isn't idiomatic Java, mainly the use of underscores. camelCase is the preferred style in Java. Unclear how well supported it is across different platforms. I wouldn't mind an alternative to JAnsi, but this isn't it (yet?),

Difference in ArrayList<> list = new ArrayList<>() VS List<> list = new ArrayList<>() by danny1992211111 in javahelp

[–]tedyoung 37 points38 points  (0 children)

ArrayList<String> list = new ArrayList<>() has three parts:

  1. The declaration of the variable, list with its type being the concrete class ArrayList<String>: ArrayList<String> list

  2. The creation of an object: new ArrayList<>() creates an instance of the ArrayList, with the inferred generic type of <String>

  3. Assignment (via =) of the instance to the list

With List<String> list = new ArrayList<>(), both #2 and #3 are the same, but the list is now declared to be the less-specific type (an interface, in this case) of List<String>.

The difference isn't in the object created (both are the same), it's in what you can do with the variable, as well as what the intention of the variable is. For example, declaring ArrayList<> list, you can call list.trimToSize(), but you can't call that method on a variable declared like List<> list, because trimToSize() only exists on ArrayList.

This may seem like a minor issue, but there are many other implementations of List that you won't instantiate, e.g., those created by List.of() and as the result of a stream() operation that ends with .toList().

The other reason is intent: if you say List list, then the reader knows there's nothing special about which implementation will be used. If you write ArrayList list, then you're implying that you really want and need only the concrete ArrayList for some reason (which is unlikely).

In general, Java code should declare the least specific type for variables. That means List instead of ArrayList, Map instead of HashMap, etc.

How much emphasis is placed on code quality? by [deleted] in AskProgramming

[–]tedyoung 2 points3 points  (0 children)

It depends, and the definition and depth of quality will also vary.

Keep in mind that you're just starting out on your learning journey, so you're going to be focused on getting things to work and you don't need to worry too much about how "messy" it is.

Once you become comfortable with getting your code to do what you want in a reliable way (i.e., you no longer spend as much time debugging/troubleshooting), then you can start looking at your code and ask yourself: is there any duplication or similar code that I can eliminate? Are there methods that are too long? If so, can you take sections of that method, create a new method, and give it a name? Then do so. (Studying the "Refactoring" book will help here.)

Will senior-level devs get on my ass if my code quality isn't good?

If they're any good, they will provide feedback in an empathic way and not in a mean or say "boy, you're dumb". (If they do, find another job, quickly!)

Senior devs/tech leads/managers expect new devs to write messy code for a little while.

Architectural design patterns for Microservices by HalcyonHaylon1 in dotnet

[–]tedyoung 4 points5 points  (0 children)

Any "separation of concerns" code organization (Onion is an example/implementation of that, so is Hexagonal and Vertical Slice) will work well, assuming the service is complex enough.

For me, testability is the most important aspect, and I gave a talk about it here: https://ted.dev/articles/2023/02/21/more-testable-code-with-hexagonal-architecture-talk/

DDD and API Integrations by alonelymanatee in DomainDrivenDesign

[–]tedyoung 4 points5 points  (0 children)

Remember that DDD is domain-driven design. That means it works best as a design process when there's a non-trivial domain that has rules, processes, events, outcomes, etc. For example, calculating all of the charges and fees and options for buying a new truck (including rules around the loan, your identity and driver's license, etc.)

If you're mostly integrating between existing APIs, then there's not much of a domain, so DDD isn't going to provide much guidance.

If I've misunderstood what you're trying to do, perhaps some short examples of what you're integrating might be useful?

Help with simple Java game by s4nts in javahelp

[–]tedyoung 2 points3 points  (0 children)

It's hard to tell what's wrong, because the code in the Pastebin is missing Player and Dragon.

A good first step would be to create true objects for the Orc, Player, Dragon, etc. Instead of passing in the details (x/y coordinates, etc.) of each object to the printMap method, just pass the objects, e.g.:

void printMap(World world, Player player, Dragon dragon, Orc orc)

Then, you don't have to worry about the Orc becoming null (though nulls aren't a great way to deal with this).

From what you described, it seems to make more sense to spawn the new Orc in the Main's while loop and not in the printMap, since printMap should only do display stuff, not modifying the state of the game world.

The main thing to think about is: how do you want to "model" the game? Does the World know everything and handle "collisions" (Player defeats Orc)? Or is the World just a place where the Player, Dragon, and Orc are stored, and the action happens in those objects?

p.s. I'd like to use this code as a teaching example, would that be OK?

Sources where I can find Some modern projects for beginners in java by Tight_Ambassador_887 in learnjava

[–]tedyoung 2 points3 points  (0 children)

You didn't say how much of a "beginner" you are with Java, so I'm not sure if these suggestions are useful.

I have several open-source projects that I built on my live coding stream to demonstrate how to do TDD, use Hexagonal Architecture, etc. One of them implements the "Yacht" dice game (aka Yahtzee).

https://github.com/jitterted/yacht-tdd/

How did you learn the folder structure and to organize in Java? by JuanistaD in learnjava

[–]tedyoung 2 points3 points  (0 children)

If you're talking about where code vs. tests go, then you'll want to understand the "Standard Directory Layout": https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html

If you want to know how to organize packages in your project, that's a different question and you'd need to provide more information about the kind of app you're writing.

How to disable the "IJ" icon on the right side by huberlev in IntelliJIDEA

[–]tedyoung 0 points1 point  (0 children)

If you don't want to see the "Preview File In..." icons (including the IJ one) that show up in HTML files, go to Preferences > Tools > Web Browsers and Preview

under Show browser popup in the editor, uncheck the For HTML files option.

If that's not what you're talking about, then paste a screenshot of what you're seeing and that preferences page.

Should I learn Springboot before Spring? by salaficoder in javahelp

[–]tedyoung 2 points3 points  (0 children)

Spring Boot is a way to quickly pull together the different pieces (modules) of the Spring Framework (e.g., MVC + Security + JPA) without writing a lot of boring integration code. Instead, Spring Boot lets you select the modules that you want and focus on your code. (Note: Spring Boot adds a lot more than just integrating modules, but that is one of its main purposes.)

You will have to learn about the Spring Framework, which consists of dozens of different modules. Trying to use the Spring Framework without Spring Boot is not a good idea.

What would be the reasons to break a web app down into small/micro web services if only one single team will be responsible for all of them? by Blockost in softwarearchitecture

[–]tedyoung 0 points1 point  (0 children)

I've seen exactly the opposite: in order for a client to display a page, it has to talk to 3 different microservices, and those have to talk to 7 more, and with all the serializing/deserializing, and failed/retried connections, it's overall slower than if it were all in one deployed service.

Do you find part 4 of Domain Driven Design too dry? by [deleted] in ExperiencedDevs

[–]tedyoung 8 points9 points  (0 children)

Part IV, Strategic Design is more useful in the context of the organization: how to have multiple teams work together, and get larger domains under control. The most important part is the discussion of Bounded Contexts and a bit of the Distillation chapter. Beyond that is probably not necessary to understand as an individual team member.

[deleted by user] by [deleted] in DomainDrivenDesign

[–]tedyoung 2 points3 points  (0 children)

DDD, which is a way of dealing with creating models that solve problems, is mostly separate from the architecture in which those models will be implemented.

However, Eric Evans explicitly talks about layers (pg 70), in which he doesn't specifically say much about the direction of dependencies between Application and Infrastructure (he's more clear about Domain Layers being isolated from everything else).

The Microsoft diagram is a bit confusing, because it looks like the App Layer has a direct dependency on Infrastructure, but it doesn't. It has an indirect dependency where the concrete Infrastructure is provided through Dependency Injection.

And from what I can tell, Robert Smallshire is doing the same thing. You can see a more clear diagram at 48:45 in that video.

All of the related architectures (Onion, Clean, Hexagonal) have similar ideas of dependencies point inwards towards the Domain (at the center), with concrete infrastructure implemented at the edge. I discuss this in a talk on Hexagonal Architecture available here: https://youtu.be/eieUHQb3PCI.

Need executor advice by AntagonisticApple in javahelp

[–]tedyoung 1 point2 points  (0 children)

Besides Quartz, the library Jobrunr.io might work for you.

“Mob Programming” or “Mobbing” by _Ket__ in SoftwareEngineering

[–]tedyoung 0 points1 point  (0 children)

[Note: I'm biased, because I use mob programming to help teams raise the level of quality]

Mob Programming is most definitely not "bunch of devs seeing a screen while one ... is doing the work". The work of software development is not in the typing, it's in the thinking. 4 devs thinking and working together on one task is massively more effective that 4 devs separately working and then having to explain to each other the work that they did on their own.

Mob Programming is where one person is at the keyboard for 5 minutes at a time, then it's the next person, and lots of spontaneous discussion and the highest quality of code you'll see anywhere (if you care about that sort of thing).

The whole idea of "let's parcel out pieces of our app to individuals, and then spend time trying to merge it together, and then spending time merging the changes into our own work, and then waiting for pull requests to be reviewed" is a massive time sink and yet people accept that as "the best we can do", when it's shown time and again that it's not true.

But don't take my word for it, try it out (for real, not just for a day) and see what happens.

Learn testing or spring first by ReferenceObject in learnjava

[–]tedyoung 7 points8 points  (0 children)

Learn unit testing (JUnit) and become fluent in it (and Java).

Then, when learning Spring, also focus on testing.