//table of contents /

05 28 66 COMMUNITY FROM SMART ME 8 AND GRIDS TO THE INTERNET JAVA 8: JAVA MICROBREWS OF THINGS V2COM uses Java to Top features of EXPLORE THE connect millions of Java ME 8 POSSIBILITIES intelligent devices. JAVA IN ACTION From embedded to the cloud, get there with Java 8.

Java 8 Is Here JAVA TECH New theme icon. See how it works.

COMMUNITY JAVA TECH 50 62 03 33 Java Architect Embedded From the Editor New to Java Processing Data with JavaFX and Near 15 How to Become an Java SE 8 Streams Field Communication Java Nation Embedded Developer Use stream operations to on the Raspberry Pi ABOUT US News, people, books, in Minutes express sophisticated data Use your Java skills to create and events Jump into programming processing queries. end-to-end applications that the next big thing using 56 span card readers on embedded 23 embedded Java. devices to back-end systems. JCP Executive Series Java Architect Q&A with Goldman Sachs 41 JSR 308 Explained: 69 John Weir and Donald Raab New to Java Java Type Annotations Polyglot discuss the impact of Three Hundred Sixty– The benefits of type annotations Take Time to Play lambda expressions. Degree Exploration and example use cases Learn how to take advantage of Java EE 7 of the client tier. Part 3 in our series 75 on Java EE 7 Fix This blog Take our concurrency code challenge!

COVER ART BY I-HUA CHEN 01

ORACLE.COM/JAVAMAGAZINE /////////////////////////////////////////// MARCH/APRIL 2014 EDITORIAL PUBLISHING Editor in Chief Vice President Caroline Kvitka Jeff Spicer COMMUNITY Community Editors Publisher Cassandra Clark, Sonya Barry, Jennifer Hamilton +1.650.506.3794 Yolande Poirier Associate Publisher and Audience Java in Action Editor Development Director Michelle Kovac Karin Kinnear +1.650.506.1985 Technology Editors Janice Heiss, Tori Wieldt ADVERTISING SALES President, Sprocket Media Contributing Writer Kyle Walkenhorst +1.323.340.8585 Kevin Farnham Western and Central US, LAD, and Contributing Editors Canada, Sprocket Media Claire Breen, Blair Campbell, Karen Perkins Tom Cometa +1.510.339.2403 IN ACTION JAVA DESIGN Eastern US and EMEA/APAC, Senior Creative Director Sprocket Media Francisco G Delgadillo Mark Makinney +1.805.709.4745 Senior Design Director Advertising Sales Assistant Suemi Lam Cindy Elhaj +1.626.396.9400 x 201 Design Director Mailing-List Rentals Richard Merchán Contact your sales representative.

Contributing Designers RESOURCES TECH JAVA Jaime Ferrand, Arianna Pucherelli Oracle Products Production Designers +1.800.367.8674 (US/Canada) Sheila Brennan, Kathy Cygnarowicz Oracle Services +1.888.283.0591 (US) Oracle Press Books oraclepressbooks.com

ARTICLE SUBMISSION ABOUT US If you are interested in submitting an article, please e-mail the editors. SUBSCRIPTION INFORMATION Subscriptions are complimentary for qualified individuals who complete the subscription form. MAGAZINE CUSTOMER SERVICE [email protected] Phone +1.847.763.9635 PRIVACY Oracle Publishing allows sharing of its mailing list with selected third parties. If you prefer that your mailing address or e-mail address not be included in this program, contact Customer Service.

Copyright © 2014, Oracle and/or its affiliates. All Rights Reserved. No part of this publication may be reprinted or otherwise reproduced without permission from the editors. JAVA MAGAZINE IS PROVIDED ON AN “AS IS” BASIS. ORACLE EXPRESSLY DISCLAIMS ALL WARRANTIES, WHETHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ORACLE BE LIABLE FOR ANY DAMAGES OF ANY KIND ARISING FROM YOUR USE OF OR RELIANCE ON ANY INFORMATION PROVIDED HEREIN. The information is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied blog upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. Oracle and Java are registered trademarks of and/or its affiliates. Other names may be trademarks of their respective owners. Java Magazine is published bimonthly with a free subscription price by Oracle, 500 Oracle Parkway, MS OPL-3C, Redwood City, CA 94065-1600. Digital Publishing by GTxcel 02

ORACLE.COM/JAVAMAGAZINE /////////////////////////////////////////// MARCH/APRIL 2014 //from the editor / COMMUNITY

FIND YOUR JAVA IN ACTION hange is good—when it comes with benefits. In the case of Java 8, those benefits come in the JUG HERE form of more productivity for developers plus expanded opportunities to develop applications that span from My local and global JUGs embedded devices to the cloud. Java 8 is here—you can download Java SE 8 today, while Java are great places to network

C JAVA TECH Java 8 ME 8 is available in Early Access form. We’ve dedicated most of this issue to Java 8—just look both for knowledge and work. Is Here My global JUG introduces for the theme icon for articles on this topic. me to Java developers all The biggest change in Java SE 8—what some have called the most significant upgrade to the Java program- over the world. ming language ever—is lambda expressions, or closures. “Lambda expressions are anonymous methods that Régina ten Bruggencate JDuchess provide developers with a simple and compact means for representing behavior as data,” explains Brian Goetz, Java language architect at Oracle. “In a few years, developers will wonder how they ever lived without [them].” LEARN MORE ABOUT US There’s plenty more to get excited about, including Nashorn, a next-generation JavaScript engine; Compact Profiles, which offer a convergence of the Java ME Connected Device Configuration (CDC) product with Java SE 8; and a new date and time API. You, the Java community, also played a huge role in bringing Java 8 to fruition. We examine all that and more in our Java 8 cover story. In “Java ME 8 and the Internet of Things,” we explore the new features that make //send us your feedback / Java ME 8 a comprehensive platform for connected devices. And if you’re ready to get We’ll review all going with embedded development, Angela Caicedo shows you how. suggestions for future improvements. This issue is jam-packed with information to get you started with Java 8 (including Depending on volume, articles on streams and type annotations). So go on . . . embrace change and explore some messages may the possibilities. Let us know where you take Java 8. not get a direct reply. blog

Caroline Kvitka, Editor in Chief BIO

PHOTOGRAPH BY BOB ADLER 03

ORACLE.COM/JAVAMAGAZINE /////////////////////////////////////////// MARCH/APRIL 2014

COMMUNITY

1. LAMBDA EXPRESSIONS 2. NASHORN AND JAVASCRIPT 3. COMPACT PROFILES JAVA IN ACTION JAVA 4. DATE AND TIME API EXPLORE THE 5. JAVAFX 8 POSSIBILITIES 6. COMMUNITY INVOLVEMENT JAVA 7. JAVA ME 8 TECH JAVA 8. JAVA SE 8 AND THE JVM ABOUT US

Java 8 From embedded to the cloud, get there with Java 8. Is Here

BY TIMOTHY BENEKE ava 8, which encompasses both Java SE 8 and Java ME 8, might be the most significant expan- sion of the Java platform yet. JLambda expressions and the Stream API increase the expres- sive power of the platform and blog make it easier for developers to take advantage of modern, multicore processors. Compact Profiles in Java SE 8 allow developers to use just ART BY I-HUA CHEN 05

