Java 8 Arrives

RSS

Java 8 is out the gate. It’s big step forward for embedded applications, and a few of its many new features stand out. First is the simplification and unification of the different versions of Java. There is now just Java SE and Java ME, and they are the same versions. Also, Java ME is a proper subset of Java SE.

Java ME now incorporates connected limited device configuration (CLDC), the Generic Connection Framework (GCF), and the Java ME Embedded Profile (MEEP). Even Java SE can fit onto smaller platforms like a microcontroller with 16 Mbytes of RAM and 10 Mbytes of flash.

Next is the inclusion of lambda expressions in the Java language. I used lambda expressions in Lisp, and Java is not in the same league. Lambda expressions in Java are a definite plus, though. A lambda expression is essentially a nameless function. Many applications require a callback function, which allows a programmer to define inline, typically as an argument in a method call.

Download this article in .PDF format
This file type includes high resolution graphics and schematics when applicable.

Lambdas use the -> operator with the argument list on the left and a function body on the right as in:

(String s) -> { System.out.println(s); }

This is a function with a single string argument that prints out the value. Lambdas make a functional programming style easier. They are also handier for embedded applications that use functional arguments. The underlying system has been enhanced to improve support for these new features.

Lambdas play well with another enhancement in Java 8, streams. Java 8’s stream application programming interface (API) specifies a set of interface methods that allow code like this:

List<Block> blocks = /* … */

int total = blocks.stream()
                          .filter(b -> b.GetValue() > 100)
                          .sum();

In this example, the blocks list provides a stream object that has its elements filtered and then added together. Methods like filter return a stream that while sum returns a value. The type of the lambda argument for filter is inferred. Inferred types are another enhancement that is useful in almost any context. The argument parentheses for the lambda parameter are also not required since there is a single argument. The lambda body assumes the block element value is obtained using the GetValue method. All the elements whose value is over 100 will be added together.

Type annotations are a new addition that can be used anywhere a type is needed in Java code. For example, one might want to make sure a variable was never set to a null value. The variable must always reference an object. This is what a String definition would look like.

@NonNull String myString;

This is just a simple example. The type annotations can also apply to more complex type definitions. Java does not have a type checking framework, but Java 8 supports pluggable checkers that can do that job. Static analysis tools can do more, though improved type checking can help keep bugs out of code.

Java JVMs can run other programming languages like Groovy and Scala (see “If Your Programming Language Doesn’t Work, Give Scala A Try” at electronicdesign.com). Java 8’s Nashorn Javascript engine adds Javascript to the mix. Javascript has been used a lot on the Web, and it is a completely different language from Java. There are probably more Javascript programmers than Java programmers, but now both can take advantage of Java 8.

Java is yet another language that takes aim at the Internet of Things (IoT). Its advantage is its wide range of communication and middleware that comes as part of it. The SE/ME spread also means sensors can use the lightweight Java ME, and higher-end applications can run Java SE systems. Other useful features include an upgraded date and time API, which was needed to address international date and time issues that were not handled well in earlier versions of Java.

The JavaFX 8 graphics toolkit now includes an embedded graphics stack. The toolkit also now handles HTML5, adds many new user interface controls, and improves 3D support.

Discuss this Blog Entry 3

on Apr 7, 2014

Thanks, I'm studying java now and the article gave me a birds eye view of the topic. All this time I thought java and javascript were the same. Very helpful and up to date content.

I also liked mr. wong's article on robots. Very informative and is worth checking out (its an article though, not a blog post)

on Apr 10, 2014

I understand what you bring to it really very useful and interesting, thank you

on Apr 11, 2014

What sort of advanatage over Java SE???

Newsletter Signup

Please or Register to post comments.

What's alt.embedded?

Blogs focusing on embedded, software and systems

Contributors

William Wong

Bill Wong covers Digital, Embedded, Systems and Software topics at Electronic Design. He writes a number of columns, including Lab Bench and alt.embedded, plus Bill's Workbench hands-on column....
Commentaries and Blogs
Guest Blogs
Nov 11, 2014
blog

How to Outsource Your Project to Failure 3

This article will address failure to carefully vet a potential manufacturing or “turnkey” partner and/or failure to transfer sufficient information and requirements to such a partner, a very common problem I have seen again and again with my clients over the years, and have been the shoulder cried upon by several relatives and clients in the past....More
Nov 11, 2014
blog

Transition from the Academe to the Industry Unraveled 1

There have been many arguments here and there about how short-comings of universities and colleges yield engineers with skill sets that do not cater to the demands of the industry. There have been many arguments here and there about an imminent shortage of engineers lacking knowledge in the sciences. There have been many arguments here and there about how the experience and know-how of engineers in the industry may vanish due to the fact that they can’t be passed on because the academic curriculum deviates from it....More
Nov 11, 2014
blog

Small Beginnings 5

About 10 years ago I received a phone call from an acquaintance. He had found a new opportunity selling some sort of investments and he wanted to share it with me in case I was interested. Ken had done fairly well for many years as a contract software developer primarily in the financial services sector. His specialty was writing RPG code. (RPG is often referred to as a write only language.) But he was seeing the handwriting on the wall as the industry moved on to other methods, and saw himself becoming a fossil....More

Sponsored Introduction Continue on to (or wait seconds) ×