Friday Mar 21, 2014

Java 8 is Revolutionary! Want Proof?

Java SE 8 is a revolutionary release of the world’s #1 development platform. It is the single largest upgrade ever to the programming model, with coordinated core code evolution of the virtual machine, core language, and libraries. With Java SE 8, you are uniquely positioned to extend innovation through the largest, open, standards-based, community-driven platform. Want proof? Attend the Java 8 Launch webcast for all the authentication you need!

Download Java JDK 8.

Register now for the Java 8 keynote address and more than 35 deep-dive technical sessions.

Use #Java8QA to tweet questions for the Oracle Java Architect Team in advance of and during the webcast.

Join the discussion on the OTN Java 8 Questions Forum.


Thursday Nov 28, 2013

Java Mission Control - Production Time Profiling Out of the Box

By Guest blogger: Marcus Hirt

With the release of 7u40, there is a new kid on the JDK tooling block – Java Mission Control. This article will try to explain why it is worthwhile to take a closer look at this technology, as well as provide pointers on how to get started. 

History

Mission Control is a production time profiling and diagnostics tools suite that originated with the tooling available for the JRockit JVM. 

As part of the development effort of the JRockit JVM we started building tooling for analyzing the runtime performance of the JVM. We needed information about how real production systems were utilizing JRockit. Requests to get customers to lend us their latest top secret trading applications for evaluation in-house were usually, quite understandably, met with telling blank stares calling our sanity into question. It probably wouldn’t have done us much good anyways, since we wanted production data from systems under real loads. Thus we built a tool (the JRockit Runtime Analyzer, which later evolved into the JRockit Flight Recorder) with low enough overhead that we could convince customers to actually use it to collect production time data for us.

Eventually we accidentally solved some customer problems using the tools and customers started asking us if they could license them. The idea was born to spend some more resources on the tooling and make it a commercial tool to pay for its development. JRockit Mission Control was born.

Java Mission Control

After Oracle acquired Sun Microsystems, Oracle suddenly had two of the top three most commonly used general purpose JVMs available on the market. One was the open sourced reference JVM, with a lot of people knowing the source and licensees basing their own ports and versions of JVM off of it. The other JVM, whilst being a quick and pretty little thing, was proprietary with a rather small number of people knowing the code base. Instead of having to support two JVMs, Oracle wanted to pool the available resources into building a best of breed JVM. It was decided that the base would be HotSpot and that the most useful features in JRockit would be ported over – one of them being Mission Control.


In JDK 7u40 the functionality available in HotSpot had reached critical mass, and the very first version of Java Mission Control (unfortunately versioned 5.2.0) was released. It mainly contains equivalents of two of the JRockit Mission Control tools – the JMX Console and the Flight Recorder. There is no on-line heap analyzer yet. There is however a set of quite useful (experimental) plug-ins for JMC, extending Mission Control to do heap dump analysis, targeted analysis for various oracle products or simply extending existing functionality in more (or sometimes less – yes, I’m looking at you Twitter Trigger Action) useful ways .

Getting Started

Starting Java Mission Control is quite easy. Download a recent enough Java 7 JDK (7u40 or later), then simply launch %JDK_HOME%/bin/jmc. The alien thing that now starts is not, as I am sometimes asked, a native application. It’s Java, but it’s built upon Eclipse RCP technology. If you would rather run JMC inside of Eclipse, you can install JMC into your Eclipse from the JMC update site. A word of caution here – because of a bug in Eclipse/SWT, Mission Control performance is horrible in Eclipse 4.x. This bug is slated to be be fixed in Eclipse 4.4, but until then I strongly recommend either using the stand-alone version of JMC, or installing it into an Eclipse 3.8.2. 

The JMX Console

The console in Mission Control can be thought of as a JConsole on steroids. It allows you to monitor JMX data in various ways, to take action when attributes attain certain values and to persist the data and later look at what has been recorded. There are various experimental plug-ins for the console, such as a Coherence plug-in, a plug-in for running JConsole plug-ins and a plug-in for tweeting messages when a action triggers. 