ORACLE.COM/JAVAMAGAZINE /////////////////////////////////////////// MARCH/APRIL 2014 COMMUNITY

a subset of the platform, 1 and are a significant step toward the convergence of Java SE and Java ME. Java ME 8 itself, meanwhile, has JAVA IN ACTION JAVA been updated to include more-recent Java Virtual LAMBDA Machine (JVM), language, and library features while retaining the focus on small EXPRESSIONS embedded devices. Java 8 allows developers to apply TECH JAVA the same skill set across Lambda expressions are at the over behavior. As Goetz explains, readability, and performance.” a wide range of scenarios, heart of Java SE 8. “Lambda “If we want to model a workflow According to Goetz, the typical from the smallest embed- expressions, also known as clo- such as ‘do A before you start, do developer’s initial experience with ded Internet of Things (IoT) sures, are anonymous methods B for every file in this group, do C lambda expressions is likely to be devices to enterprise serv- that provide developers with a if you encounter an error, and do through the powerful new APIs

ers in the cloud. simple and compact means for D when you’re done,’ for manipulating ABOUT US As Mark Reinhold, chief representing behavior as data,” we don’t have ideal collections. Business architect of the Java Platform explains Brian Goetz, Oracle’s tools for express- “This is the most logic typically is full Group at Oracle, put it, “Java Java language architect and ing the behaviors A significant upgrade of ad hoc query-like 8 is the first truly revolution- Specification Lead for JSR 335, through D, and this of the Java calculations over ary release we’ve done in a Lambda Expressions for the Java affects the sort of collections; the core very long time.” Programming Language. “This APIs we design. We programming model libraries now make Here, we take a look at enables the development of have to break up ever. In a few years, it easier to express eight key pieces of Java 8. libraries that do a better job of the phases of the the “what” of such abstracting over behavior, which workflow, and the developers will a query without in turn leads to more-expressive, client code has to be wonder how they getting bogged less error-prone code.” directly involved in ever lived without it. down in details While Java has always provided each phase, rather about the “how.” blog reasonable tools such as classes, than saying ‘here’s I certainly do!” The other major inheritance, and generics for what I want; go do —Brian Goetz, Java language feature of abstracting over data, Java SE 8 it.’ This negatively Language Architect, Oracle Java SE 8 is default provides new tools for abstracting affects reusability, methods, which PHOTOGRAPH BY TIM GRAY/GETTY IMAGES 06

ORACLE.COM/JAVAMAGAZINE /////////////////////////////////////////// MARCH/APRIL 2014 COMMUNITY SPOTLIGHT EASIER QUERIES ADOPT-A-JSR not simply a matter of AND CALCULATIONS COMMUNITY new syntax; there are WITH LAMBDAS some new concepts that JSR 335: Lambda developers will have to Java Language Architect which is good because Expressions for the Java learn just to be able to Brian Goetz shows how code that is easy to read read Java code, even if Programming Language Brian Goetz does a live the Java core libraries have also is more likely to be they do not plan to take hacking session on lambda been enhanced to enable correct,” says Goetz. ADOPTED BY: Jozi JUG expressions. advantage of these new

more-query-like calcula- This shift from hand- IN ACTION JAVA (Johannesburg, South features in the code they tions over collections. written loops to aggregate Africa), London Java write. There are also big enable interfaces to “Consider something like operations using lambdas additions to the core Community, and SouJava evolve over time. Default ‘find artists with albums and streams inverts the libraries that develop- (São Paulo, Brazil) methods are necessary that have fewer than eight control of the computa- ers will have to learn— for Java SE 8 given that tracks.’ This is easy enough tion. “With thefor loop, the WHAT: Jozi JUG organized but these costs should some core library classes, to write with a for loop, but client is in control at every be more than offset by TECH JAVA a Java 8 hackathon and such as Collections, are the resulting code is full step, asking the Iterator increases in productivity presented a talk on lambda more than 15 years old. of accidental detail about for the next element on and expressiveness.” expressions to its members. Without default meth- ‘how,’ which obfuscates the each iteration,” Goetz Goetz makes no effort ods, some core library ‘what,’” he says. In Java says. “With lambdas and to hide his enthusiasm London Java Community classes would be unable SE 8, it looks like this: streams, the library is in for lambdas: “I think this held three hackdays and to support lambdas. control, but still allows the is the most significant presented a “Lambdas: “More generally,” Set artists = computation to be easily ABOUT US upgrade of the Java pro- explains Goetz, “if you albums.stream() customized by the client.” Myths and Mistakes” talk gramming model ever— want libraries to stay .filter(album -> album. He goes on to explain, to 140 Java developers. and yet, it still feels like relevant over long peri- getTracks().size() < 8) “In the albums calculation the Java we know and SouJava held several ods of time, they need .map(album -> album. above, it might look like love,” he insists. “In a to be flexible, so we getArtist()) we’re doing three passes lambda expressions ses- few years, developers will needed to address this .collect(toSet()); on the data, but in fact the sions for its members wonder how they ever problem while maintain- three are fused into a single and evangelized Java 8, lived without it. I cer- ing our commitment to “Here, we’ve said ‘give pass. This is possible only tainly do!” Adopt-a-JSR, and the compatibility.” us the elements of albums, because the client was able JCP in Brazil, Colombia, When asked about the MORE ON LAMBDAS select the ones with fewer to express everything it and beyond. challenges Java devel- than eight tracks, for each wanted in one go, parame- • Project Lambda blog opers face in working of those get the artist, and terizing the steps with vari- with lambdas, Goetz • Lambda Expressions then collect them into a ous bits of behavior, rather is optimistic. “The big tutorial set.’ The code reads like than being involved in every challenge,” he says, “is • “Looking Ahead to the problem statement, loop iteration.” accepting that this is Project Lambda” 07

ORACLE.COM/JAVAMAGAZINE /////////////////////////////////////////// MARCH/APRIL 2014 COMMUNITY NASHORN AND 2 JAVASCRIPT IN ACTION JAVA

“Nashorn is a part of Java SE 8 that the wealth of libraries normally only is intended to provide a version of available to Java developers, and can JavaScript that would run as part implement portions of their applica- of the JVM—a more modern ver- tion in a simpler, lightweight pro- TECH JAVA sion of JavaScript using newer JVM gramming language. Developers can technologies,” observes Jim Laskey, now implement runtime dynamic engineering lead for multilan- features and bypass build cycles, guages at Oracle. With Java SE 8, while users and field engineers can Nashorn is being shipped as a javax make configuration changes without

.script engine embedded in the JDK, having to rebuild the application. ABOUT US which means that any Java applica- “Nashorn will allow JavaScript to tion can now contain components be used in ways that have not been written in JavaScript. JavaScript is available before,” he says. a popular language with features Laskey is quick to point out, similar to Java’s features that is “Although Nashorn JavaScript is not ideal for transmitting code across the same as browser JavaScript, and networks. In addition, there is now currently lacks DOM components, it a command-line tool (jjs) that is a full-featured programming lan- allows developers to use Nashorn guage with access to all of the avail- as a scripting tool. Nashorn, which able Java libraries.” replaces Rhino, also an open source “Nashorn will allow JavaScript to be used JavaScript engine, is both faster and in ways that have not been available before.” blog lighter and integrates JavaScript and MORE ON NASHORN —Jim Laskey, Engineering Lead for Multilanguages, Oracle Java more tightly. • Project Nashorn As a consequence, JavaScript • “Oracle Nashorn: A Next-Generation developers can take advantage of JavaScript Engine for the JVM” PHOTOGRAPH BY DAN CALLIS/GETTY IMAGES 08

