Java Magazine Is Provided on an “As Is” Basis
Total Page:16
File Type:pdf, Size:1020Kb
+ KOTLIN 46 | FUNCTIONAL JAVA 50 | CDI 59 | CAREERS 77 Testing HUNTING DOWN HARD-TO-FIND ERRORS SEPTEMBER/OCTOBER 2015 AUTOMATED 14 TESTING FOR JAVAFX JUNIT’S MOST 20 UNDERUSED FEATURES BUILDING 26 A SELENIUM TEST GRID ORACLE.COM/JAVAMAGAZINE //table of contents / 14 20 26 32 42 EIGHT GREATLY BUILDING AND STRESS TESTING THINK LIKE UNDERUSED AUTOMATING JAVA EE A TESTER AND TEST JAVAFX APPS FEATURES OF JUNIT A FUNCTIONAL APPLICATIONS GET RID OF QA WITH TESTFX By Mert Çalişkan TEST GRID By Adam Bien By Mark Hrynczak By Bennet Schulz Make your testing a whole By Neil Manvar Identify application server Atlassian represents the Simple JUnit-style testing of JavaFX UIs lot easier with little-used How to assemble a grid configuration problems, bleeding edge in testing: JUnit capabilities. for Selenium testing potential bottlenecks, its developers are required synchronization bugs, to formulate tests before and memory leaks in they code and after. QA is Java EE code. there to help—but not test. Here’s how it’s working. COVER ART BY I-HUA CHEN 03 46 59 77 From the Editor JVM Languages Java EE Career One of the most effective tools for Kotlin: A Low-Ceremony, Contexts and Dependency More Ideas to Boost defect detection is rarely used due to High-Integration Language Injection: The New Java EE Your Developer Career old prejudices, except by companies By Hadi Hariri Toolbox By Bruno Souza and Edson Yanaga who can’t afford bugs. They all use it. Work with a statically typed, low- By Antonio Goncalves Skills to develop, activities to explore 06 ceremony language that provides More loose coupling with observers, 25 Letters to the Editor first-class functions, nullability interceptors, and decorators Java Proposals of Interest Corrections, questions, and kudos protections, and complete integration with existing Java libraries. 70 JEP 259: Stack-Walking API 07 Architecture 45 Events 50 A First Look at Microservices Functional Programming User Groups Calendar of upcoming Java By Arun Gupta The Virtual JUG conferences and events Functional Programming The latest trend in enterprise computing in Java: Using Collections is microservices. What exactly are they? 80 10 By Venkat Subramaniam 75 Contact Us Java Books Part 2 of our coverage of functional Have a comment? Suggestion? Reviews of books on JavaFX programming explains the code smells Fix This Want to submit an article proposal? and Java EE 7 that can arise from lambda-based Our latest code challenges from Here’s how to do it. the Oracle certification exams functional routines. 01 ORACLE.COM/JAVAMAGAZINE /////////////////////////////// SEPTEMBER/OCTOBER 2015 EDITORIAL PUBLISHING Editor in Chief Publisher Andrew Binstock Jennifer Hamilton +1.650.506.3794 Managing Editor Associate Publisher and Audience Claire Breen Development Director Copy Editor Karin Kinnear +1.650.506.1985 20 Years of Karen Perkins Audience Development Manager Section Development Jennifer Kurtz Michelle Kovac ADVERTISING SALES Technical Reviewers Josie Damian +1.626.396.9400 x 200 Stephen Chin, Reza Rahman, Simon Ritter Advertising Sales Assistant Innovation DESIGN Cindy Elhaj +1.626.396.9400 x 201 Senior Creative Director Mailing-List Rentals # Francisco G Delgadillo Contact your sales representative. 1 Development Platform Design Director Richard Merchán RESOURCES Oracle Products Senior Designer +1.800.367.8674 (US/Canada) Arianna Pucherelli Oracle Services Designer +1.888.283.0591 (US) Jaime Ferrand Senior Production Manager Sheila Brennan Production Designer Kathy Cygnarowicz Since 2002 Since 1999 Since 1995 ARTICLE SUBMISSION Since 1996 Since 1998 Since 1996 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 Since 1996 Since 2008 Since 1998 [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. Since 1999 Since 2001 Since 1996 Since 2012 Copyright © 2015, 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 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 Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Java Magazine is published bimonthly at no cost to qualified subscribers by Oracle, 500 Oracle Parkway, MS OPL-3A, Redwood City, CA 94065-1600. Digital Publishing by GTxcel 02 ORACLE.COM/JAVAMAGAZINE /////////////////////////////// SEPTEMBER/OCTOBER 2015 //from the editor / BIO The Unreasonable Effectiveness of Static Analysis It’s easy to run, provably effective, and greatly underused. Why? here is perhaps no greater peculiarity in the demics study real-life projects, both open source Tprofession of software development than the and inside companies, the perception that they are lack of interest in software engineering. This field, disconnected from reality endures. Their utility, which is the empirical, quantitative analysis of however, shows up when a project with unusual software-development techniques, should be the requirements confronts an organization. Suppose cornerstone of the trade. And yet for most devel- after several years of leading various teams at your opment organizations, it remains a closed domain company and delivering projects roughly on time into which they never venture. Even the emerg- and of the desired quality, you’re charged with ing emphasis on metrics and dashboards has not a green-field project that requires a much lower led to curiosity about what thousands of projects level of defects than your organization is accus- tell us about those very numbers. The disregard tomed to. How will you amp up the quality? extends even to the parlance we use: In most This is where software engineering becomes a locales, a “software engineer” is a seasoned pro- crucial resource: You can see which techniques grammer. There is no implication of familiarity deliver lower defect rates and what their impact with software engineering. on productivity has been historically. Informed Part of this neglect is the view that practitioners with this data, you’ll be able to plan how to go are mostly academics. Although those same aca- about reaching the new goals for this project. (In PHOTOGRAPH BY BOB ADLER/GETTY IMAGES 03 ORACLE.COM/JAVAMAGAZINE /////////////////////////////// SEPTEMBER/OCTOBER 2015 //from the editor / real life, of course, most organi- and to a lesser extent Checkstyle. false positives a decade ago aver- zations just call in consultants.) Commercial tools—such as those aged 10 percent but now are well Were you to perform this from Coverity, Parasoft, Rogue below 3 percent. In commercial inquiry, it might lead to con- Wave Software, and other ven- products, the rate is even lower. sideration of what practices you dors—are significantly more The other perceived drawback could add to existing projects to advanced. They can do magical is that the tools are slow. This raise their overall quality with- things such as data-motion anal- remains true. You typically run out sacrificing productivity. In ysis, which reveals defects that the high-end tools once a day for many—likely in most—cases, are hard to see via other means. the whole project, but always on that additional practice would be For example, this analysis can code about to be checked in. The static analysis of code. Relying show that a given data item can tools can analyze new code by on the work of Capers Jones, one never be null because all paths cross-checking with the database of the most widely experienced that touch it first pass through of artifacts from the most recent analysts of software-engineering another module far afield that whole-project scan. data, static analysis reduces guarantees nonnullness. Or it can Static analysis has an addi- defects in projects by 44 percent find the opposite, that a method tional upside: It’s not disruptive (from an average of 5.0 defects that counts on being passed only to existing site practices. You per unit of functionality to 2.8 prescreened objects can in fact can add it to a testing pipeline defects). Among standard quality be passed a null. Some of these with ease. This aspect and its assurance techniques, only formal tools excel at finding other very remarkable effectiveness make inspections have a higher effec- difficult bugs, such as unwanted it one of the simplest, but unde- tiveness (60 percent). By com- interactions between two servedly underused, ways to parison, test-driven development threads, or the rare case that a improve quality. (TDD) comes in at 37 percent. data item can be read incorrectly These numbers are not additive, due to the design of the Java Andrew Binstock, Editor in Chief of course. Inspections plus static memory model. These are subtle [email protected] analysis don’t deliver 100 percent items that can be hard to locate @platypusguy defect-free code. By the same and costly to fix—and they’re token, static analysis reveals typically not revealed by formal PS: Update on our evolution: problems that inspections and inspections or unit testing.