To connect the console to a JVM, simply choose the JVM you want to connect to in the browser tree and select Start JMX Console. If the JVM was started locally or with JDP, then it will automatically appear in the JVM browser. If you have a remote JVM without JDP running, just enable the built in JMXRMI agent as you normally would to be able to connect with JMX clients such as JConsole.

The JMX console is typically used to monitor a small set of critical attributes, such as the CPU load and Java Heap usage, sampled at a relatively low frequency. The console can be configured to take action when undesirable values are reached for an attribute, and one of those actions can be to dump Flight Recorder data. The JMX console also contains special tabs for looking at thread information, such as deadlocked threads, per thread allocation information and per thread profiling information. That said, the JMX console is used for monitoring the runtime. When profiling capabilities or better diagnostic information is needed, the one stop shop is really the Flight Recorder.

The Java Flight Recorder

The Java Flight Recorder can be thought of as of the equivalent to the Data Flight Recorder for an airplane, but for the Java runtime. While it is running It records information about the JVM and its environment. When something “interesting” happens, the data in the Flight Recorder can be dumped, and the information analyzed off-line to gain an understanding of why everything suddenly went from good to “interesting”. Having the Flight Recorder running as an almost unnoticeable impact on the performance of the Java Application running in the JVM. The overhead is usually well below a per cent. This is achieved by having a high performance recording engine built directly into the runtime and collecting data already being tracked by the runtime or as part of an activity where the data is reachable. (As opposed to actively having to do additional work to get the data.) There are a lot of interesting things that can be said about the recording engine implementation, but this being an overview article, I’ll just move on to how to use it, not how it does what it does.

Creating Flight Recordings

The most important difference to how the Flight Recorder worked in JRockit is that in HotSpot two JVM start-up flags must be enabled on the JVM for which you want to do flight recordings:

-XX:+UnlockCommercialFeatures -XX:+FlightRecorder

And that was probably the most important line in this article. 

There are two different types of recordings, and you can have multiple recordings (of different types) running simultaneously:

1. Timed recordings 

These recording run for a pre-configured duration. They are automatically stopped when the time is up. If initiated from JMC, they will be automatically downloaded and opened in the user interface when done. 

2. Continuous recordings 

These recordings have no explicit end time and must be dumped by the end user. 

Now there are three different ways you can do actual recordings, once the parameters are in place:

1. From Mission Control. This is probably the easiest way. Just point and click. 

2. From jcmd. This is a very useful way to control the Flight Recorder from the command line. Quite useful when you can’t access the machine that is running the JVM of interest from Mission Control and you only have access to a shell. 

3. Using command line flags. This is handy when you want to always run with a continuous recording, or when you want to record the start up behaviour of the JVM right from the very start. 

If you want to know more about how to create Flight Recordings, this blog entry is probably a good place to start. 


Analyzing Flight Recordings

There is a lot of useful information in the flight recordings, and there are a lot of different things the information can be used for. For example:

Method profiling. The Flight Recorder will quite happily do method profiling in production systems with a very low overhead. As a matter of fact, it’s even enabled in the continuous template, so go ahead and use it. It will tell you where the hotspots are in your application. In other words, if you have a CPU bound problem, the method profiling information will tell you where to optimize to get things to go faster. 

GC profiling. The GC implementations emit useful events at GC related activity. Information that can be used to check on the live set, semi-refs, GC pauses (and their individual sub-phases) etc. Quite useful for GC tuning, finding out if you’re overusing finalizers and more. 

Allocation profiling. If you do notice a lot of garbage collections, but don’t notice anything strange about the individual GC phases, you may want to kick back a bit on the allocation. Allocation profiling will help you see where all that allocation activity is putting it’s toll on the memory system. 

WebLogic Server analysis. WebLogic is producing its own set of events for the Flight Recorder. They are quite useful in their own right, but can also be good for putting all the other information recorded in a context - “What was really happening during this transaction?”. This article on the Operative Set shows some of the capabilities. 