ORACLE.COM/JAVAMAGAZINE /////////////////////////////////////////// MARCH/APRIL 2014 COMMUNITY “With the introduction of Compact Profiles, we now have a single Java SE standard with all of the productivity that Java is famous for that can truly scale from small embedded IoT devices to large enterprise server installations.” —Bob Vandette, Consulting Engineer, Oracle JAVA IN ACTION JAVA

much smaller than the full Java SE Java runtime environment (JRE), they enable applications to be deployed on platforms with limited storage.

The smallest of these runtimes is 11 MB, which is TECH JAVA more than four times smaller than the equiva- lent traditional JRE. Java SE applications can now be designed to run on resource-constrained devices by targeting the specific APIs that are available in Compact Profiles. The Compact Profiles were primarily ABOUT US designed for embedded developers who wish to use Java for the creation of embedded solutions with limited static and dynamic storage. By keep- ing the amount of RAM and flash to a minimum, the bill of materials (BOM) cost for embedded devices is also kept to a minimum, resulting in COMPACT PROFILES increased profit for device distributors. 3 Bob Vandette, consulting engineer at Oracle, sums it up: “With the introduction of Compact Compact Profiles, three well-defined API subsets For many years, embedded developers have Profiles, we now have a single Java SE standard of the Java 8 specification, offer a convergence wanted to allow subsetting of the Java SE plat- with all of the productivity that Java is famous of the Java ME Connected Device Configuration form in order to deploy smaller binaries in their for that can truly scale from small embedded IoT blog (CDC) with Java SE 8. With full Java 8 language embedded devices. Compact Profiles enable devices to large enterprise server installations.” and API support, developers now have a single the creation of applications that do not require specification that will support the Java ME CDC the entire platform to be deployed and run on MORE ON COMPACT PROFILES class of devices under the Java SE umbrella. small devices. Because Compact Profiles are • “An Introduction to Java 8 Compact Profiles” PHOTOGRAPH BY TIM GRAY/GETTY IMAGES 09

ORACLE.COM/JAVAMAGAZINE /////////////////////////////////////////// MARCH/APRIL 2014 4 DATE AND COMMUNITY TIME API COMMUNITY SPOTLIGHT Java SE 8 introduces a new java rency issues when ADOPT-A-JSR JAVA IN ACTION JAVA .time API with a fluent and famil- used in multitask- iar style that is easy to read and ing environments. JSR 310: Date and Time API write without the aid of IDEs. It In addition, the ADOPTED BY: Guadalajara provides excellent support for extensibility of the JUG (Guadalajara, Mexico), the international ISO 8601 time API enables the Jozi JUG (Johannesburg, standard that global businesses addition of new use and also supports the fre- calendars, units, South Africa), London Java TECH JAVA quently used Japanese, Minguo, fields of dates, and “The new java.time API will make Community, and SouJava Hijrah, and Thai Buddhist calen- times. Developers developers more productive, (São Paulo, Brazil) dars. Each of the new core Java can focus on completing a partic- KEY CONTRIBUTIONS: classes—for date, time, date ular task without being concerned whether they are using the global and time combined, time zones, about unrelated functions. date and time standards or one of Guadalajara JUG held a live

instants, duration, and clocks— The new API uses immutable date and time coding session. ABOUT US has a specific purpose and has values, with each computation the regional calendars.” Jozi JUG organized a hack- explicitly defined behavior with- producing a new value. With —Roger Riggs, Consulting Member out side effects. The types are immutable objects, an instance of Technical Staff, Oracle athon with more than 25 immutable to simplify concur- can be shared with a library or a participants. concurrent task without concern Calendar combine many functions London Java Community that the value will change unex- in each type, which often results pectedly, explains Roger Riggs, separated out technology in unexpected interactions that consulting member of the techni- compatibility kit (TCK) tests increase programming complex- cal staff at Oracle. This contrasts ity,” explains Riggs. “The new APIs versus implementation- with the current Date and Calendar offer greater clarity of purpose, specific tests. types that hold a mutable value ease of use, and maintenance.” and are not multithread safe. SouJava held several talks at blog Using immutable values elimi- their meetings and provided nates many problems for multi- MORE ON DATE AND TIME feedback to the JSR 310 Jim Gough of the London Java threaded programming. • Package java.time Expert Group. Community hacks on date and time. “The current APIs for Date and • “Java SE 8 Date and Time” PHOTOGRAPH BY TIM GRAY/GETTY IMAGES 10

ORACLE.COM/JAVAMAGAZINE /////////////////////////////////////////// MARCH/APRIL 2014 “JavaFX 8 is integrated with Java SE 8 and works well with lambda expressions. It simplifies many COMMUNITY kinds of code, such as event handlers, cell value factories, and cell value factories on TableView.” —Richard Bair, Client Java Architect, Oracle JAVA IN ACTION JAVA

nents, many of which can now work out of the box. All of the above will lead to enhanced pro- ductivity for JavaFX developers, he says.

Much progress has also been made on the TECH JAVA Mark Reinhold (left), performance front, largely due to the effort chief architect of the Java Platform Group at to bring JavaFX to embedded devices such as Oracle, and Richard Bair, the Raspberry Pi and Freescale i.MX 6 boards. client Java architect Increased 3-D support in JavaFX has opened at Oracle, talk about new opportunities for developers, with AMD JavaFX 8 and lambdas. contributing COLLADA importer functionality to OpenJFX, which is a lively and thriving ABOUT US community, Bair adds. “The new Scene Builder 2, the first Scene Builder actually built with Scene Builder, has an excellent CSS inspector, so developers can JAVAFX 8 better understand why things are styled as they 5 are,” explains Bair. It is also modular and can be embedded in any IDE. Scene Builder 2 works with FXML, an open and published format, so “JavaFX 8 is integrated with Java SE 8 and works In addition, says Bair, JavaFX 8 offers a pow- developers can hack the FXML file directly. well with lambda expressions. It simplifies many erful rich text node for the scene graph, and “I encourage everybody to download kinds of code, such as event handlers, cell value the Java community is fast at work on several JavaFX 8, try it out, and provide feedback blog factories, and cell value factories on TableView,” projects building rich text and code editors on to the team,” he adds. explains Richard Bair, client Java architect at top of this support. In addition, the default look Oracle. “It brings some much-requested new of JavaFX applications has been refreshed with UI controls and APIs such as TreeTableView and a new theme, called “Modena.” JavaFX 8 also MORE ON JAVAFX 8 APIs that enable modal dialogs.” offers increased support for third-party compo- • JavaFX 8 Overview PHOTOGRAPH BY BOB ADLER 11

ORACLE.COM/JAVAMAGAZINE /////////////////////////////////////////// MARCH/APRIL 2014 COMMUNITY

COMMUNITY IN ACTION JAVA 6 INVOLVEMENT

The Java community has been vital in the cre- standards as well. More than 26 JUGs have

