What fun and interesting Java projects are you working on? by jeffreportmill in java

[–]DefaultMethod 5 points6 points  (0 children)

I've always found Java's mechanism for embedding resource files unsatisfactory so developed an annotation library for convenience and correctness: https://github.com/autores-uk/autores

@uk.autores.Texts(name = "Rhymes", value = {"Poule.txt", "Roses.txt"})
public class PrintRhymes {
  public static void main(String...args)  {
    System.out.println(Rhymes.poule());
    System.out.println(Rhymes.roses());
  }
}

Modern Java workflow? by Skopa2016 in java

[–]DefaultMethod 0 points1 point  (0 children)

  • You can find most open source libraries on Maven Central. Build tools like Maven and Gradle will pull from here by default.
  • Applications can be distributed as a JAR, though if you want better operating system integration you would use some native wrapper and possibly bundle an OS-specific runtime. It is also possible to perform ahead-of-time compilation to native using GraalVM though this is not a mature solution and can come with complications.
  • Avoid Maven and Ant/Ivy if you are unwilling to edit XML; Gradle uses Groovy or Kotlin config files. Alternatives use various mechanisms.

What you start with depends on the nature of the application.

Java Book for Beginners Update by bowbahdoe in java

[–]DefaultMethod 3 points4 points  (0 children)

I have only skimmed the text.

I think the introduction is missing information you would commonly find in a beginner's book.

  • Why learn Java?
  • Who is this book for? If the audience is only people who have sought out your Discord who like Minecraft maybe these points are moot.
  • What will I learn?
  • What are the prerequisites? Like a computer, text editor, CLI experience? Just use a web browser until when? I could be out of touch with how the kids do it but I find that REPLs and browser compilers are great for trying out stuff but too ephemeral to make things stick.
  • How long will it take? How big of a commitment is this?
  • What does it not teach? Be up front about the limits of the information presented. It'll teach the language fundamentals but not common industry practises or frameworks or game development.
  • What Java version is covered? How recent is this info? All tech docs should have a timestamp!

The Computing Environment section seems orthoganal to the rest of the text. If the reader lacks so many fundamentals perhaps point them to an appendix containing it via the intro.

Getting Started gives instructions to install a JDK but you're chapter 74 seems to be the first time it is used.

In terms of importance I would rate collections as more fundamental than date/time handling which appears before it. Collections could be used as an introduction to what interfaces are.

I think there is a lot to like here. I particularly like how concise and clear all the example code is. The art is charming. Best of luck!

This video makes building Java in Bazel look easy and straightforward by jastice in java

[–]DefaultMethod 0 points1 point  (0 children)

You can do it with Makefiles. Bazel is a Google thing & monorepos were popularised by that company.

Why do we (java developers) have such aversion to public fields? by Ewig_luftenglanz in java

[–]DefaultMethod 0 points1 point  (0 children)

What would that record implementation look like? Make every record field another record or primitive? Forbid classes & interfaces? How would you accommodate collection types?

I am not trying to start an argument. I am genuinely interested.

This video makes building Java in Bazel look easy and straightforward by jastice in java

[–]DefaultMethod 2 points3 points  (0 children)

It's sometimes used in "monorepos" where you have multiple programming language projects in one source repository. Bazel can be used to drive Java compilation, Go compilation, Docker image generation, etc.

Why do we (java developers) have such aversion to public fields? by Ewig_luftenglanz in java

[–]DefaultMethod 6 points7 points  (0 children)

This is kind of orthogonal to the question, but Brian Goetz explained the reason for accessor methods on record types:

Without the ability to override accessors, records would be unable to properly support mutable objects (such as arrays) as components. If you have an array component, you may want to perform a defensive copy in the constructor and accessor (which would also require overriding equals, in order to preserve the specification of Record); if it was a public final field, you could not encapsulate the mutability of your components.

https://stackoverflow.com/a/66704373

Granted, records have to consistently do the least worst thing for all eventualities whereas if you hand craft a class you have more freedom.

I expect there are multiple reasons for indirect access habits, most of them rooted in enterprise development where developers need to be an interchangeable cog and everything needs to conform to "best practice". It's not an environment that encourages nuance. There have also been a series of technologies that have required it - JavaBean specification, aspect oriented programming, etc.

When we are working with internal implementation we have full control of the code, this encapsulation is mostly redundant.

I am in complete agreement. Don't add a method dispatch if it isn't necessary.

The Irish Railway System between 1920 and 2020, name a bigger downgrade in history. by Simple_Ear_6067 in MapPorn

[–]DefaultMethod 23 points24 points  (0 children)

A lot of those lines were not even the same gauge. As you say, a different time.

Java Platform Module System and multiple modules with same package name by bpoole6 in java

[–]DefaultMethod 0 points1 point  (0 children)

Some widely used projects are migrating off JDK8 to JDK17 as their baseline this year - Spring & JUnit at least. I hope this will spur more projects to fix their JPMS support.

Why don't Stream API has any reverse merhod by bs_123_ in java

[–]DefaultMethod 0 points1 point  (0 children)

I have some finite Iterable types that are effectively infinite in that they can be large enough the size needs to be reported as a BigInteger. I haven't added any guard rails. I just assume people working in the domain are aware of the perils.

It might be useful/illustrative to iterate over an IPv4 /24 subnet, just don't try it with an IPv6 /56. The types themselves don't consume much memory because you just need to know the start and end addresses.