Latency Profiling. The Flight Recorder has a lot of different events for various thread stalling activities that can occur, such as blocking on monitor enter, parking, waiting etc. I can’t believe I haven’t written a blog post on this yet. Shame on me. This is usually the first place to look if you haven’t got a CPU bound problem, but still performance issues. 

OS information. CPU load, JVM CPU load, environment variables, running processes – there is a lot of operating system information. If you still can’t find what you’re looking for, Mission Control has a D-Trace plug-in for retrieving everything you ever wanted to know, but were too afraid to ask. Note that the overhead from using D-Trace, even with very few probes, is usually more than an order of magnitude worse than just using the Flight Recorder – use with caution. 

There is much more information available from the event providers built into the JVM, such as class loading and compiler events. One way to learn more details about what is available is to take a closer look at the metadata from a recording.

Summary

Since JDK 7u40 there is a new tools suite bundled with the JDK – Java Mission Control. The main focus of the suite is on production time profiling and diagnostics. This has the benefit that the data gathered is quite true to the dynamics of the application being profiled, as the observer effect is kept quite low. In other words, instead of profiling the profiler itself, most of the time is actually spent profiling the application and the runtime. Whilst the main focus of Mission Control is production systems, it can be quite useful in development too. It is also free for use in development, as per the standard Oracle Binary Code License (BCL).

This article provided a brief introduction to Java Mission Control.

Further Information

Java Mission Control Homepage

My Blog

@javamissionctrl;  @hirt


Tuesday Oct 01, 2013

At the Java Demogrounds: What’s Happening with Java SE?

Over at the Java SE demo booth, Oracle’s Aurelio Garcia-Ribeyro, Senior Group Product Manager, briefly discussed JDK 7 and  JDK 8.

“People may not realize that we’ve recently added new functionality to JDK 7,” he said. “So with JDK 7 u40, we added Mission Control and Flight Recorder to the JDK, something we're very proud of. Flight recorder is a feature that works a little like the flight recorder on a plane; you leave it on and it doesn’t really impact your production. It simply runs, and if you encounter an issue, you can go back and discover what triggered it after the fact. It’s quite useful in debugging horrible problems that occur only in production that you cannot really catch when you’re developing because you need it to be going for 15 days with a slow memory leak, but you don’t want to have to reproduce that because it’s costly and you don’t know when it happens. With flight recorder you just leave it on, set a trigger, and when something goes bad, it helps you figure out what triggered that event.”

I asked him about Java SE 8, which is scheduled for release in March of 2014.

“If you want to play with it, go to https://jdk8.java.net/ and download the developer preview. We’d like you to first try your existing projects, which should work just fine. Then after that, you should start playing with the new features like lambda and JSR 310, the Date and Time API. Lambda is the biggest change to the developer programming model. We are very excited about this.”

Monday Sep 23, 2013

The JavaOne 2013 Technical Keynote

by Timothy Beneke

Mark Reinhold, Oracle’s Chief Architect, the Java Platform Group, took the stage to kick off Sunday’s technical keynote at the Moscone Center. He began by quoting “father of Java” James Gosling. For Java to thrive, it must maintain what Gosling called the “feel of Java”. In other words, it must retain the key values of readability, simplicity, and universality.

“If we keep those,” said Reinhold, “then Java will remain not just productive but fun. It is not enough to simply add popular features each year.”

Lambda Expressions – The Single Largest Upgrade Ever
He turned to lambda expressions, which he described as the single largest upgrade to the programming model ever -- larger even than generics. “This is the first time we have done a carefully coordinated co-evolution of the JVM, the language, and the libraries all together – and the results still feel like Java,” said Reinhold.

He then welcomed Oracle Java Language Architect, Brian Goetz, to share the stage and began by remarking that while most developers understand that lambda offers a simple way to express code as data, some are not sure how it helps Java. Goetz responded that lambda expressions would more than help Java. “It’s going to change the way we all program in Java every day,” he explained. “Programming well is about finding the right abstractions. We want the code we write to look like the problem statements it’s trying to solve, so we can look at it and immediately know it’s correct. Java has always given us good tools for abstracting over data types. I wanted to do better in abstracting over patterns of behavior – that’s where lambda comes in.”