ation of Java 8. It has provided ongoing feed- participated in the program. TECH JAVA back to Specification Leads, made requests for The (JCP), with its new Java functionality, uncovered bugs, con- enhanced openness and flexibility, has made tributed to code fixes, and much more. it easier for both organizations and individu- Java user groups (JUGs), which are centers als to contribute to the Java platform. “The of Java community learning and participation, JCP now has a much more transparent pro- have been essential. As Java Champion and cess,” says Souza. “It’s a lot easier for some- SouJava JUG Leader Bruno Souza explains, one to go to the JCP site and get involved. This ABOUT US “Java 8 has set a new standard of community increased transparency has made it easier for participation. There are Java user groups all the community to participate.” over the world running programs and providing feedback for the JCP “Java 8 has set a new standard of community specifications and being active in participation. There are Java user groups all over the OpenJDK.” The OpenJDK community is where developers collaborate on world running programs and providing feedback for the open source reference imple- the JCP specifications and being active in OpenJDK.” mentation of the Java SE platform. —Bruno Souza, Java Champion and SouJava JUG Leader The Adopt-a-JSR program, cre- ated to encourage JUG members, blog individuals, and other organiza- tions to get involved in JSRs, has resulted in increased grassroots and developer partici- SouJava’s Bruno Souza explains how community pation in not only Java 8 but other emerging participation has changed with Java 8.

PHOTOGRAPH AND VIDEO BY BOB ADLER 12

ORACLE.COM/JAVAMAGAZINE /////////////////////////////////////////// MARCH/APRIL 2014 7 JAVA ME 8 COMMUNITY “Java ME 8 is a major step in the convergence of Java ME and Java SE and the unification of the Java ecosystem.” —Terrence Barr, Senior Technologist and Product Manager, Oracle JAVA IN ACTION JAVA

“Java ME 8 is a major step in the iar platform, language, pro- convergence of Java ME and gramming model, and tools. TECH JAVA Java SE and the unification of With the embedded space the Java ecosystem, enabling and the fast-developing IoT Java developers to more eas- in a state of flux, Java ME 8 ily deploy their existing skills offers a flexible and scalable across a range of embedded development/deployment

devices, drawing upon the rich- environment. ABOUT US ness and portability of the Java See “Java ME 8 and the platform,” explains Terrence Internet of Things” in this Barr, senior technologist and issue for details. product manager at Oracle who focuses on the IoT and embed- ded technologies. “This results MORE ON JAVA ME 8 in a faster time to market, • Oracle Java ME Embedded 8 as well as cross-platform Early Access compatibility and embedded • Connected Limited Device device scalability.” Configuration 8 With the advent of Java ME 8, developers can take their exist- • Generic Connection blog ing skills and begin writing Framework 8 applications for the rapidly • Micro Edition Embedded developing realm of embedded Profile 8 devices—using the same famil- • Device Access API 8 PHOTOGRAPH BY TON HENDRIKS 13

ORACLE.COM/JAVAMAGAZINE /////////////////////////////////////////// MARCH/APRIL 2014 COMMUNITY SPOTLIGHT TAKE IT FOR A SPIN JAVA SE 8 TEST JAVA 8 COMMUNITY The Test Java 8 program All in all, Java 8 offers a new oppor- 8 tunity for enhanced innovation for was initiated by the London Java developers who operate on AND THE JVM Java Community as part of anything from tiny devices to cloud- the Adopt-a-JSR program. based systems. We can expect increases in developer productiv- “Java SE 8 offers an improved, member of the technical staff The aim of the program was IN ACTION JAVA ity and application performance more mature G1 garbage col- at Oracle. “G1’s basic design is for Java user group members through the reduced boilerplate lector. G1’s scalability is getting not changing, but incremental to help with testing Java 8 code and increased parallel pro- better, and more work is being improvements toward more- on several open source gramming that lambdas offer. Java 8 done concurrently,” explains dependable pause times have software projects prior to offers best-in-class diagnostics, Jon Masamitsu, principal been made in many areas. the launch of Java 8. with a complete tool chain to con-

More generally, in all the gar- TECH JAVA tinuously collect low-level and bage collectors the command- detailed runtime information. line flags are now more con- By bringing the advantages of sistent, with flag discrepancies Java SE to embedded development, corrected. This should make out of the permanent genera- developers can transfer their Java it easier for users to switch tion (which has been removed skills to fast-evolving new realms in among the different garbage entirely) and moved into native

the IoT, enabling Java to support any ABOUT US collectors and have the com- memory and/or the Java heap. device of any size. It is an exciting mand-line flags have a com- Previously, tuning the size of time to be a Java developer, so take it mon meaning where possible.” the permanent generation was for a spin, and tell us about the ride. In addition, Java SE 8 a tiresome, trial-and-error pro- removes the need to tune the cess. The maximum size of the permanent generation. The permanent generation had to MORE ON TOPIC: Java HotSpot VM’s internal rep- be set at startup, and there was Java 8 resentation of Java classes has no intuitive way to know how Is Here been re-engineered and moved large it should be. Developers need no longer guess about Timothy Beneke is a freelance writer “Java SE 8 offers an improved, more mature G1 a size for the permanent and editor, best known for his books generation. on gender. blog garbage collector. G1’s scalability is getting better, Finally, Java ME 8 has been updated with the JVM, the lan- DOWNLOAD JAVA 8 and more work is being done concurrently.” guage, and the libraries to be • Java SE 8 —Jon Masamitsu, Principal Member of Technical Staff, Oracle aligned with Java SE 8. • Java ME 8 PHOTOGRAPH BY BOB ADLER 14

ORACLE.COM/JAVAMAGAZINE /////////////////////////////////////////// MARCH/APRIL 2014 // java nation / IOUC Summit /

Clockwise: COMMUNITY The JCP’s Heather VanCura; Simon Ritter, Georges Saab, and Mark Reinhold field

questions IN ACTION JAVA about the Java platform; summit attendees engage during a session. JAVA TECH JAVA

More than 20 Java user group (JUG) leaders from all over the world attended the International Oracle ORACLE USER GROUP User Group Community (IOUC) Annual Summit ABOUT US January 21–23, 2014, in Redwood Shores, California. The IOUC is a community of leaders representing LEADERS’ SUMMIT Oracle user groups worldwide. User group leaders from all over the world, including more than 20 JUG leaders, attended the summit to learn about Oracle products and technologies, provide feedback to product groups, network, and share best practices. The unofficial kickoff to the Java track was a Brazilian barbecue at the home of Stephen Chin, a Java evangelist at Oracle. Bruno Souza, leader of SouJava in Brazil and a member of the Java blog Community Process (JCP) Executive Committee, acted as executive chef, manning the barbecue for hours after just stepping off a flight from Brazil. The official Java track began the following day, PHOTOGRAPHS BY BOB ADLER 15

ORACLE.COM/JAVAMAGAZINE /////////////////////////////////////////// MARCH/APRIL 2014 //java nation / IOUC Summit //

powering small devices.

HOT TOPIC: The panel also dis- COMMUNITY cussed the challenges of IoT. Chin asked, “How INTERNET many people have a wire- less router at home?” and many hands went up. But OF THINGS when he asked how many

