18 ms·
Java in the Small
- bArray 2y agoSpent a while trying to get (OpenJDK's) JShell to work, it seems like a buggy mess. I would currently not recommend using it for anything serious.
- wing-_-nuts 2y agoI remember reading horstmann's books in college and it doesn't surprise me at all that java is the hammer he reaches for given a particular nail. I have to say I find it an odd choice for small replacements for bash scripts. I think python or golang are probably better choices for that purpose. Java is one of those 'enterprise' backend languages which lend itself to making a team productive over making the individual productive, and I say this as a java / go dev who's most comfortable with java for most backend work.
- ggerules 2y agoDr. Horstmann was my advisor in college, San Jose State. I just loved his lectures, very dry sense of humor, and extremely funny. He was just getting started writing books in the early 90s. He has this awesome way of thinking about programming, that I imparted to my own students when it came my turn to teach programming. I wish there some videos of his classes that I could go back to and share with people. Good website also, https://horstmann.com/ https://horstmann.com/ The picture on the website with him in the row boat has a funny story with it. When asked why he is in a row boat, he would reply, "Students are in the row boat with me, learning to program. At some point I push them out of the boat into the eel infested lake. The ones who are clever enough to make it back to the shore will be good programmers." All of this said with a faint hint of a German accent and a sly smile. If you happen to read this, Dr. Horstman. I made it to shore. Thanks! It has been an awesome journey!
- spike021 2y agoThat's an interesting experience. I also had him as a professor a while back and he was awful. He was always looking at his phone or computer especially during project presentations and completely ignoring what anyone said. He also didn't seem to know much course material in general. What I remember most is his obsession with Emacs. There was one time that I was grateful though, I had to buy a few of his books and one of them had a defect from the printer, so he helped me get a new copy from the publisher for free.
- anitil 2y ago> lend itself to making a team productive over making the individual productive That's a really insightful way of presenting this. I think if that's how I'd been introduced to Java I might even have tolerated it.
- PaulHoule 2y agoI learned to code "single file Java" when I was working through Hacker Rank before they added features to the JDK to make it easier. Certainly if you want to do whiteboard coding sorts of problems it is good to know.
- losvedir 2y agoI've been using Java 21 for Advent of Code this year, and I've been surprised at how much less clunky it is than I remember. `var` and `record`'s are especially nice for how I like to code. It's still not perfect, but it's not something that I hate programming in now. These were some neat tricks. I've been using the `java myfile.java` approach for running the AoC problems. I didn't realize the "implicit class" thing where you could have top level statements and methods, though, with the automatic import of java.base. That's pretty slick for this.
- papercrane 2y agoRecords being allowed in methods has been great for me when doing things like path finding. Makes it easy to write something like: record Node(int cost, int row, int col){} var pq = new PriorityQueue<Node>(Comparator.comparingInt(Node::cost));
- gf000 2y agoThis is actually a natural extension of classes being allowed inside, which is not well-known for some reason. Nonetheless, I also really like this feature with records.
- roncesvalles 2y agoIt's allowed because Record automatically implements methods called cost(), row(), and col().
- Nijikokun 2y agoJava is still great, same for PHP and they have only been getting better.
- lxgr 2y agoGreat is pretty domain-specific! Java has been great for larger projects for a while, but I think smaller things like one-off scripts have been firmly out of reach so far. It's good to see that change, as being able to use it in the small has obvious synergies.
- riku_iki 2y ago> but I think smaller things like one-off scripts have been firmly out of reach so far. why specifically?
- lxgr 2y agoThe article lists several good reasons: Having to compile every time (or at least there not being a convenient wrapper that compiles and runs at once), the boilerplate of having to define a class and main method, exception handling, and most of all having to deal with Maven.
- riku_iki 2y agoyou don't need to deal with Maven if Java standard library(which is huge) is enough for you. Also, not sure why such big resistance against maven. Other pointers are either opinionated or minor. From another hand, if dev has experience in Java, benefit of not learning some new language/ecosystem is kinda huge.
- never_inline 2y agoFor CLI scripts, PicoCLI with Graalvm seems to be a good option now.
- deleted 2y ago[deleted]
- HaroldCindy 2y agoI wasn't aware that single-file Java without a top-level static class was possible now, that + JBang seems quite useful for small tasks. One nit: > Python programmers often use ad-hoc dictionaries (i.e. maps) to aggregate related information. In Java, we have records: In modern Python it's much more idiomatic to use a `typing.NamedTuple` subclass or `@dataclasses.dataclass` than a dictionary. The Python equivalent of the Java example: @dataclasses.dataclass class Window: id: int desktop: int x: int y: int width: int height: int title: str @property def xmax(self) -> int: return self.x + self.width @property def ymax(self) -> int: return self.y + self.height w = Window(id=1, desktop=1, x=10, y=10, width=100, height=100, title="foo")
- qsort 2y agoThis is obviously valid, but it's definitely more common in a language like Python to just dump data inside a dict. In a dynamic language it's a far more flexible structure, it's the equivalent of HashMap<? extends CanBeHashed, LiterallyWhatever>, which is obviously a double edged sword when it comes to consuming the API. Luckily more rigid structures are becoming more popular at the API boundary.
- deleted 2y ago[deleted]
- bcoates 2y agoThat's deranged, just use a namedtuple and some functions. Even decorators for something this simple are a code smell. What do you do when another module needs ymin, inheritance? OO is dead, leave it buried umourned.
- lxgr 2y agoIt's of course always a good idea to read the article before posting, but doubly so here – I was getting ready to yell about all of the annoyances making this infeasible to anyone with a less-than-extreme pain tolerance, but it turns out Java has changed a lot since I last used it around six years ago :)
- Shakahs 2y agoAfter years of Python and TypeScript, I've started using Java as my default for everything. It's just so much more productive. The ancient developer memes that Java is slow and clunky don't apply anymore. Postgres also had a long-held reputation for being slow and difficult, but it made incremental improvements for decades and now it's the default choice for databases. I see Java in the exact same position, as the Postgres of languages.
- agumonkey 2y agowhat parts do you enjoy now ? I do agree that new ecosystems (js for instance) makes you miss some of the old big languages development feel. less churn
- deleted 2y ago[deleted]
- sdf4j 2y agoFirst time I hear those claims about Postgres. Was that the sentiment 30 years ago?
- dannyobrien 2y agoIt was definitely initially seen as big and cumbersome compared to MySQL, but sentiment shifted.
- cryptos 2y agoMySQL was kind of a fast toy database in the early days, but it was good enough to power simple PHP based websites.
- Tostino 2y agoIf say it was only about 15 years ago that the Postgres is slow stuff started dying off. Right around 2010.
- bcoates 2y ago14 years or less. Any version of Postgres before 9.0 was a nightmare to administer as a real production transactional dbms, at least the off the shelf version without a whole lot of tweaking without a (then very rare) pg expert.
- simonw 2y agoWow: void main(String[] args) { println("Hello world"); } I just saved that as "hello.java" and ran it (using OpenJDK Runtime Environment Homebrew (build 23.0.1) which I happened to have on my Mac already) like this: java --enable-preview hello.java This is SO MUCH less crufty than the old "public static void main(String[] args)" thing. I always felt that was a terrible introduction to programming, when Hello World included a whole chunk of boilerplate and a class that didn't need to exist.
- jimbob45 2y agoI disagree. Working through each keyword until you understand the full signature felt great when learning. It’s the Python if __name__ == __main__ trash that was the worst. You’ll never understand it and it doesn’t fit in the language.
- Comma2976 2y agoIn my humble and correct (trumping anyone else's) opinion, they are both garbage.
- Quekid5 2y agoYou're not wrong... but for different reasons :)
- exe34 2y agoyou don't need it until you get to importing modules. hello world in python is literally just print("hello world!")
- dvdkon 2y agoYou don't even need it afterward, unless you want a file to be both an importable module and an executable script. Arguably you could be a happy Python programmer without this capability.
- 2y ago
- forty 2y agoYou might also want to look at scala and ammonite [1] [1] https://ammonite.io/#ScalaScripts https://ammonite.io/#ScalaScripts
- eweise 2y agoexactly my thought. If you think java makes a good scripting language, you will be really happy with scala
- dropofwill 2y agoAlso scala-cli https://scala-cli.virtuslab.org/docs/getting_started https://scala-cli.virtuslab.org/docs/getting_started I still like to use Ammonite as a REPL, but scala-cli has replaced it for me in those cases where i get fed up writing bash.
- vvillena 2y agoScala-cli would be even better. It explicitly supports Java too!
- brundolf 2y agoVery cool to see all these quality of life improvements. I haven't kept up with Java for several years. Still, the dependencies thing seems like an issue (as it is in Python) Deno has been my go-to scripting tool lately. Similar benefits to Java as used by the OP, but it also allows you to import dependencies directly by URL, which means you can have your script self-define dependencies without a separate manifest file
- qsort 2y agoPython packaging continues to be a pain, but you can specify dependencies for single-file scripts with inline script metadata, see: https://packaging.python.org/en/latest/specifications/inline-script-metadata/#inline-script-metadata https://packaging.python.org/en/latest/specifications/inline...
- nesk_ 2y agoRemembers me the “Java for Everything” blog post: https://www.teamten.com/lawrence/writings/java-for-everything.html https://www.teamten.com/lawrence/writings/java-for-everythin... Also, thank you for sharing! I do appreciate Java and I’m glad to see it can be used for scripting nowadays.
- deleted 2y ago[deleted]
- neonsunset 2y agoStill long way to go before it reaches .NET levels of productivity (especially so if you use F# for scripting, but C# is no slouch either) :P
- pjmlp 2y agoDepends on the platform, some don't have any .NET productivity available. :)
- neonsunset 2y agoThese platforms are not being considered here nor have much relevance anymore. You cannot seriously claim this unless you don't use the tooling side by side at all. The difference is so stark it's no longer amusing. Performing setup for complex Java projects has me go through similar steps as if they were written in C++. Performing setup for C# projects of comparable complexity usually requires just cloning and hitting 'dotnet run', much like it usually happens with Rust or Go (some may claim I undeservedly bash it but credit is where credit is due).
- pjmlp 2y agoLike my phone, or those used by US military? I love your identity with .NET ecosystem, to the point of nothing else being in the way. See latest JetBrains Developer Surrey about platforms. .NET is a great ecosystem, but lets be real where it stands outside Microsoft shops, across everything that has a CPU on them, and the various ecosystem where sadly it doesn't even get a tier 1 support. Programming languages are tools, a toolbox has space for plenty of them.
- mike_hearn 2y agoAre you comparing "complex Java projects" against just ordinary "C# projects"? Because ordinary Java projects will also be "./gradlew run" or the Maven equivalent, that's nothing special.
- neonsunset 2y ago
- singpolyma3 2y ago> Java has many features that make it well suited for large, long-lasting projects Already disagree, haha
- whtsthmttrmn 2y agoI'll bite. Explain, please.
- ljfusddqq 2y ago[flagged]
- barbs 2y agoWhy?
- gf000 2y agoBecause it's a powerhouse, has top notch performance, observability, a vast ecosystem and developer pool, etc. Root commenter is just a troll.
- lproven 2y agoAgree: why? I don't know a single reason, and I've worked on Java docs in the Java industry. This was literally my day job for a while, and I have no clue what they're trying to hint at here.
- KyleBerezin 2y agoThere are reasons to not like Java, but this isn't one of them. Java is a fantastic language for large long lasting projects. I can't think of a more suited language for large long lasting projects in fact.
- singpolyma3 2y agoI mean if you like Java that's fine, to each their own I guess. But the thing that makes a codebase nice to maintain or not is how nice the code are is, nothing to do with language. If you try hard can you make a bit Java codebase easy to maintain? Probably. If you go in to maintain a random big Java codebase will you have a good time? No.
- mongol 2y agoI don't think Java is fit for "the small". And there is nothing wrong with that. My go-to language for "the small" is Go. Java is good for enterprise heavy-lifting, not for quick and nimble tools.
- Pet_Ant 2y agoFor the small I like Groovy. Especially as Grapes is like Maven but in annotations that you include in the script file. Being Java-based means that if it goes from "in the small" into something larger you are already on a stable foundation.
- jknoepfler 2y agoand you get a nice little portable binary that doesn't force someone to install a compatible version of an interpreter/virtual machine to run.
- mongol 2y agoExactly
- vips7L 2y agoThat's if they're on the same architecture and operating system as you. Half the people I know are on mac, half of them are on arm. The other half are on windows and x86.
- Terr_ 2y agoNow I'm having flashbacks to porting a whole stack of applications from x86 to a customized Linux distribution running on a big-endian PC platform. A mishmash of C/C++, Java, Node-JS, Python... It was really dumb, but that's what the client needed. So much cross compiling.
- evantbyrne 2y agoGo has cross compilation.
- 2y ago
- dajtxx 2y agoI started with Java 1.0 and thought it was great. I still do, although I haven't used it since 2020. The only thing I don't like is how there is no built-in JSON package which seems like a necessity these days. Removing the public static void main(String[] args) business seems like pandering to a non-existent audience, or at least a miniscule and insignificant one. Anyone who is going to use Java for a real project is not going to be worried about that, and anyone who thinks that's too difficult to deal with is never going to be a good programmer anyway.
- Zu_ 2y agoThe last part seems like a very 'gate keepy' point of view. If you want to introduce someone to programming, you probably don't want them to worry about what all those 'magic words' do. At least for their first steps, they won't need to know what a class is or what `public` and `static` mean.
- znpy 2y ago> If you want to introduce someone to programming, you probably don't want them to worry about what all those 'magic words' do. I learned Java when i was 15 or 16, reading some random book first and then I stole 35 euros from my mother's purse and bought a copy of "Java how to program" by deitel and deitel[1]. The recommended version at the time was Java 5, and the SJCP certification was still issued by Sun Microsystems. I can tell you, "public static void main" is not going to be the problem. [1]: looking back (i'm in my 30ies now) sometimes I wonder if i would have been better off buying weed or alcohol (or both)
- deleted 2y ago[deleted]
- scotty79 2y agoFor error handling they could add error propagation operator `?` from Rust. In Java it could propagate "throws" from the expression it's applied to the signature of a method that contains it. In Rust it's a bit awkward becuse you need to adjust return type. Since Java tracks exceptions separately it would be completely unobtrusive and ultraconvenient.
- deergomoo 2y agoIt’s not a popular choice for it, but PHP is also fantastic for the sort of things described in this article. A relatively recent version is pre-installed on many *nixes, it has a decent enough (and gradual) type system, and standard library absolutely chock full of functionality (albeit very self-inconsistent in naming and structure) for dealing with files, JSON, making network requests, etc. And because it’s not compiled, you can just whack a hashbang at the top of the file and chmod it to be executable.
- Terr_ 2y agoI agree it'll work, but from a broader ecosystem perspective it feels like a mismatch, given PHP's historic focus on webstack stuff, and the projected likelihood that someone maintaining the system will know PHP versus Python etc. But perhaps we can both agree that it shouldn't be in JS/Node. :p
- macspoofing 2y agoThat's true for every other mainstream interpreted language. Is PHP better than Ruby or Python for those use-cases?
- AtlasBarfed 2y agoGroovy is still far far far better at cli scripting in javaland. You don't even need main methods and class wrappers, can import libraries with annotations with Grape, etc. The real failing of cli and scripting in jaba and groovy is running cli commands with access to stdin stdout stderr streams. I have figured out the dark art for groovy but it takes quite a few stack overflows to get there.
- socksy 2y agoMaybe it's sort of not the same because it's compiled with graalvm and so not trivial to add any arbitrary Java dependency, but the tech that scratches that itch for me is babashka — a proper REPL, because it's a lisp, sensible Clojure syntax, and easy IO. And all the core Java libraries, available in a much snappier form than Clojure or other compiled languages
- brabel 2y agoThe Groovy shell can be really fast if you use GroovyServ: https://kobo.github.io/groovyserv/quickstart.html https://kobo.github.io/groovyserv/quickstart.html It feels instant, no need for GraalVM.
- e12e 2y agoInteresting. Anyone have an opinion on how this compares to using Kotlin for similar tasks?
- mdaniel 2y agoSeems very similar https://kotlinlang.org/docs/kotlin-tour-hello-world.html https://kotlinlang.org/docs/kotlin-tour-hello-world.html although I haven't ever used Kotlin like a "script replacement" (e.g. https://kotlinlang.org/docs/run-code-snippets.html#command-line-ki-shell https://kotlinlang.org/docs/run-code-snippets.html#command-l... ) to compare and contrast Overall, I think Kotlin is a vastly superior language to Java and spanks Scala in discoverability and legibility (less magick moar bettar, IMHO)
- norir 2y agoI've abandoned the jvm, but I found Scala much better designed than Kotlin. Things in Kotlin felt consistently ad hoc and I would frequently run into weird special casing whereas Scala actually had general principles that could be applied to more use cases. Kotlin on the other hand had better IDE support in intellij for obvious reasons. That was not nearly compelling enough for me.
- therealdrag0 2y agoWhat’d you switch to from JVM?
- occz 2y agoI'd consider it equal or better in all regards. - Top-level functions/main is supported - data classes are approximately as good as records - A scripting mode comes built in, and can use annotations to import and use dependencies within the same file - There's a repl - The keyword 'var' exists, and the keyword 'val' is more ergonomic than 'final var' The only thing I remember missing from the article is the implicit imports which I don't remember Kotlin having. Regardless, I'd reach for Kotlin every time. I think funnily enough Java never fully clicked for me until I started using Kotlin, which in many ways is "Java, except many best practices are on by default".
- anthk 2y agoOn Java, a lot of 1.2/1.3 era games are half-broken and threads fail a lot with interpreter from Java 2SE (>1.6/OpenJDK 6) and beyond.
- msgilligan 2y agoFor those interested in the rationale for the simplified main methods (and the rationale for not simplifying further), the relevant JEP is a good read. JEP 495: Simple Source Files and Instance Main Methods (Fourth Preview) https://openjdk.org/jeps/495 https://openjdk.org/jeps/495 The parent article mentions and links JEP 477 -- the 3rd preview of the same feature-set. JEP 495 is the 4th preview and is included in JDK 24 which is in "stabilization" mode for release in March 2025.
- aardvark179 2y agoI regularly end up using Jshell when I’m analysing things like profiling data. Partly because I have access to libraries that parse those formats, but also because typing and autocomplete make it really effective for this sort of interactive thing.
- driggs 2y agoLightweight Java has always been a thing for those who appreciate Java-the-language but despise Java-the-ecosystem. You don't need to fool with Gradle or Maven or Ant if you'd like to incorporate third-party or your own custom dependencies in single-file "Java scripts". Just copy some .jar files into ~/lib, and in your `.bashrc`: export CLASSPATH=~/lib;$CLASSPATH
- miuramxciii 2y agoAh.. the old days of java programming - set up your CLASSPATH and done.. Nowadays; however, most libraries have tons on other dependencies and doing this manually is tedious and a pain in the neck - download the wrong version of the dependency, and you are in for a rabbit-hole trying to figure out the compilation errors. Do not get me wrong, Maven is ugly and disgusting(so are the other dependency managers for java), but gone are the days of CLASSPATH.. unless you avoid using libraries bloated 3rd part libraries at any cost.
- rmgk 2y agoIf you like to have most of the simplicity of just setting classpath, but still have convenient dependency resolution, I highly recommend checkig out coursier: https://get-coursier.io/ https://get-coursier.io/ Its a cli based artifact fetching tool for the JVM ecosystem, and you can have it just make up classpath strings for you, i.e., to use some Apache dependencies with the single file simplified java running you could just: java --enable-preview --class-path (cs fetch --classpath org.apache.commons:commons-collections4:4.4) program.java Also, maybe do have a look at scala-cli: https://scala-cli.virtuslab.org/ https://scala-cli.virtuslab.org/ It does work just fine with Java files, and allows you to write single-file programs that include dependencies as special comments. The tool has some idiosyncrasies (like a background compiler server), but overall works extremely well if you need some of the power of a build tool, but without having a complex project structure.
- oftenwrong 2y agoAlso, see this project that is in a similar space as Coursier: https://github.com/bowbahdoe/jresolve-cli https://github.com/bowbahdoe/jresolve-cli https://github.com/bowbahdoe/jresolve https://github.com/bowbahdoe/jresolve
- w10-1 2y agoLaunching without compiling, a main interface... a Mark Reinhold story During jdk 1.1 development, there was obviously no consensus on test suites (i.e., JUnit), and the JavaSoft JCK tests required a ridiculous amount of html documentation for tracing to specs. Mark Reinhold, the jdk tech lead, refused to have his team write tests in JCK form, so instead he wrote a small harness with a compiling class loader: point the harness at a directory tree of .java files, and it would run them all, compiling as needed. The test interface was just a main function, and if it threw an exception, it failed. Pure and simple. But probably the best magic trick for Java programmers is debugger hot reload. You write some empty methods, start the debugger, and then code iteratively, reloading as needed. (Set up the data and interfaces right, and change method bodies as you wish.) It's so much easier than recompile-println when you're just getting started, and after you've grown up and out, it's easier than rebuild/redeploy when you're working on a big system.
- jaccarmac 2y ago> debugger hot reload Hey, that's (close to) the traditional Smalltalk introduction-trick! And this has been available since 1.1? How does one concretely do that in Java and why is it not widely known?
- gf000 2y agoWell, it doesn't sit that well with mutable global/local state. There is a saying that hot reloading works better if you can replace at a smaller, atomic granularity. In the JVM, this kind of reload is at the method granularity, which may or may not be ideal. But the JVM still has a few tricks up its sleeve, e.g. the class loader can dynamically re-load a newly compiled version of a class at runtime - jrebel is a proprietary extension that uses both tricks, but this latter can also be used by spring for hot swapping many parts of a running system. Basically, in the JVM a class is unique within the class loader, so with a new class loader you can load as many class instances of the same, or slightly different class as you wish.
- mike_hearn 2y ago1. There's no way to react to hot reload in the normal Java API, so you can't easily clear state. 2. The JDWP protocol lets debuggers redefine nearly anything, but HotSpot doesn't implement the full protocol. In practice many kinds of reload don't work. 3. To fix those issues app frameworks went with classloaders for partial app reloads instead, or reimplemented hotswap logic themselves (see JRebel). There's no fundamental reason these can't be fixed, and in fact the Espresso JVM fixes both 1 and 2: https://www.graalvm.org/latest/reference-manual/espresso/hotswap/ https://www.graalvm.org/latest/reference-manual/espresso/hot... You can write JVM plugins that are invoked after redefinition occurs, allowing you (really your app framework) to do something sensible like partially reload state. And it implements the full protocol, so many more kinds of redefinition work. Using it is easy. Just install Espresso as your JDK, point your build system at it, then debug your app. Recompiling what attached will cause hot reload.
- easylion 2y agoI totally agree. I use java for every possible coding script or task. I have been using it in my company for last 5+ years and have understood the language too well to be able to switch to something else and learn its caveats. In my comfort zone with java and I love that its being actively developed and improved every day.
- trallnag 2y agoAre you in the comfort zone with Spring as well?
- throwaway03452 2y agoI can only speak for myself, but I was lucky to be exposed to Spring Boot back in the v1.5 days after spending a few years creating Java programs without any framework. No XML at all, configuration by code, and opinionated default configuration that covers most use cases. The learning curve was not that hard, and I got comfortable with it. In contrast, I find React, Next.js and other frameworks more complex, and it takes a lot longer to be comfortable
- joeevans1000 2y agoTake a look at Clojure and also Clojure Babashka.
- lebski88 2y agoBabashka is truly wonderful and has taken over almost all my scripting projects. But the author started by saying they didn't want to use a language without types so Clojure is probably out!
- Kwpolska 2y ago> I am pretty sure [working around checked exceptions] will never be a part of the JDK, because it is arguably bad for large and serious programs. And yet so many programming languages, including JVM languages like Scala or Kotlin, just don’t do checked exceptions, and the world hasn’t caught fire yet (and in fact, I can’t think of another mainstream language that does have them). Java could just drop them altogether and everyone (except maybe the most devout Java fans) would be happier. > The file gets compiled on the fly, every time that I run the script. And that's just the way I want it during development or later tinkering. And I don't care during regular use because it's not that slow. The Python crowd never loses sleep over that, so why should I? Java takes significantly longer to compile than Python does. My Python takes ~40 ms at first startup of a hello world script, ~20 in later attempts. `java hello.java` is in the 360-390 ms range.
- klez 2y ago> `java hello.java` is in the 360-390 ms range. That's still pretty negligible. I don't think he's making a strict comparison, just saying that in both cases it's barely noticeable.
- vips7L 2y agoChecked errors are not unique to Java. Rust, HNs darling baby, is praised on this forum every day for checked errors. Swift, F# and countless other languages have checked errors. There is nothing wrong with checked exceptions and there is really no difference between a Result and a function with a checked exception. fn a() -> Result<String, SomeError> String a() throws SomeException The issue is not with checked exceptions but with Java’s syntax. They have not given programmers the language syntax to easily deal with checked exceptions. You cannot easily escape them without boilerplate and they don’t work correctly across lambdas. This is why Rust ships with ?; Swift has shipped with try!, try?; and Scala ships with try as an expression and is experimenting with checked exceptions that work across high order functions [0]. Programmers across every language ecosystem are moving towards checked errors and away from unchecked runtime crashes. Even Kotlin, a language that shipped with unchecked errors, is planning on adding a form of checked error handling [1]. [0] https://docs.scala-lang.org/scala3/reference/experimental/canthrow.html https://docs.scala-lang.org/scala3/reference/experimental/ca... [1] https://youtrack.jetbrains.com/issue/KT-68296 https://youtrack.jetbrains.com/issue/KT-68296
- exabrial 2y ago> JTaccuino Shame the link is broken, looked fascinating!
- Alifatisk 2y agohttps://github.com/jtaccuino/jtaccuino https://github.com/jtaccuino/jtaccuino
- d_burfoot 2y agoIt's worth observing that languages significantly over time, usually for the better. I remember writing Java when it was slow and had no generics. Now it's one of the fastest languages, and has not just generics but also (simple) type inference, which cuts down significantly on boilerplate. The point is: if you have a foggy memory from ten years ago of hating some language, many of the problems may have now been fixed.
- mattgreenrocks 2y agoIt's hard to fault Java at this point: arguably the best runtime of them all from a perf perspective, great tooling from JetBrains, large, high-quality ecosystem whose quality far exceeds npm on average, and sealed classes as an acceptable sum type. My only remaining issue is how prevalent nulls are, but there's some work in progress on improving that. Until then, I'll prefer Kotlin slightly. Definitely one of those things where the comment section is only good at spouting ancient memes with little regard to the truth of them.
- Xeoncross 2y ago> It's hard to fault Java at this point: arguably the best runtime of them all from a perf perspective The JVM is a massive memory sink compared to the tiny (actual) runtime in Go or the total absence of a VM or runtime in Rust or Zig. I allocate at least 5x more memory for Java tasks, but sometimes its more. Java is great compared to scripting languages or writing raw C, but not compared to modern compiled languages from a syntax (null, thrown exceptions, inheritance, etc..), library selection, CVE/security, memory usage or raw computer power perspective.
- pron 2y agoMany times the "massive" memory sink is because people give the VM more memory than it actually needs (or they use the default, which is to take up to 25% of RAM whether or not it's really needed for the required performance). I.e. people will say a process "takes" 1gb, when the same program could run just as well if they tell it to use, say, 300mb. The more memory, the faster it could run. The GCs offered by the JVM are more advanced than Go's by a couple of tech generations (the Go-like GC was removed from the JVM when it was superseded by two generations of newer GCs), and memory consumption is already going down with compact object headers [1] and will go down even further with Valhalla. All in all, Go may take up a little less memory for similar performance, but the JVM is more flexible (and more observable), offering you better performance if you need it. And the footprint will continue dropping, as it has done for years [2]. C++, Zig, or Rust are not really an apples-to-apples comparison. Sure, they take up significantly less RAM, but their performance is more expensive per unit of effort, and it's not a one-time cost, either. It's a permanent tax on maintenance, not to mention Java's superb observability. Don't get me wrong -- I'm a fan of Zig, and C++ is the language I still program in most, but you can't really compare them to Java. Java makes you pay for certain things -- especially in RAM -- but you do get your memory's worth in exchange, and in a way that translates to pretty significant time and money. If you can't spare the memory as you're running in a constrained environment that's one thing, but if you can, it's all a matter of what you want to use it for: do you want to use it all just on data, or do you want to spare some to reduce maintenance costs/increase development speed and improve performance? BTW, I'm not sure what is actually meant by a "lack of runtime" for C++/Rust/Zig. They all have standard libraries, just like Java. Rust even has a (crude) GC in its runtime that most Rust programs use (and, like Java, it compiles down to a VM). I think what people mean is that compilation to native is typically AOT rather than JIT, but that has both pros and cons. [1]: https://openjdk.org/jeps/450 https://openjdk.org/jeps/450 [2]: E.g. https://openjdk.org/jeps/254 https://openjdk.org/jeps/254
- egeozcan 2y agoI use Java/JavaScript/TypeScript at work but I do most of my scripting with .NET using LINQPad. Being able to use LINQ makes scripting so much easier. Python? Huge respect, huge ecosystem, however I don't know if it's just me but I find it mighty hard to read. PHP with the "->" and Python with the space-sensitivity... Not sure why but it's so hard for me to overcome.
- dominicrose 2y agoPHP syntax does add to the line widths, so breaking long lines in multiple lines by extracting variables can help with readability. Using return, continue and break early reduces indentation so that helps too, as well as creating smaller functions. I use Ruby for scripting because it has a big standard library (unlike javascript) and an expressive syntax. The syntax is also very readable and short. It's also easy to install gems globally and use them. Things only need to be imported once. I wouldn't say these things are qualities for big projects though. I like Typescript for big projects.
- nprateem 2y agoThey should adopt the tag line for Java: "Not as bad as you remember" I was also surprised when I looked at it again a year ago. I would have used it for my latest Web app but django just beat Spring boot.
- riskable 2y agoHave a look at any "mature" Java project on Github and you'll quickly come away with the opposite: "Wow! It's even worse than I remember!" "Wow! How many files and directories does this project NEED? It's like someone decided that it's easier to manage files than code..." ...and there's still XML everywhere :(
- brabel 2y ago> As of Java 23, three methods are automatically imported from java.io.IO: println, print, readln I thought they had just hallucinated `java.io.IO`, but apparently it's a new type, available in Java 23 with --enable-preview: https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/io/IO.html https://docs.oracle.com/en/java/javase/23/docs/api/java.base...
- roncesvalles 2y agoI just had this thought recently. Java is a fantastic "scripting" language as long as you're fine running it in an IDE. Clean and typed syntax, powerful standard library (especially for data structures), great performance. A better choice in these respects than say Python, Bash, or Go. I've used it for scrapers, Advent of Code, plain ole data munging and of course programming interviews. That being said, I would never write a webserver in Java in 2024.
- va1a 2y ago> but the Python API isn't all that wonderful, and dynamic typing means that I spend too much time debugging I don't know, this just seems more like inertia. "I'd rather stick to what I know best than this popular thing." Which is fine, and I'm glad Java has made improvements making it easier to hit the ground running. But blaming the use of Java on the inadequacies of Python? The python API can do just about anything, it has regex toolings, I've never found myself needing anything else. And the typing complaints? Yeah it can be annoying if you're not good at keeping track of your own typing hints, but modern python supports type annotations and linters like mypy[1] catch everything related to that just fine. I've always admired many of Java's features, but let's not act like the reason for using Java for scripting is the pitfalls of Python. It's just because of an underlying preference for Java. 1. https://mypy-lang.org/ https://mypy-lang.org/
- BeefWellington 2y ago> Yeah it can be annoying if you're not good at keeping track of your own typing hints If you write all the code you deal with, then sure. My experiences on big projects tend to be typing problems introduced by libraries. The kind where documentation and the decorators suggest it'll only ever return some specific value type, but then very occasionally it'll return a tuple of that value type and a message.
- va1a 2y agoFair, but in the context of scripting, which seems to be the focus of this article, how often are you dealing with complex library code? When I write scripts for file manipulation / simple automation, I'm usually not dealing with complex library objects. Plenty of os method calls, plenty of regex matches, but little else in this context. Big projects are another thing entirely. There's a plethora of reasons why you may want to use a different language for a certain project type. But it doesn't seem fair to imply that python is uniquely handicapped (or otherwise inferior to Java) for scripting and simple automation use-cases.
- pliuchkin 2y agoAs for my experience, nothing beats nodejs for fast scripting. Its literally just `npm install x y z` and then fire it up `$ node script.js`. But Im giving Java a chance.
- Alifatisk 2y agoWoah, reading the article felt so refreshing. Being able to see Java in this state is very exciting, this expands its usage into the scripting environment. I am currently a heavy user of JRuby for quick and dirty scripts but still want to be on the JVM, but I'll give Java 23 a go and see how far it goes.