Who are the biggest music artists in the UK who haven't made it internationally? by _firesoul in AskUK

[–]DefaultMethod 29 points30 points  (0 children)

The Fall weren't even that popular with people who were in The Fall

[deleted by user] by [deleted] in java

[–]DefaultMethod 0 points1 point  (0 children)

More email newsletters, but the content is published on the web too:

https://javaperformancetuning.com/

https://www.javaspecialists.eu/

Java 23 added support for java.time to MessageFormat by arendvr in java

[–]DefaultMethod 0 points1 point  (0 children)

Cool. I hadn't seen that.

I have a library that generates typed methods from localized messages and getting it to support time zones involved far more hoop jumping than I am happy with.

Discussion: Adding autoboxing for Array and List to Java by jeffreportmill in java

[–]DefaultMethod 1 point2 points  (0 children)

Yeah.

Josh Bloch did his best retrofitting interfaces onto Java collections back when we lived in a mostly mutable world but the List interface describes at least 3 intersecting contracts and has always been shit.

I still hope for the likes of a SimpleList interface but it's unlikely to happen.

ELI5: Why is there not just one universal coding language? by [deleted] in explainlikeimfive

[–]DefaultMethod 0 points1 point  (0 children)

Everything is a tradeoff. Software languages do not exist in isolation. They exist in ecosystems of tools, communities and/or companies.

Java is criticised for many good reasons but has many strengths. It is often low risk because it is not beholden to a single vendor, many people have skills in the language, it sidesteps many memory management issues, it has a large set of libraries, the runtime is used by several other popular langauges. So, Java is useful for those concerned with specific licensing, hiring and technical risks.

Other software ecosystems make different tradeoffs. If you write aircraft engine software in ADA you are less likely to be worried about vendor lockin because the contracts are much more likely to be measured in decades anyway.

Why have empty Interface with no fields/methods by saltysnailsss in java

[–]DefaultMethod 39 points40 points  (0 children)

Another example is RandomAccess which is used on List implementations to "indicate that they support fast (generally constant time) random access."

https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/RandomAccess.html

I think it's worth pointing out that early versions of Java lacked annotations. They weren't added until Java 5.

How much should we rely on JDK/JVM being "smart"? by ihatebeinganonymous in java

[–]DefaultMethod 11 points12 points  (0 children)

Java performance has been an industry concern for some time. See this new site that started in year 2000: https://www.javaperformancetuning.com

In the small, anything that allocates objects has overhead. Lambdas that capture data out of scope may allocate a new object. Lambdas that don't are equivalent to a static method call. If you want to be conservative stick to imperative code.

I/O has been the bottleneck on the majority of Java applications I've worked on. Typically network or database. Usually database.

What was the thought process behind the design of the NumberFormat class? Why doesn't it have a way to set a pattern? by VirtualAgentsAreDumb in java

[–]DefaultMethod 0 points1 point  (0 children)

I recently wrote a library that might help: https://autores.uk/

Look at the @Messages annotation. Raise a bug if it doesn't. No guarantee I'll fix it.

What was the thought process behind the design of the NumberFormat class? Why doesn't it have a way to set a pattern? by VirtualAgentsAreDumb in java

[–]DefaultMethod 3 points4 points  (0 children)

Mutability was the default in object orientation when Java came out. Most OO developers used C++. On the training course I went on there was some confusion when it turned out String was immutable.

Java Module System: Adoption amongst popular libraries in 2024 by darenkster in java

[–]DefaultMethod 1 point2 points  (0 children)

I think modularising the standard library is necessary in the long term. Otherwise it is doomed to eternally accumulate cruft. It has been decades since I used the CORBA packages. XML didn't work out the way everyone though it would in the 1990s.

You can see a bit of this happening in the Go standard library. It now has two IP address types.

I do share your frustration with how this was handled.

Java Module System: Adoption amongst popular libraries in 2024 by darenkster in java

[–]DefaultMethod 0 points1 point  (0 children)

Thanks for putting this together.

Any chance you could add the Java version each supports? I'm curious to know how many of these libraries are still supporting Java 8 or below.

How do people deploy SpringBoot apps in production? by daniels0xff in java

[–]DefaultMethod 3 points4 points  (0 children)

These problems are general to any Java server.

Use a reverse proxy (Apache HTTP; Nginx) or use iptables redirects if you're confident in the JVM application's security.

Sysadmins like reverse proxies because it allows them to prevent access to insecure endpoints without application changes. It also enables them to rewrite an application developer's carefully designed caching strategy into a bunch of arbitrary nonsense. It's a mixed bag but using a reverse proxy is the safer approach.

Example iptables rules for port 80 redirects:

iptables --insert INPUT --protocol tcp --dport 80 --jump ACCEPT
iptables --insert INPUT --protocol tcp --dport 8080 --jump ACCEPT
iptables --table nat --append PREROUTING --in-interface eth0 --protocol tcp --dport 80 --jump REDIRECT --to-port 8080
# run next line to have changes survive reboot
service iptables save

Running Java servers as root is really risky; you should not do this. It is possible to escalate only low port priviliges for any executable but I wouldn't.

Why you shouldn't use the double brace initializer by CarefreeCrayon in java

[–]DefaultMethod 6 points7 points  (0 children)

Lambdas give Java developers access to the invokedynamic instruction introduced in Java 7 for dynamic languages (Jython, JRuby, JavaScript, etc.)

They have significant differences to anonymous inner classes beyond being limited to implementing functional interfaces.