people had updated IN ACTION JAVA Clothes that monitor your baby’s vital signs. their router firmware Prescription medicine bottlesthat remind you in the last six months, to take your pills (and can tell others when you most hands dropped. don’t). Wind turbines that turn themselves With more devices come Summit attendees have a healthy discussion over lunch. on in anticipation of high energy usage. Traffic more software, more

lights that adjust to traffic conditions. Trash management, and more TECH JAVA cans that send a text when they are full. These vulnerability. Security is with a session on the future with the JCP and JSRs, a real issue, especially for of Java. Oracle’s Mark including the Adopt-a-JSR are all examples of the rapidly growing world devices and industries Reinhold, Georges Saab, program. “Adopt-a-JSR has of the Internet of Things (IoT). There is a lot that haven’t had to con- Henrik Stahl, and Simon been a great push and has of interest in this topic, so it wasn’t surprising sider it before. And it’s Ritter hosted an interactive put the JCP back in the spot- that the Internet of Things session was full at not you get hacked, but discussion of what’s next light,” said VanCura. “There the IOUC Summit. if . “One good thing ABOUT US for the Java EE, Java SE, and is more interest from JUGs, when Oracle’s Sharat Things. Most computers about Java in the IoT Java ME platforms (beyond more people are involved, Chander assembled a already talk to a “back space,” Suri commented, Java EE 7, Java SE 8, and Java and there are more discus- panel of experts to dis- end,” so what makes IoT “is that it provides a level ME 8). Topics included the sions.” One way that many cuss IoT: Bruno Souza, different? “IoT makes of abstraction that allows Internet of Things, big data, JUGs are involving their SouJava president computers invisible,” for better security and Project Sumatra, OpenJDK, members is through hack- and Java Community Souza explained. “They quicker updates. That’s alternative languages for the athons. Badr Elhouari of the Process (JCP) Executive are everywhere and all especially important in , mod- Morocco Java User Group Committee member; connected. You don’t devices that are out in the ularity, adoption of the Java said that getting a hack- Stephen Chin and Jai Suri think of your refrigera- field for years.” platform, and more. athon going is easy. “Have a of Oracle; Ian Ferguson tor as a computer.” Suri Whatever it is, IoT is In a session on JUGs and speaker,” he said, “and then of ARM; and Richard talked about the mul- coming fast. New applica- the JCP, Heather VanCura do a hands-on activity at blog Niemiec, Midwest Oracle titude of devices and tions are happening daily. and Patrick Curran of the JCP your JUG meeting.” Users Group leader. networks involved, the The coolest IoT innova- led a discussion about how Other topics of discus- The panel started by challenge of data in many tion hasn’t even been JUGs can be more involved sion were barriers to par- defining theInternet of different formats, and thought of yet. PHOTOGRAPH BY BOB ADLER 16

ORACLE.COM/JAVAMAGAZINE /////////////////////////////////////////// MARCH/APRIL 2014 //java nation / IOUC Summit //

GAMIFICATION FOR COMMUNITY USER GROUPS At the Gamification session at the IOUC Summit, user group lead- ers discussed how to drive mem- IN ACTION JAVA bership. Typically, they give away software licenses, books, and goodies to encourage attendance at monthly meetings. Others have used gamification to get their communities to brainstorm on TECH JAVA SouJava’s Bruno Souza (center) grilled up a traditional Brazilian ArabOUG Leader Mohamed Chargui talks feast to welcome Java user group leaders to the summit. mascot names, or post pictures about his experience using gamification. and comments on social media. ticipation in the JCP for those to promote experimenta- Hackathons also require the use of who don’t speak English and tion. By participating in the similar techniques to keep attendees motivated to create applications over ways to work around this; Adopt-a-JSR program, said several days. SouJava Leader Bruno Souza said that his Java user group (JUG) successfully ran hackathons that combined brainstorming, team building, lack of awareness of the JCP; SouJava’s Souza, your mem- ABOUT US and complexity in getting bers will feel like they are training, hacking sessions, and prizes to keep participants engaged. involved. However, Adopt- participating and they will Gamification lets you turn life into a game, said Houston JUG LeaderJim a-JSR is helping to lower the learn more about Java. Bethancourt. The key advantages are driving audience engagement, mak- barriers to participation and Other session topics dur- ing the user experience more enjoyable, and getting users to come back. ing the summit The forum platform Stack Overflow is a great example of running a thriv- included gamifi- ing community of developers with its point systems, he said. Contributors cation, managing get rewarded with points for their useful entries, and visitors easily find the your community, most-relevant and best-rated entries. getting the most The ArabOUG has implemented a point system to keep its community out of Java.net, and active. The group gives out points to its members, who contribute applica- feedback about tions, articles, and translations. It partnered with training organizations and blog JavaOne. other services to give its members free training and services in exchange for points. As a result, members don’t have to pay for services using online payments, which governments in many countries in North Africa and the Java user group leaders share their reasons for attending the summit. Middle East don’t allow.

PHOTOGRAPH COURTESY OF STEPHEN CHIN; VIDEO BY BOB ADLER 17

ORACLE.COM/JAVAMAGAZINE /////////////////////////////////////////// MARCH/APRIL 2014 //java nation / COMMUNITY

IoT Developer Challenge IN ACTION JAVA From March 3 to May 30, 2014, Oracle Technology Network is hosting an Internet of Things (IoT)

Developer Challenge. Open TECH JAVA to online submissions, the HACKING AT challenge gives developers the chance to submit an innovative, ground- CAMPUS PARTY breaking, business-ready IoT project using embedded Java and any hardware, whether it Brazilian Java user group SouJava ran a is computer boards such as the Raspberry Pi,

Raspberry Pi and Java hackathon from ABOUT US sensors, or other IoT technologies. Members of January 30–February 1, 2014, at Campus Clockwise from top left: Duke is ready to hack; winning teams will each receive a JavaOne 2014 Party, the weeklong technology gathering Yara Senger welcomes participants; hackers pass, plus up to US$2,000 for flight and hotel of geeks, developers, gamers, scientists, work on their projects. expenses. A student category with prizes is also and students in Brazil. Sponsored by Oracle available, thanks to Oracle Academy. Technology Network, the hackathon was During the challenge period, Oracle Tech- designed for enthusiasts who wanted to cre- ects. Onsite experts were available to help nology Network will offer free online training ate Internet of Things (IoT) projects with the participants. These veteran Java developers on IoT, the Raspberry Pi, embedded Java, and Raspberry Pi and Java. The objectives were for of web, enterprise, and embedded develop- more. By registering, you will enter a chance to attendees to learn, practice, and innovate. ment included GlobalCode Founder Vinicius win a Raspberry Pi. Oracle Java evangelist Angela Caicedo Senger, Senior Developer at Vitae Futurekids opened the hackathon with an overview of Brazil Rubens Saraiva, SouJava Leader Bruno blog IoT and Java development. Over three days, Souza, Java Champion Yara Senger, Oracle participants formed teams, brainstormed, Product Manager Bruno Borges, and Senior attended training, received a kit from the Mobile Developer at Mobilidade é tudo organizers, and hacked on their own proj- Ricardo Ogliari.

PHOTOGRAPHS COURTESY OF SOUJAVA ART BY I-HUA CHEN 18