He illustrated this with some simple code that was, strictly speaking, “good” code, but weighed down with boilerplate and did not read like the problem statement it was trying to solve. It could be improved by using an inner class tool, but that too generated a lot of boilerplate. Reinhardt pointed out that improving the code made it less pleasant to work with, as if the developer was being punished for doing the right thing. This often causes developers to give up and do it the “dumb and ugly way”.

Lambdas can replace inner classes with a lambda expression which is simply an anonymous method that captures a behavior without a lot of syntactic boilerplate. “Lambdas are a nicer syntax,” said Goetz. “But they are also something deeper. It’s not just a compiler generating inner classes for you – it uses the invokedynamic feature to get more compact and higher performance code. It will make a qualitative difference in the way we program.”

If the right way to write a program is unpleasant, then people are less likely to do it according to Goetz. They are more tolerant of doing it the wrong way. He gave an example of how lambda expressions address this with the collections API involving a new abstraction to the JDK called stream and showed how to represent a simple query through applying a filter and mapping transformation, followed by an aggregation, in a way that is fused into one path without creating any intermediate weapons.

Reinhold summarized the key points: “So lambda brings 3 weapons to Java – syntax, performance and abstraction.”

“Plus parallelism,” Goetz added. He explained that Java 7 has the fork/join framework for parallel decomposition that is powerful, flexible, and highly efficient – but not the easiest thing to use. Goetz showed how lambdas enable better parallelism without needing to write fork join code: by asking the collection for a parallel stream it uses fork/join under the hood.

Lambda also helps with normal sequential code by making code clearer, less noisy, and easier to read. “When you have code that is hard to read, that’s where bugs come from. You are trying to maintain some code, you look at the code and think you know what it does, but don’t actually know what it does, and boom! – you’ve introduced a bug.”

All in all, the message was clear: Lambda expressions make Java code easier to read and easier to write.

Working with Lambda and the Collections Framework
For lambdas to be successful, they must work with the Java Collections Framework, which is now 15 years old. So an evolution of the interface was in order. Goetz’s team had to grow an interface over time without breaking implementations of the interface. They added a concept that allows developers to compatibly add a method to an interface, as long as a default implementation is provided.

Reinhold remarked that he has now written a couple of thousand lines of code with lambda features and really enjoyed it. “I can be more productive, and the end result still feels like Java,” he said.

To get started learning lambda expressions, Java developers can go to the OpenJDK Project Lambda page and download the developer preview builds there.

Reinhold reminded attendees that there is a great deal more in Java SE 8 besides lambda expressions. Developer preview builds can be downloaded at JDK8.java.net. “Now is a great time to download JDK 8 and take it for a spin. Every planned feature is in there. It’s reasonably stable and it passes almost all of the tests. If you have any feedback, please send it in!” said Reinhold. 

Playing Chess
In the rest of the technical keynote, Oracle’s John Ceccarelli, head of engineering for Oracle’s NetBeans team and Oracle’s JavaFX architect Jasper Potts, arrived on stage to demonstrate a Duke pad running real Java via a chess program that was connected to a server. The iPad operated through an HTML5 client talking to a Java EE 7 back end with an EE server in charge of  messaging, communication, game state, and so on, with clients hook into it – all built with NetBeans. Jasper Potts further showed off the chess demo with an HTML5 client using a front end to a chess server that was managing the chess games. Then a robot, powered by Java ME 8, took over the game.

Oracle Software Engineer, Santiago Pericas Geertsen, who built the chess server, also described how it was built with 5 distinct functional modules.

In sum, attendees witnessed a server running Java EE 7 hooked up with a variety of clients, some written in HTML5, one written in JavaFX on a Duke pad, one using JavaFX 3D on a powerful laptop, plus a Java ME 8-powered robot contributing to the ongoing chess game. In the process, the powers of the Raspberry Pi were demonstrated.

Developers were encouraged to jump in the water, go for a swim, and have fun with NetBeans and Java embedded.

Java SE 9 and Beyond
Wrapping it up, Reinhold peered a bit into the future and suggested some possible directions for Java, some of which are already in development:

