We've picked up on some common problems on the Oracle JET forum and have put together some tips and tricks, as well as news and updates, here:
We expect to release a similar YouTube clip part way through the 2nd and 3rd week of the course.
In the last post I showed how the Java 7 try-with-resources feature reduces boilerplate code, but probably more importantly how it removes errors related to unclosed resources, thereby eliminating an entire class of errors. In this post, the first in an ad-hoc series on Java 8 features, I'll show how the stream API can reduce the lines of code, but also how it can make the code more readable, maintainable, and less error-prone.
The following code is from a simple back-end service that lets us query metadata about messages flowing through various systems. It takes a map of key-value pairs and creates a Lucene query that can be submitted to SOLR to obtain results. It is primarily used by developers to verify behavior in a distributed system, and it does not support very sophisticated queries, since it only ANDs the key-value pairs together to form the query. For example, given a parameter map containing the (key, value) pairs (lastName, Smith) and (firstName, Bob), the method would generate the query "lastName:Smith AND firstName:Bob". As I said, not very sophisticated.
The new JDKâ„˘ 9 early access release contains a JDK enhancement proposal JEP 143, Improve Contended Locking, to improve the performance of contended monitors. Monitors are used by the Java synchronized statement to lock access to a code block. If the synchronized block is called by several threads, the monitor becomes contended. This can degrade performance dramatically. So let us look at the performance improvements of contended monitors.
The graphic shows the time of one method call. The lower numbers mean better performance. The test consists of 8 threads accessing a synchronized block, and all threads are accessing the same monitor. You can download the test here. The test was run on an Intel i5 4 core CPU. As we can see, JDK 9 improves the performance of contended monitors. Let us now look at a direct comparison between JDK 8 and 9.
Welcome to another installation of This Week in Spring! This week Iâ€™m in NYC (for the NYC Java SIG), Austin and San Francisco (for the Silicon Valley Spring User Group) talking to customers and doing meetups! Weâ€™ve got a lot to cover, as usual, so letâ€™s get to it!
- Spinnaker is a continuous delivery tool from Netflix built on Spring Boot. It supports a build-and-bake pipeline and works naturally with Spring Boot and various cloud platforms. Itâ€™s enjoyed contributions from Microsoft, Google and Pivotal. In this post, Spring ninja Greg Turnquist introduces Spring Cloud Spinnaker 1.0.0.M1. Definitely worth a look!
- This seemed interesting - a code generator that supports Spring-based applications called Sifu
- JAX London just announced their top 20 social influencers for Java. Spring Data lead Oliver Gierke and I made the list. This is awesome and Iâ€™m sure I speak for Oliver in saying weâ€™re honored to be included :-) There are a lot of other cool folks down there on that list, too, so Iâ€™m pretty stoked to be counted among them!
- Marco VĂ¶lz has been putting together a nice series on whatâ€™s new in BOSH, the systemâ€™s orchestration engine
- Good news everybody! The SpringOne Platform videos and content are available!
- Cool! An ElasticSearch Beat implementation for Spring Boot applications
- I liked Luanne Misquittaâ€™s post on building Spring Data Neo4J 4.1 applications
- Thereâ€™s an interesting post on Stormpath: Using Spring Boot to Build and Deploy .war files
- This is an interesting post on using Spring Boot and Letâ€™s Encrypt to seamlessly setup encryption for a Spring Boot application
- Rafael Salernoâ€™s got a nice post up on using Spring Cloud Netflix for service registration and discovery
Recently I needed to create a regular expression to validate the format of a comma-separated list of email addresses. Just thought Iâ€™d share the result in case it is of use to anyone:
Hereâ€™s an example of applying the pattern in Java:
While working on my Ionic 2 application, I made use of the exif.js library (for extracting meta-data from image files). Some of the key functions in this library are called and passed a callback function that is invoked when the image has been analyzed. From this callback function, I wanted to invoke a function (TypeScript method) defined in my class. Inside the callback function however, I did not have access to the calling context. Inside the callback function, this referred to the object passed into the callback function – and not to what this referred at the point of making the call to EXIF:
It took me some wondering, experimenting, mild cursing and browsing to figure out how to resolve this issue. Using some threads on StackOverflow, I worked out a solution. The callback function is produced by a helper method that produces the callback function and in doing so injects context references into it. Any parameters passed into this method are available as context inside the callback function. In this example, a parameter called outerThis of type AddBeadModal – the class this code resides in – is expected. Any elements defined on this class are now accessible inside the callback function, as is demonstrated with the call to convertDegToDec and the reference to the location property.
Code for exifHandleGetData – the helper method that produces the callback function:
When the call is made to EXIF, the result from the call to exifHandleGetData(this) is passed to EFIX as the callback function. This parameter carries references to the calling scope – through the parameter this.
Code for handlePictureSelection – the method that receives an update to an input type=file component and has EXIF process the selected image (and updates an Angular 2 form component subsequently.
This thread on StackOverflow helped me deal with my challenge: http://stackoverflow.com/questions/14471975/how-can-i-preserve-lexical-scope-in-typescript-with-a-callback-function.
The post Access the original calling context in a callback function in TypeScript appeared first on AMIS Oracle and Java Blog.
There is clearly some differences on opinions out there and not all of them are positive for the JVM community. What does it mean to be a â€śleading edgeâ€ť developer on the JVM. On the JVM, there are many languages like Scala, Kotlin and Clojure to name languages with real forward momentum.Are All Languages Welcome on the JVM?
So can you program in two (or more) languages at the same time? Comments like this one give me pause.
We started working on design smells many years earlier than when we started writing our book "Refactoring for Software Design Smells" (see http://www.designsmells.com). I was digging through some of the old documents and remembered that we did not cover many smells, considering them to be "uncommon smells". By "uncommon smells", I mean the ones that we (co-authors of the book) hadn't seen commonly occurring in software projects, and so did not think that they were worth discussing in detail in the book. We toyed with the idea of listing them in an appendix in the book, but dropped that idea because some readers could object the selection of the smells that formed the core of the book; for example, readers may question the choice of smells covered in the book, and may consider some of the smells mentioned as "uncommon smells" as common in their projects!.
Given the fact that it's been a couple of years since the book was published, I thought it would be interesting to see what you think about these smells. So with that, here are some of the smells that did not make it to our book. If this article generates much interest, I can post more smells in future articles!
Java web applications have come a long way since the days of servlets and Java Server Pages (JSPs). There are now many Java web frameworks for a developer to choose from, including Spring MVC, Java Server Faces, Struts, GWT, Play, and Grails. As with many other emerging technologies, an abundance of choices of web frameworks will lead to developer fatigue, the feeling of being overwhelmed by the need to keep up with the modern development worldâ€™s rapidly multiplying set of options. Interoperability tools like JNBridgePro are an ideal way to deal with many kinds of developer fatigue, particularly when the new technologies are based on Java or .NET. With JNBridgePro, you can learn a small piece of a new technology, while bridging back to other parts of your project, which use the old, familiar technology.
For example, letâ€™s say that youâ€™re a .NET developer maintaining an all-.NET web application using ASP.NET as the web framework. If youâ€™re tasked with updating the application to use a modern Java web framework, you can simplify your task and avoid developer fatigue by reimplementing only the front end, while preserving the familiar .NET code in the back end.
In part one, we started to look at a new approach to defining default arguments for methods. Here we continue with a few detailed examples.Default Arguments and Functional Programming
Let me introduce you to the MaleProgrammer class, which I'll use as an example for the rest of this newsletter:
Earlier this month I attended Pivotalâ€™s SpringOne platform conference in Las Vegas. In case youâ€™re not familiar with it, Spring is a Java Framework â€śthat helps development teams everywhere build simple, portable, fast and flexible JVM-based systems and applications.â€ť
For some of you out there you may be thinking Java is old school and not relevant in in todayâ€™s modern world of digital business. Au contraire mon frere. James Governor, the Dâ€™artagnan of the analyst world, countered this belief of irrelevance in his SpringOne talk entitled, â€śWhen Web Companies grow up, the become Java Shops.â€ť
Every day we try to find new ways to improve developer experience with IntelliJ IDEA. It may be a bugfix, a performance improvement, or a new feature (usually in this order). Today weâ€™d like to introduce a new plugin called JVM Debugger Memory View.
The plugin extends the built-in debugger with capabilities to explore objects in the JVM heap during a debug session. The Memory View shows you the total number of objects in the heap grouped by their class name.
Java lacks a built-in way to define default arguments for methods and constructors. Over the years, several approaches have been proposed, each with its pros and cons. The most widely-known one uses method overloading, though varargs, null values, the builder pattern, and even maps have been used as well. Here we propose a new approach based on functional constructs.Functional Default ArgumentsBackground
Many languages support default arguments for methods and constructors out of the box, i.e. Scala:
In 2002, Joel Spolsky coined something he called â€śThe Law of Leaky Abstractions.â€ť In software, an â€śabstractionâ€ť hides complexity of an underlying system from those using the abstraction. Examples abound, but for a quick understanding, think of an ORM hiding from you the details of database interaction.
The Law of Leaky Abstractions states that â€śall non-trivial abstractions, to some degree, are leaky.â€ť â€śLeakyâ€ť indicates that the abstraction fails to adequately hide its internal details. Imagine, for instance, that while modifying the objects generated by your ORM, you suddenly needed to manage the particulars of some SQL query. The abstraction leaked, forcing you to understand the details that it was supposed to hide.
1. Download the JS library and add it to the www directory of the Ionic 2 application
3. In every TS file in which you want to use the library, declare a variable of type any and with the name of the function from the 3rd party library – to act as a placeholder for the 3rd party JS library. During compilation, the real 3rd JS library is not visible, so any direct references to it will cause errors unless there is such a placeholder as shown here. Because the 3rd party library is loaded by the index.htm- the main page in the single page application – its functions will always be available (no lazy loading) and the references to the placeholder become references to the real library as a result.
The next figure shows how I did this for the exif library. Its main object is called EXIF, so my placeholder has that name. In the typescript function I can refer to functions that I know exist on EXIF – and I do not get compilation errors (nor of course do I get code completion or type safety). At runtime the references to EXIF are satisfied because then the exif.js file has been loaded.
Last weekend I spent an afternoon at a coffee shop with no wifi in order to solve a problem that I thought should have been simple (automatic de-duping) but which had stumped me for weeks. (I was getting false positives in a pattern I couldn't figure out.)
It took me less than an hour to solve the problem. Turns out I had been counting on one number (but really a string) being very unlikely to collide with other numbers for more than a few digits, when in fact that number -- for domain-specific reasons -- was supposed to share lots of n-grams with other numbers. Dead-simple fix, once I figured this out..and felt stupid for not noticing it before.
In the post What Might a New @Deprecated Look Like?, I used the description of JEP 277 ("Enhanced Deprecation") at that time to guide the creation of an enhanced customized @Deprecated annotation. Since that post, however, there have been significant changes made in JEP 277. This post summarizes the changes and the currently planned enhancements to @Deprecated that are slated for JDK 9.
The changes made to JDK-8065614 ("JEP 277: Enhanced Deprecation") on 2016-03-03 18:04 remove the portion of the JEP description that described the proposed @Deprecated enum. The "Alternatives" section of the main JEP 277 page documents why the enum was removed:
I am in the process of migrating a few modules that are dependent on Apache XMLBeans to JAXB. It has been an exciting and challenging few days. I thought of jotting down a few important things I came across for anyone who might find it useful in the future.
First of all, let us look at setting up the maven plugin for the JAXB code generation. As of the time of writing this post, I came across two maven plugins. I ended up using the first one as I found the configuration to be quite straightforward.
At Stormpath, we take quality and productivity very seriously. As any good craftsmen already knows, having talent is not enough, you also need the right tools for the job. Engineering isnâ€™t just a science, itâ€™s also an art, so although we undoubtedly have talent (wink wink) at Stormpath, we always look to supplement with the tool that best fits our needs. Our engineers are always eager to share new tools with the rest of the team. And now, with all the other talented Java developers out there!
In this post, Iâ€™ll share the tools that our Java SDK team uses for daily tasks, how we use them, and hopefully, share a few tips that will be useful for you.