ORACLE.COM/JAVAMAGAZINE /////////////////////////////////////////// MARCH/APRIL 2014 //java nation /

JAVA CHAMPION PROFILE COMMUNITY FEATURED JAVA USER GROUP HOWARD LEWIS SHIP

doing payrolls for his invoicing, inventory, interested to see how JUG Münster CPA business. It came accounts payable, people are using my with a “Battleship” and accounts receiv- open source projects. Java User Group Münster was game you played by able business suite. It is fascinating that so formed in December 2008 printing the map on An early programming much innovative work by Thomas Kruse and Gerrit the line printer and accomplishment was happens in smaller IN ACTION JAVA Grunwald (inset), who continue entering shots using developing an auto- cities, not just the to lead the group today. Howard Lewis Ship is the keyboard. matic zip-code-to- larger technology cen- Münster’s geographic loca- a Java EE and Java Magazine: What UPS-zone lookup that ters. It’s everywhere! tion posed some challenges developer, author, was your first com- saved my Dad’s order Java Magazine: What as the Java user group (JUG) was getting blogger, and speaker. puter and program- entry team lots of time are you looking for- started. Münster is only about 50 km away The creator of the ming language? and tedious effort. ward to? TECH JAVA from Germany’s populous Ruhr area, which Apache Tapestry open Ship: I had access to Java Magazine: What Ship: It will be inter- has some long-established larger JUGs that source web frame- our high school’s PDP- do you enjoy for fun esting to see the func- included members from the Münster area. work, he became a 11 when I was in junior and relaxation? tional programming Nevertheless, the JUG continued to meet; Java Champion in high. I started out Ship: I have a four- aspects of Java SE 8 go Kruse and Grunwald continued spreading the February 2010. by entering and run- year-old and a one- mainstream. For some word; and JUG Münster’s membership steadily Java Magazine: Where ning BASIC code from year-old, so fun and developers, it will open ABOUT US grew to the current level of 280 members. did you grow up? David Ahl’s BASIC relaxation are mostly their eyes to the limi- JUG Münster has had an active meeting Ship: I grew up Computer Games. I “something I used tations that have been and events schedule from the start. “Since we south of Boston, also experimented to do.” I enjoy skiing, around them. I fear, started in 2008, we’ve met every two weeks for Massachusetts, and with Pascal and Logo photography, read- though, that for many a so-called ‘Java Roundtable,’” says Grunwald. got my CS degree at on an Apple, and even ing, flying stunt kites, others it will mostly “In addition, we arrange 10 events each year Worcester Polytechnic wrote some games and playing board and provide a new way to where we invite external speakers; and we have Institute. that had a smidgen of card games. do things wrong. an annual event for Software Freedom Day.” Java Magazine: When 6502 assembly code. Java Magazine: What But what I’m really Developers who come to Java after having did you first become Java Magazine: What “side effects” of your looking forward to worked with other languages are often sur- interested in comput- was your first profes- career do you enjoy is the kids being old prised by Java’s community aspect. “Java is not ers and programming? sional programming the most? enough to take care a young language/environment anymore, but Ship: My dad bought job? Ship: I love to speak at of themselves in the blog still has the greatest community that I know, a Burroughs B800 Ship: I helped my conferences and see morning, so that I can and one reason for this is the Java user groups… computer, a beast dad after school, the work people are sleep in every once in so let’s keep this alive,” says Grunwald. I called “HAL,” for customizing an doing. I’m especially a while. 19

ORACLE.COM/JAVAMAGAZINE /////////////////////////////////////////// MARCH/APRIL 2014 //java nation /

THE JAVAFX ANDROID COMMUNITY COMMUNITY PROJECT Vos blogged about the project’s their applications on Android, which background, present, and future in is very cool.” IN ACTION JAVA the post “JavaFX and Android.” There The JavaFX Android Community he notes that with respect to porting Project currently has 4 active software to unsupported platforms, developers. About 20 developers “developers are usually better in have contributed feedback that JUG doing it themselves than in com- has resulted in patches and new plaining. With the JavaFX code being code. But, as the project’s task list Tour TECH JAVA open-sourced over the past years, and reveals, there’s a lot more work to Oracle Technology with lots of work already being done do. So, the project is actively seeking Network is hosting by Oracle people, a community effort broader participation. a Java user group for porting JavaFX to mobile platforms “All contributors are very wel- (JUG) tour follow- turned out to be a viable option.” come,” Vos says. “Tool support is ing the launch of You can findinstructions for high on our list. People who can Java 8. Events will be ABOUT US building and deploying JavaFX help with integrations with IDEs and held at JUGs across The JavaFX Android Community applications on the Android plat- packaging tools are very welcome. the globe, with Java Project seeks to make JavaFX code form on the project site. The proj- Also, native Android developers are evangelists and Java runnable on Android devices. The ect’s source code is available in very much appreciated, especially Champions talking project was started by Johan Vos the Bitbucket android-graphics-rt people with feedback on how to about key features in (@johanvos) after he talked with repository. You can download a complete the last mile toward send- Java 8. Follow @java JavaFX architect Richard Bair prebuilt JavaFX Android runtime, or ing an application to the Play store. for more information. (@richardbair) at Devoxx 2013. The you can build it yourself. Developers with Gradle knowledge project got off to a fast start due to The project has come a long way are also very welcome.” work that Oracle’s Tomáš Brandalík in a relatively short time. In his blog, If you’d like to contribute to the had already done on the native parts, Johan says, “Most of the JavaFX JavaFX Android Community Project, and the Java 7 backport maintained 8 Ensemble applications are now visit the JavaFXAndroid Google blog by Stefan Fuchs. “After only a few working out of the box on Android Group, or contact Vos. weeks, we delivered a JavaFX runtime devices. I’ve seen many reports from for the Android platform,” says Vos. JavaFX developers demonstrating

PHOTOGRAPH BY TON HENDRIKS 20

ORACLE.COM/JAVAMAGAZINE /////////////////////////////////////////// MARCH/APRIL 2014 //java nation /

4Developers GeeCON 2014 APRIL 7 MAY 14–16 WARSAW, POLAND KRAKOW, POLAND COMMUNITY 4Developers is a technical confer- With its motto “Let’s move the Java ence intended for developers, archi- world,” the conference focuses on tects, testers, coders, team leaders, Java technologies, dynamic lan- project managers, IT departments, guages, rich internet applications, as well as all IT students. The event is enterprise architectures, patterns, designed for both professionals and distributed computing, software

Paris, France IN ACTION JAVA amateurs working in different tech- craftsmanship, and more. nological fields. JEEConf Great Indian Developer Summit MAY 23–24 (GIDS) KIEV, UKRAINE APRIL 22–25 JEE is the largest developer con-

BANGALORE, INDIA ference in Ukraine. It focuses on TECH JAVA Twenty-five thousand develop- Java technologies for application ers are expected at this four-day development. conference. At the dedicated Java track, top experts Stephen Chin, Devoxx UK Venkat Subramaniam, Erik Hatcher, JUNE 12–13 Kito Mann, Pratik Patel, and oth- LONDON, ENGLAND