One is Java on GPUs, graphic processing units. As GPUs are being used more and more widely to process big data he suggested that it would be good to make Java work directly with the GPU rather than having to call out to some primitive interface. An OpenJDK called Sumatra has people working on this.

Reinhold spoke of the need for reification. Java’s generics, added in 2004, are based on the notion of erasure for good technical reasons as a sound way to create a type system that supports migration compatibility. But this creates programming problems in which the erasure approach severely limits what can be expressed. Reinhold suggested that introducing some reification and eliminating the “annoying dichotomy between primitive and reference types” would be of value.

He mentioned JNI 2.0 and said, “It just shouldn’t be so hard to integrate Java with native code after all these years.”

He called for memory efficient data structures: “As we get into big data – all this boxing and pointer chasing makes it hard to do big data well. We could have less boxing and pointer chasing and load a lot more data into memory.”

Finally, he talked about the notion of a truly modular platform. “The compact profile in Java 8 is a start but it is not flexible enough. We need to continue to unify the Java SE and Java ME platforms.”

JDK 8

OpenJDK Project Lambda

Watch Keynote and Session Highlights on Demand

Friday May 17, 2013

New Java SE Version Numbering Scheme!

The releases with new functionalities and non-security fixes also called Limited Update Releases will be numbered in multiples of 20. The Critical Patch Updates (CPUs) will be calculated by adding multiples of five to the prior Limited Update and when needed adding one to keep the resulting number odd.

As an example: The next Limited Update for JDK 7 will be numbered 7u40, and the next 3 CPUs after that will be numbered 7u45, 7u51, and 7u55. The next release will be a Limited Update 7u60, followed by CPUs 7u65, 7u71, and 7u75.

This new version system will apply to JDK 5, JDK 6 and JDK 7 which are available on OTN Java SE Download page and Java.com

The change will: 
  • assign a fix/enhancement to a specific release in the bug systems. 
  • prevent the existing code from breaking. the versions will follow the format 7u44 and will not allow 7u44-2 for example.
  • leave “space” between planned releases for any potential unplanned ones. 

Wednesday Mar 06, 2013

Get started with Java!

Every year, the Java platform is growing with new features for enterprise, web, embedded and mobile application and developers. To help beginners navigate the platform and get started with Java technologies, new learning resources are available on the New to Java website. Developers will write a "Hello World" application, test their Java knowledge,  create user interfaces with JavaFX, and build enterprise applications with Java EE, desktop applications with Java SE or applications for mobile and embedded devices.  

Being up to date about current trends and networking with other developers are also critical for a career in programming. Developers can connect with top leaders in the community at conferences and community networks such as local user groups. They have the chance to contribute to open-source projects such as OpenJDK and Adopt-a-JSR to name just two.

Finally, parents and educators teaching programming to children will find software tools for young developers. They are free downloadable development tools with easy to use interfaces for young students. And Minecraft is so popular! Java technologist Daniel Green walks us through Minecraft mods with Java.

Wednesday Jan 30, 2013

Nashorn, the JavaScript Implementation in Java 8

In this Interview, Marcus Lagergren, who works on the dynamic language team at Oracle, discussed the Nashorn project.  "Nashorn is the JavaScript runtime based on InvokeDynamic for the Java Virtual Machine (JVM)" he explains. The Nashorn project is now part of the OpenJDK

The performance is much better than its predecessor Rhino. "We totally blow it out of the water now that we have specific tools to run other things than Java on the JVM." Marcus commented. "The pluggability between JavaScript and Java is another good thing" he added.

His Devoxx talk about Nashorn is now freely accessible at Nashorn - implementing dynamic languages on the JVM
Marcus Lagergren's twitter handle is @lagergren. Nashorn blog has the latest on the project

Thursday Jan 24, 2013

OpenJDK, Adopt-A-JSR and Adopt OpenJDK Projects!

In two interviews, Martijn Verburg, leaders of the London Java user group and Cecilia Borg, Project Manager at Oracle explain the OpenJDK and two community projects Adopt-a-JSR and Adopt OpenJDK.  

