- Life hack: Look before you paste because people can hide content from rendering in the browser. Pasting content to a command line can do some unexpected things. (From cheeser.)
- From whaley, who’s been on fire lately: Recipe for a great programmer. Great reading.
- More from cheeser, who is also on fire: InfoQ’s reference to Chaperone – A Kafka Auditing Tool from the Uber Engineering Team. If you’ve ever struggled with how visible Kafka information can be – i.e., you’re a Kafka user – any promise of improvement is a blessing.
- Compilation of Java code on the fly shows a highly dangerous and insecure feature that people have known about – but as said, it can be a security nightmare. Use with lots of caution, or don’t use at all – but it’s there.
Category: channel news
EJB Injection in JSP with Java EE 7
User suexec
asked ##java about accessing an EJB from a JSP template.
User dreamreal
(i.e., your author) put together a simple application (rather imaginatively called “suexec-war
” ) to explore the possibilities. The application was built from Adam Bien‘s minimalistic Java EE 7 Maven archetype, deployed into Wildfly 10.0.
It turns out that to the best of my understanding, injection of an EJB into a JSP is simply unsupported. The JSP can use JNDI to acquire an EJB via JNDI (see source) but the CDI injection never worked.
Next, I wrote a simple servlet (called, of all things, TestServlet.java
). Here, the @EJB MyEJB ejb
worked like a charm.
To render, I used the Handlebars template library just for kicks; Freemarker (or even JSP itself) would have worked just as well, but I wanted to play with something different.
The process would have been the same no matter what templating library was chosen: you’d take the values you wanted to render and store them somewhere such that the rendering engine could access them. In my case, I could have built a composite object (or even asked Handlebars to call the greet()
method itself, using the ejb
value) but I was aiming for simplicity rather than optimal behavior, following whaley’s “Make it work, make it pretty, make it fast” principle (from “Suffering-oriented programming” )- this is rough code, meant to serve more as a smoke test than an actual example of a great application, so I left off at “make it work,” leaving even “make it pretty” to others.
Comments and improvements welcomed.
Interesting Links – 18 Nov 2016
Today’s apparently a Microsoft edition of the interesting links! Almost everything relates back to them this time…
- From wyvern: “The Error Model” is an article discussing… exceptions. Exception handling and the “checked or unchecked” question is (still) controversial in Java; article provides some interesting context on error handling approaches, and explains how error handling evolved in Midori (Microsoft’s experimental research OS). A fundamental decision when choosing to make your API throw a checked or unchecked exception is whether or not a particular error is considered fatal or not. This is frequently a murky question: if you’re writing a one-off script,
IOException
may be fatal, but for a long-lived daemon, it should be handled safely and not rethrown to the top level. While we obviously can’t use Midori’s exact approach in Java, the thought process exhibited is helpful when deciding how to structure your APIs to allow tidy error handling. The whole Midori blog series is worth reading, if you’re looking for more. - Microsoft has announced that it is a Linux Foundation platinum member. My, how things have changed…
- Speaking even more of Microsoft, it looks like they’ve finally open-sourced their SQL Server JDBC driver, and it’s hosted in a Maven repository. Typically, people use jTDS instead, but this is potentially great news; it’s not clear offhand what the advantages are compared to jTDS, but the more options you have, the better, right? Plus, this is another example of Microsoft actually contributing to the larger ecosystem, something many are still not used to. Now, if they could only make SQL Server less of a pain to work with…
- Finally, stepping off the Microsoft train, user asgs pointed out Simon Ritter‘s “20 Years Of Java Deprecation,” which details the list of accumulated deprecated classes and methods in the Java runtime library. It’s actually a really low number given Java’s maturity (maybe that’s a sign of maturity?) — and it also points out that hardly anything is actually removed, although that will change with Java 9, with a whopping six methods being removed.
Interesting Links – 15 Nov 2016
- Big news: JRebel 7 has been released, with a new agent enabling you to change class hierarchy and interface implementations on the fly. For Spring it now also supports reconfiguring dependency injection in non-singleton scoped beans.
- From Light Java, “JEE is dead.” Misses a lot of history – blames Java EE for WebLogic’s speed and deployment model (what about containers like Orion, which could deploy the same apps in a few seconds, and didn’t need
ejbc
? What about JBoss, which was free? This post ignores both, saying Java EE containers were slow and expensive), and misrepresents a question about Oracle as a statement of Oracle policy, also misunderstands some other core facets – and tries to market Light Java itself as a framework, making this a bit of a “your framework is dead! Use mine!” post, but it’s still interesting. Of course, it’s not the only microcontainer framework out there in Java… - From /r/java, Jadler looks like a good HTTP mocking library.
- Also from r/java, Nudge4j is a small jar to create a web-enabled access point for a running JVM – you can effectively type code to run inside a running VM. I haven’t tried it, but what an idea.
- jsoup 1.10.1 has been released. Lots of little changes; the biggest seems to be the ability to preserve case of tags (as an optional feature) but memory usage has also been optimized.
- John McClean posted an interesting article: “Trampolining: a practical guide for awesome Java Developers“.
Interesting Links – 8 Nov 2017
- From ernimril: a video! CppCon 2016: Jason Turner “Rich Code for Tiny Computers: A Simple Commodore 64 Game in C++17†is an hour and twenty minutes of Jason Turner talking about writing a game for the Commodore 64 using, surprise, C++17 and translating to 6502 assembly. (Play at 1.25x speed to save some time – or 2x speed if you want that Brian Goetz effect.) It’s actually really fascinating to watch, and has nothing to do with Java whatsoever.
- For Mac users, particularly on Sierra: “MacOS Sierra problems with java.net.InetAddress: getLocalHost()” documents some lookup problems on the recent MacOS update. Short form: make sure your
/etc/hosts
actually has your local domain name resolving to127.0.0.1
. - FindBugs is apparently having some problems.
- Non-java, but useful for programmers anyway: Bulletproof Mind: 6 Techniques for Mental Resilience from the Navy SEALs. Some adult language, but it’s an excellent article and we’re all adults anyway.
- “Docker in Production: A History of Failure” is a litany of issues with the popular virtualization technology. It’s worth reading, even if you’ve deployed Docker successfully – if only to keep track of how far there is to go.
- From the Python world: EAFP and LBYL. In Python, apparently using the “Easier to Ask For Permission” approach yields massive performance gains; Java, like C and C++, tends to prefer LBYL, which stands for “Look Before You Leap.” Worth keeping in mind, especially as Java adds more functional programming concepts. It’d be interesting to see EAFP and LBYL contrasted well in Java – and note that EAFP tends to prefer
try/catch
to manual boundary checking, so maybe Java’s already there to a large degree.
Interesting Links – 4 Nov 2016
Oh, boy, a bunch of releases:
- Guava 20, the ultra-useful third-party library for Java that virtually everyone can and should be willing to use, has been released…
- MongoDB 3.4, the NoSQL document database used by jabavot and many others, has been released…
- LWJGL 3.1.0, the lightweight java graphics library, has been released…
Finally, DZone publishes something I wanted to read:
- “Everything You Want to Know About ThreadLocal Random Implementation,” a really interesting walk through a random number generator.
- From cheeser: Whiley, “A Programming Language with Extended Static Checking.” It’s another language for the JVM with significant whitespace (blocks are determined by indentation); it also provides a way for methods and functions to guarantee at the compilation stage that return values comply with a specification. It looks neat. It’s been around since 2009, and there’s no way to tell if it has any sort of path to critical mass yet. Take a look!
Interesting Links, 31 Oct 2016 (and 25 Dec 1038)
- kumuluzEE is “A lightweight framework for developing microservices using standard Java EE technologies and migrating existing Java EE applications to microservices.” It’s not immediately clear from the web page what makes it ideal for migrating to microservices, but there it is.
- “Don’t Even use COUNT(*) For Primary Key Existence Checks” has some valuable performance advice, and considers multiple DB implementations while offering it.
Now for some Scala stuff:
- “Quo Vadis, Scala?” has some considerations of the value of Scala on the larger JVM ecosystem. Turns out that Scala has more impact than some think it does, and less impact than others think. Go figure. 🙂
- “Sbt makes me want to give up Scala” has some well-considered criticisms of the Simple Build Tool, SBT, Scala’s primary delivery mechanism. Well-written and justified; if a build tool is the primary contact point someone has with a language, and that build tool is slow and uncomfortable to use, well… that impression is going to stick with people. SBT is really powerful… and it sucks. This post walks through a lot of why.
- From user tetero, apparently inspired by the SBT link, “Scala Collections: Why Not?” is a video presentation by Paul Phillips that feels like it’s a rant about why he’s leaving Scala: it doesn’t do things the way he wants. Sure, what he wants would be good (simplicity, accuracy, honesty, clarity) and it highlights what people see as the worst in Scala: the community’s hardheadedness about how good Scala really is. It turns out to be an anti-Scala rant, in the end, but the truth is that Scala is better than he makes it sound and just as bad as he makes it sound. Use Scala if it works for you, and don’t, if it doesn’t. (The user in question said that this video was part of what led him to Clojure. There’s nothing wrong with Clojure, but like most things, it’s not perfect and Scala’s type system oddities seem like a poor sole motivator.)
Interesting Links – 24 Oct 2016
- The Way of the Lambda – Elegant and Efficient discusses using Java 8’s
removeIf
to remove elements from collections, as opposed to removing them via an iterator, and shows graphs to show the improvement. One claim (via Reddit) was that it was O(1) but here the claim is a little more reasonable. Another thing from the post was that the author says that he’s “recently … spent a few years away from Java development,” something that a lot of people seem to be saying now. Not sure what’s making that happen – maybe Java 8 made Java cool again. - Speedment is another persistence engine for Java, focusing on streams.
- Java Method Reference Evaluation discusses Java’s evaluation of method references, as done by the
::
operator. From the author: “The immediate target evaluation of method references is likely undesirable in most cases where the target can be expected to change between invocations. Consider using method references only for static methods and constructors (X::new
), or with instance references that are known to remain unchanged for all invocations. If there is any chance that the target reference might need dynamic re-evaluation you will have to use a lambda expression.” - Meet Franz is a centralized chat application. I haven’t tried it and can’t vouch for it (yet) but given that I have four chat applications open at minimum at all times… it might be something I have to try soon.
- From /r/java: apparently GWT 2.8.0 has been released. The website looks really nice; I liked GWT in the day; who knew development was ongoing? (No release notes were apparent on the website, unfortunately, so I don’t know offhand what changed; I could dig it up, but maintaining interest is difficult.)
Interesting Links – 21 October 2016
- Everything is fine with JavaScript – hold on, I know, this is a Java blog! But it’s okay. Trust me. This post says a lot about JavaScript – but a lot of it is also very transferable to the Java ecosystem. One headline stands out: “If someone is holier-than-thou about technology choices, they’re wrong and you should ignore them.” (Notice how carefully I’m avoiding bringing up, say, MySQL or JSF here.)
- From r/java: Externalizor says that it is a library for “efficient (fast and small) Java serialization using
Externalizable
interface.” No analysis provided of the potential security risks, and there’s no description of the format – but one nice thing aboutExternalizable
is that the library allows users to leverage the standard Java serialization. (No comment on whether that is an actual good thing or not.) - User yawkat made a reference to JITWatch, a tool for understanding the behavior of the Java HotSpot Just-In-Time (JIT) compiler during the execution of your program. It’s not exactly trivial to use (you may have to use a debugging version of the JVM – see the instructions) but the information can be really cool.
Interesting Links – 17 Oct 2016
- JEP 295: Ahead-of-Time Compilation offers deployers a chance to compile the base Java modules to native code. This can save time on some optimizations, but it’s understandably limited (and should be).
- The Halstead Metrics (also known as “Halsted metrics”) discusses code complexity in Java. Worth considering; this particular explanation comes courtesy of JHawk, a commercial code metrics tool, not to be confused with “j-hawk“, an open source testing tool.
- Experimenting with “mutation testing†and Kotlin is a neat post describing PIT, a testing tool that changes your source code and runs your tests – if your tests don’t fail, your tests are probably bad (or your code’s awful.)