ers will talk about Java 8, lambdas, Devoxx UK is part of the Devoxx fam- ABOUT US InvokeDynamic, the Raspberry Pi, ily of conferences. Run by the local EVENTS JavaFX, and more. Java community, this developer con- ference consists of a packed sched- Devoxx France APRIL 16–18 JAX 2014 ule of presentations, hands-on labs, PARIS, FRANCE MAY 12–16 quickies, and Birds-of-a-Feather MAINZ, GERMANY (BOF) sessions. Top local and inter- Now in its third year, Devoxx France brings together 1,500 Java This conference on Java and the national speakers present an array enthusiasts in an adrenaline rush of technical content, training, enterprise focuses on current and of Java topics on web, mobile, Java and community networking. The conference focuses on Java, web future trends in web, Android, soft- Virtual Machine languages, agile, technologies, mobile, cloud, agile, Java Virtual Machine languages, ware architecture, cloud, agile man- and more. and entrepreneurship. This year’s theme, “Born to Be,” is about agement methods, big data, and blog being and becoming a developer. more. More than 180 speakers will present 230 talks and 20 day-long sessions on Java 8, Java EE, JavaFX, embedded Java, Java core, and agile. PHOTOGRAPH COURTESY OF WILHELM LAPPE ON FLICKR 21

ORACLE.COM/JAVAMAGAZINE /////////////////////////////////////////// MARCH/APRIL 2014 //java nation /

JAVA BOOKS COMMUNITY JAVA IN ACTION JAVA

JAVA SE 8 FOR THE REALLY JAVA 8 LAMBDAS JAVA: THE COMPLETE JAVA FOR DUMMIES, NightHacking IMPATIENT By Richard Warburton REFERENCE, NINTH EDITION 6TH EDITION By Cay S. Horstmann O’Reilly (April 2014) By Herbert Schildt By Barry Burd Tour Addison-Wesley Professional If you’re an experienced Oracle Press (April 2014) Wiley (March 2014) JAVA TECH JAVA Java Evangelist Stephen (January 2014) Java programmer, Java 8 In Java: The Complete In this update of a best- Chin is making his way Author of Core Java Lambdas shows you Reference, Ninth Edition, selling book, veteran across Europe—visiting and internationally how to make use of your Herbert Schildt uses the author Barry Burd shows Java user groups, con­ renowned Java expert existing skills to adapt clear, concise, uncom- you how to create basic ducting interviews, and Cay S. Horstmann con- your thinking and your promising style that has Java objects and clearly broadcasting it all. Chin cisely introduces Java codebase to use lambda made the previous eight explains when you should SE 8’s most valuable new will be talking with com- expressions properly. editions so successful simply reuse existing code. ABOUT US munity experts about Java features (plus a few Java Starting with basic exam- worldwide. This compre- He explores how Java SE 8 8, the community, the SE 7 innovations that ples, this book is focused hensive volume covers the offers more-robust func- future of Java, the Internet haven’t gotten the atten- solely on Java SE 8 lan- entire language, including tionality and new features of Things, and more. Join tion they deserve). If you’re guage changes and related its syntax, keywords, and such as closures to keep him at an event or watch an experienced Java pro- API changes. Lambdas fundamental program- Java competitive with more his sessions online at grammer, Horstmann’s make a programmer’s job ming principles. Schildt syntax-friendly languages nighthacking.com. practical insights and easier, and this book will also presents detailed like Python and Ruby. He sample code will help you teach you how. Coverage information about Java’s also covers object- quickly take advantage includes introductory core libraries and key oriented programming of these and other Java syntax for lambda expres- programming techniques. basics with Java, code language and platform sions, method references Of course, coverage of new reuse, the essentials of improvements. that allow you to reuse features added by Java creating a Java program blog existing named methods SE 8, such as lambda using the new JDK 7, creat- from your codebase, and expressions and modules, ing basic Java objects, and the collection library in is included. new features. Java SE 8. 22

ORACLE.COM/JAVAMAGAZINE /////////////////////////////////////////// MARCH/APRIL 2014 Goldman Sachs’ Donald Raab (left), manager of the JVM

Architecture team, COMMUNITY and John Weir, global head of Application Platforms, talk at the company’s New York City office. JAVA IN ACTION JAVA TECH ABOUT US

JCP Executive Series Java 8 Is Here

Goldman Sachs’ GS Collections ohn Weir is the global head of Application Platforms at Goldman JSachs. In 2011, Goldman Sachs was Leverages Lambdas elected to the Executive Committee of the Java Community Process (JCP), with Goldman Sachs’ John Weir and Donald Raab discuss the creation of GS Collections, Weir as the firm’s representative. He blog the impact of Java SE 8’s lambda expressions, and how their work interacts with previously represented Goldman Sachs the JCP. BY STEVE MELOAN on the FpML Standards Committee for Credit Derivatives and was also on the PHOTOGRAPHY BY LAURA BARISONZI/GETTY IMAGES FpML Architecture Committee. He joined 23

ORACLE.COM/JAVAMAGAZINE /////////////////////////////////////////// MARCH/APRIL 2014 Goldman Sachs in 1997 and has held a and sometimes tens of thousands of COMMUNITY number of senior technology roles. He iteration patterns implemented with was named technology fellow in 2004 handwritten for loops. and managing director in 2008. Prior to Java SE 8, in the collec- Donald Raab manages the JVM tions space, there was no rich API. Architecture team, which is part of Developers had to re-create patterns the Enterprise Platforms group in the again and again. Our goal was to pro- Technology division at Goldman Sachs. vide a functional API that would reduce JAVA IN ACTION Raab serves as a member of the JSR 335 duplicate code by separating the Expert Group (Lambda Expressions for “what” from the “how” in a developer’s the Java Programming Language) and code. We also wanted to leverage paral- is one of the alternate representatives lelism using the fork/join library, allow- for Goldman Sachs on the JCP Executive ing developers to optimize performance Committee. He joined Goldman Sachs in across multiple processor cores. JAVA TECH 2001 as a technical architect on the PARA The API for GS Collections was heavily team. He was named technology fellow influenced by my experiences program- in 2007 and managing director in 2013. ming in Smalltalk, which had useful methods like select, reject, and collect. Java Magazine: Tell us about the genesis Over the years, we’ve added methods Raab: Internal iterators reduce errors Weir tackles a problem of GS Collections. When did you begin like flatCollect, groupBy, partition, and hide the implementation details on the whiteboard, while Raab looks on.

work, and what were your initial goals? and zip, which were influenced by of collections they’re operating across. ABOUT US Raab: GS Collections began in 2004 as our experiences with languages like They relieve the developer from the a Goldman Sachs internal project called Haskell, Ruby, and Scala. There are also responsibility of optimizing the various CARAMEL, which stood optimized replacements for datatypes being processed. An inter- for collections, arrays, map REALITY CHECK the JDK Collections classes, nal iterator is passed an operation to iteration library. We were “Innovation needs to like HashMap, ArrayList, and perform, and the iterator applies that dealing with very large Java HashSet. GS Collections is operation to every element in the heaps, on the order of ten be carefully vetted tuned for both large- and data collection. gigabytes to a hundred by the community small-scale performance. For example, if one collection is being gigabytes. And in these It’s ready for Java SE 8 transformed to another, and I know the spaces, we operated on through the JSR lambdas today, but it also target is the same size as the source, large collections to process process.” works with Java 5 through it can be presized in the algorithm, so lists, sets, and maps that —John Weir, Global Head Java 7. the developer doesn’t have to handle blog had millions or even hun- of Application Platforms, Java Magazine: Internal implementation details. This approach dreds of millions of ele- Goldman Sachs iteration is a key concept simplifies code and promotes reuse. ments. The codebases were for GS Collections. Why is In the Java space, most developers very large—with thousands it so powerful? implement what’s called eager iteration, 24