"The Java Platform is huge and, to a lot of people, it is too big" explained Cecilia. "OpenJDK is divided into 22 different groups and 40 different projects to make it easy to participate." She recommends starting small by "subscribing to one of the mailing lists at openjdk.java.net" and contributing small bug fixes, for example.  It is important that contributors learn as much as possible and pick a project that feels right for them.


"The idea of Adopt-a-JSR is to have ordinary Java developers get involved with the creation of standards" indicates Martijn.  "Adopt-a-JSR is about Java EE and ME standards."  "The work on the Java language and the JVM is done as part of OpenJDK and Adopt OpenJDK projects," Verburg continues. He outlines how to start on those projects. Contributors can be individuals but also JUG leaders, who organize coding events to work on Java standards. 

Wednesday Nov 21, 2012

Get Started with JavaFX 2 and Scene Builder

Up on otn/java is a very useful article by Oracle Java/Middleware/Core Tech Engineer Mark Heckler, titled, “How to Get Started (FAST!) with JavaFX 2 and Scene Builder.”  Heckler, who has development experience in numerous environments, shows developers how to develop a JavaFX application using Scene Builder “in less time than it takes to drink a cup of coffee, while learning your way around in the process”.

He begins with a warning and a reassurance: “JavaFX is a new paradigm and can seem a bit imposing when you first take a look at it. But remember, JavaFX is easy and fun. Let's give it a try.”

Next, after showing readers how to download and install JDK/JavaFX and Scene Builder, he informs the reader that they will “create a simple JavaFX application, create and modify a window using Scene Builder, and successfully test it in under 15 minutes.”

Then readers download some NetBeans files:
EasyJavaFX.java contains the main application class. We won't do anything with this class for our example, as its primary purpose in life is to load the window definition code contained in the FXML file and then show the main stage/scene. You'll keep the JavaFX terms straight with ease if you relate them to the theater: a platform holds a stage, which contains scenes.

SampleController.java is our controller class that provides the ‘brains’ behind the graphical interface. If you open the SampleController, you'll see that it includes a property and a method tagged with @FXML. This tag enables the integration of the visual controls and elements you define using Scene Builder, which are stored in an FXML (FX Markup Language) file.

Sample.fxml is the definition file for our sample window. You can right-click and Edit the filename in the tree to view the underlying FXML -- and you may need to do that if you change filenames or properties by hand - or you can double-click on it to open it (visually) in Scene Builder.”

Then Scene Builder enters the picture and the task is soon done.

Check out the article here.

Thursday Jan 19, 2012

A File I/O Tutorial Featuring NIO.2

A tutorial on the front page of otn/java titled “A File I/O Tutorial Featuring NIO.2” explains the new file I/O mechanism introduced in the Java 7 release. The java.nio.file package and its related package, java.nio.file.attribute, provide comprehensive support for file I/O and for accessing the default file system. Though the API has many classes, developers need only focus on a few key entry points. The tutorial makes it clear that the API is intuitive and easy to use.

The tutorial begins by asking, “What is a path?” and then introduces the Path class, which is the primary entry point for the package. It explains Methods in the Path class related to syntactic operations and moves on to the other primary class in the package, the Files class, which contains methods related to file operations. It then introduces some concepts common to many file operations and explains methods for checking, deleting, copying, and moving files.

The tutorial offers a concise summary of the API with suggestions for further learning.

“The java.nio.file package provides extensive support for file and file system I/O. This is a very comprehensive API, but the key entry points are as follows:
•    The Path class has methods for manipulating a path.
•    The Files class has methods for file operations, such as moving, copy, deleting, and also methods for retrieving and  setting file attributes.
•    The FileSystem class has a variety of methods for obtaining information about the file system.”

More information on NIO.2 can be found on the OpenJDK: NIO project website on java.net. This site includes resources for features provided by NIO.2 that are beyond the scope of this tutorial, such as multicasting, asynchronous I/O, and creating your own file system implementation.


Read the complete article here.

About

Insider News from the Java Team at Oracle!

duke
javeone logo
Links


Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
2
5
6
7
12
13
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today