ORACLE.COM/JAVAMAGAZINE /////////////////////////////////////////// MARCH/APRIL 2014 Collections? Are there other Java SE 8 Collections testing hierarchy by COMMUNITY features of interest? building-in default methods and Raab: GS Collections was developed behaviors. This will allow the mixing at the outset around the concepts and matching of different testing con- embodied in lambda expressions. cerns across the framework. Having lambdas built into Java SE 8 is Method references, another Java SE 8 absolutely terrific; we will be able to feature closely tied to lambdas, will also leverage them extensively across our benefit GS Collections. They provide an JAVA IN ACTION APIs. We have 90+ functional methods even more concise and readable format that can be called by passing lambdas. for leveraging functional APIs. This Java SE 8 feature will deliver a The following is a method reference huge upside. We’ll be able to delete a code example from our GS Collections lot of code. I imagine a savings between Kata Java 8 Solutions: 20 percent and 30 percent. JAVA TECH For example, the Select pattern /** handwritten in Java SE 7 looks like this: * Aggregate the total order values by item. List results = new ArrayList<>(); */ for (Integer each : list) @Test { public void totalOrderValuesByItem() Weir and Raab fuel where computation happens immedi- if (each > 50) { ABOUT US up and catch up on ately. But there are patterns where it’s { MutableMap map = projects. advantageous to perform computation results.add(each); this.company lazily, meaning that processing can be } .getOrders() done a bit later. This type of processing } .flatCollect(Order::getLineItems) is not easily implemented by develop- .aggregateBy(LineItem::getName, ers. But using internal iteration, pro- While the Select pattern in GS () -> 0.0, (result, lineItem) -> cessing details are handled internally Collections with Java SE 8 looks like this: result + lineItem.getValue()); by the collections classes. Verify.assertSize(12, map); Internal iteration is also advanta- list.select(each -> each > 50); Assert.assertEquals(100.0, map geous for code maintenance. It makes .get("shed"), 0.0); large codebases much more readable. Another interesting development Assert.assertEquals(10.5, map Over the long life of an application, this in Java 8, virtual extension methods, .get("cup"), 0.0); blog can have tremendously important pro- will benefit GS Collections. This fea- } ductivity ramifications. ture allows behaviors to be added to Java Magazine: How will Java SE 8’s interfaces, which will help reduce the Method references make mainte- lambda expressions interact with GS amount of duplicate code in the GS nance and review cleaner and easier. 25

ORACLE.COM/JAVAMAGAZINE /////////////////////////////////////////// MARCH/APRIL 2014 Optimizations have been made within method that replaces getDateTimeMillis COMMUNITY the language and the JVM [Java Virtual from Joda-Time. The new method to Machine] to take advantage of these extract time in milliseconds ran about innovations. three and a half times slower and cre- Java Magazine: When did GS ated some garbage on the JVM. The Collections become open source? Tell Goldman Sachs community uncovered us about that process. this due to our extensive codebase, and Raab: We open-sourced GS Collections we were able to offer feedback through JAVA IN ACTION in January 2012. Before doing that, we our role in the Executive Committee. open-sourced it internally. At Goldman We also participate directly in the JSR Sachs we have a large number of process. We’ve been involved as con- developers and applications; it’s a very tributing members in lambda expres- collaborative and consensus-driven sions, the Collections API, the JCache organization. We wanted to find out API, and also the Identity API. We also JAVA TECH if there was a viable community of participate in debates and discussions potential users for GS Collections. And as to how the JCP process should oper- we discovered that the demand was ate, evolve, and move forward. definitely there. Java Magazine: JCP member companies In addition to open-sourcing the col- have diverse interests and priorities. lections library, we decided to include How are these needs best orchestrated

the associated training libraries, the within the JCP? ABOUT US GS Collections Kata, which is a great Weir: One of the great strengths of the Raab and Weir look at way to learn not just GS Collections Executive Committee is its breadth of the effect that lambda but also Java SE 8 lambda expressions organizational participation—from -ven expressions have on and method references. dors and redistributors of the Java plat- their code. Java Magazine: How has Goldman form, to framework and library provid- Sachs contributed to the JCP process? ers, to Java user groups [JUGs] and end Weir: We’re engaged in the JCP pro- users. It’s an excellent representative Java Magazine: What is the proper bal- cess at several different levels. Our role community all sitting at the virtual table ance between promoting standards and with the Executive Committee involves with the goal of guiding Java’s evolution. promoting innovation? reviewing JSRs at various stages. And That goal unifies the community, in Weir: We all want innovation. And inno- internally we leverage our network spite of some vigorous competition on vation is always there. It’s a fundamen- to interact with several thousand the vendor side. We try to maintain tal ingredient when developers solve blog Goldman Sachs developers to get their a cohesive Java platform that doesn’t problems. Donald talked earlier about JSR feedback. For example, on JSR 310, become fragmented and continues to CARAMEL evolving into GS Collections. the new and improved Date and Time accommodate a broad array of func- That software resulted from develop- API, we uncovered a problem with a tional demands. ers striving for a simplified, transpar- 26

ORACLE.COM/JAVAMAGAZINE /////////////////////////////////////////// MARCH/APRIL 2014 Raab: ent, and more engaging API. In the (JSPA). Because this is a legal contract, I would echo John’s comments COMMUNITY Java ecosystem, we have a great degree there can be restrictions for some regarding our commitment to Java. of openness, which spurs innovation. companies. Consequently, some Java We’re working with JUGs globally, There is a collective wisdom that comes developers don’t have a mechanism to including groups in New York, London, from talented people solving real-world become involved. Having seen the ben- and Hong Kong. The community is problems. But innovation needs to efit from large numbers of developers huge and diverse, which is fantastic. be carefully vetted by the community engaged in software evolution, with GS We’ve also just signed the agree- through the JSR process, to make sure Collections, we’re particularly invested ment to participate in OpenJDK, and

CHANGE MAKER JAVA IN ACTION that a diverse range of needs are being in the process as a core value. So we’re we look forward to making direct con- “[Lambda met. Millions of developers are affected intent on broadening involvement, tributions. We want to give back to expressions] will by these standards. The platform has to but it must be done in a thoughtful the open source community through deliver a huge function as an integrated whole. and methodical way that reflects the this process. The work that was done in JSR 348 best interests of the community. JSR The Java platform is a very impor- upside. We’ll be to improve transparency across the 348 is tackling that. I believe that tant element of the Goldman Sachs JAVA TECH able to delete JSR process has been very beneficial. It increasing participation will increase infrastructure. We’re committed to requires that Expert Groups use pub- the rate at which new innovations can making sure that it continues to evolve a lot of code. lic mailing lists and maintain a public be integrated into the Java platform. and develop to provide benefits for the I imagine a Issue Tracker. JSR 348 mandates that There are millions of Java developers community and our firm.