The Java Tutorials' Weblog

pageicon Monday Feb 02, 2009

NIO and JDK7

You may be familiar with the NIO (New I/O) api. This API, introduced in release 1.4, extended the previous I/O package and included support for pattern matching with Regular Expressions, Buffer support for primitive types, Character-set encoders and decoders, and Channels — an abstraction for devices capable of performing I/O operations (to name just some of the functionality).

You may be familiar with NIO, but have you heard of NIO.2? NIO.2, part of the JDK7 effort, completes some of the work begun in the NIO api and goes much further: It includes an improved filesystem interface, multicast support, asynchronous I/O support, and complete socket-channel functionality (which was begun in release 1.4).

Thanks to OpenJDK, you can download and play with NIO.2 now. The NIO Project Page contains links to the latest binaries, javadoc, JSR 203, and links to bloggers involved in this effort.

-- Sharon Zakhour

pageicon Tuesday Jan 06, 2009

JavaFX Rated as Top 10 for 2008

As you know, JavaFX 1.0 was released in early December and has been receiving some exciting attention among developers and the press. For example, eweek has ranked JavaFX as number 5 in its Top 10 Application Development Products for 2008.

If you haven't yet checked it out, I would refer you to the last several entries on this blog. :)

Also, if you would like to run JavaFX applications and applets while not connected to the internet, check out this article by Thomas Ng.

Happy 2009!!

-- Sharon Zakhour

pageicon Friday Oct 31, 2008

Sun in Second Life

Have you tried Second Life yet? Probably you have at least heard of this internet-based virtual reality game, though you might have heard about its more salacious side. And yes, that does exist.

But Second Life is far more than that. It's an enormous and varied community — a rich place for people and activities of all sorts to interact and explore.

And did you know that Sun Microsystems has a presence in Second Life? Sun has three public sims and hosts a variety of events, such as the events held on our new Solaris campus.

How do you find us? You can search Places within SL, but here are Sun's Second Life URLS (SLURLs). You can click these links in your browser and they will launch Second Life (or open a Teleport window within the app):

Sun is hosting a Halloween party at Club Java on October 31st, 8am SLT. (Second Life Time is equivalent to Pacific time.) There will be a costume contest with a $1000L prize for best costume (Linden dollars are the currency used in SL.) There will also be a live DJ.

Above my avatar is modeling the costume I prepared for the event. (The Headless HUD with facial expressions is available from Tortec.)

At some point, we may host a tutorial related event in Second Life. Would you find that interesting? Sun hosts other talks and events on its public sims. There are also freebies, such as t-shirts, backpacks, etc. (Of the virtual variety, of course.)

If you haven't yet tried Second Life, here is a good opportunity. You only need download the application from secondlife.com, create a new account on the website, log in and voila — it's completely free.

I hope to see you at the Halloween party!

-- Sharon Zakhour

pageicon Wednesday Sep 24, 2008

Link to the Latest API Specification in Japanese

Last week I posted about the new link that will always point to the latest API specification: http://java.sun.com/javase/current/docs/api/index.html.

We received feedback from Manabu Nakamura asking us to provide the same link for the Japanese translation.

Ask and you shall receive.

It has gone live today: http://java.sun.com/javase/current/ja/docs/ja/index.html.

Thanks for the great idea, Manabu!!

-- Sharon Zakhour

pageicon Thursday Sep 18, 2008

Link to the Latest API Specification

Up until now, if you wanted to view the Java API, you had to specify a particular release of the JDK. For example: Likewise, if you wanted to link to the API specification, you had to hardcode the release into your documentation. This can lead to stale links as newer versions of the JDK are released and older versions are EOL'd.

We are introducing a new link that will always take you to the latest API specification. If you create a link to (or bookmark) this new URL, you are guaranteed to always be linked to the latest documentation. Currently it links to the JDK 6 API spec, but it will take you to the JDK 7 API spec when it is released.

We hope you find this to be handy!

-- Sharon Zakhour

pageicon Thursday Aug 28, 2008

The finally Block Always Executes

We recently received some very good feedback from a reader, Russel Taylor, regarding The finally Block page.

Russel pointed out that, though it might be obvious, the finally block will not be executed if the JVM exits while in the process of executing the try or catch code. Likewise (and this is where it might be less obvious), if the code is executing on another thread and that thread is interrupted or killed, the finally block would not be executed, even if the application continues.

This exact problem led to a production outage that Russel helped to debug.

I have modified this page of the tutorial to include a note about this fact. Thanks, Russel, for helping us to improve the tutorial!

-- Sharon Zakhour

pageicon Tuesday Jul 15, 2008

Class Variables and the Applet

Has this ever happened to you? In your applet, you create a global variable by defining a public non-final static field. When you are testing your applet the field doesn't have the value you expect it to have. This can happen when a browser uses the same JVM to run multiple applet instances and all are writing to the same global variable.

You can't make any assumptions on how a browser will implement the JVM. But if you are using JDK 6, you can take advantage of the new class loader cache applet parameter. Specifying "false" for this parameter will ensure that each applet instance will get its own unique set of statics.

Another possible solution available in JDK 6 is to launch the applet directly from a JNLP file. Applets launched through this Java Plug-In mechanism will never share static state.

Thanks to Yvon Rozijn who submitted this question to the tutorial feedback alias.

-- Sharon Zakhour

pageicon Tuesday Jul 08, 2008

Deployment Documentation

We are in the process of rewriting some of our deployment documentation and would like your feedback. Please read this thread on the Java Tutorials forum. You must be a member of java.net to post, but it's free.

-- Sharon Zakhour

pageicon Thursday Jul 03, 2008

Multimedia Tutorials

Do you believe that a visual demonstration blows minds better than words?

Don't you think it is time that we add a touch of multimedia to our Java guides, tutorials and any other Java documentation?

Below is a small demonstration of the procedure to validate the JRE in your system. This demo represents the validation procedure found in the Java Upgrade Guide.

Of course we are not going to replace all of the content with multimedia examples, but only to supplement the existing content. We might include small bits and pieces of such presentations, including screencasts, in the tutorials and/or guides to demonstrate tasks or illustrate concepts. We need your feedback/comments/suggestions before we implement the same.

What do you think? As a novice or a budding Java programmer do you think these presentations would enhance your understanding of the subject in a better way?

- Jacob Royal

pageicon Friday Jun 27, 2008

Java FX Resources

Have you heard? The Java Platform is now defined to include the Java SE Platform and the Java FX Platform. To accommodate this we have opened up the Java Tutorials Community Portal to include discussions and tutorials on JavaFX.

To kick this off, I have posted a list of JavaFX resources in the forum.

And I also posted Scott's "Animation, the Easy Way!" mini tutorial in the wiki.

-- Sharon Zakhour

pageicon Tuesday Jun 24, 2008

Core Java Technologies Tech Tips

It's a mouthful, but are you familiar with the Core Java Technologies Tech Tips?

These blog entries are created by engineers and are intended to show the latest and the greatest in technical detail. As I peruse the list, a few that jump out at me are:

Of course the Java Tutorials are also a good source for some of this information, but this is a blog worth watching.

-- Sharon Zakhour

pageicon Thursday Jun 12, 2008

Java Tutorials Translations

We occasionally receive requests from people who would like to translate the tutorials into other languages and to provide it back to the community. While the published book, The Java Tutorial, is available in a few other languages such as simplified Chinese and German, this does not fill the enormous language gap.

Much to my chagrin, I am a mono-linguist. We do have a few writers on staff fluent in other languages (Russian, French and Hindi, to name a few), but we just don't have time to translate our work.

But we would love to see the tutorials made available in many languages! In fact, on the new Community Portal there is a place on the wiki specifically dedicated to posting translations. So far, it's empty, but we hope to see contributions over time.

There is a thread on this subject on the forum. I would be curious to see what language you would most like to see in a translation.

-- Sharon Zakhour

pageicon Friday May 30, 2008

HTML Component

The rapid growth of HTML as a basic application platform makes displaying web content a topical question for many developers and designers, whether this content is various web sites or static HTML pages. Therefore, the need has arisen to create a reusable HTML component that can be repeatedly used by different applications and modified according to current business needs. The Java™ platform enables all functionalities to create such cross-platform encapsulation.

The HTML component provides a web viewer and full browsing functionality through its API. In particular, it supports events handling, for example, load progress, or URL traversed. The current implementation of the HTML component supports so called "street HTML", an HTML syntax which does not meet all requirements of the HTML specification, however, it is recognized by major world known browsers. Moreover, the component is implemented as lightweight in order to avoid allocating native resources in the operating system's windowing toolkit, and easy integrating with Java and JavaFX graphics libraries. The HTML component is based on WebKit, an open source web browser engine, which supports HTML4, CSS, JavaScript, DOM, SVG.

When designing an embedded browser instance, the following features are typically considered:

  • Accessing certain domains
  • Accessing the local file system
  • Loading a URL
  • Moving forward or backward in the browser's history
  • Printing web page
  • Reloading the current web page
  • Stopping loading the web page in progress
  • Support for JavaScript and plugins
Due to these features, the embedded browser enables you to host web pages and other browser-enabled documents in your applications.

The following structure depicts the internal architecture of the embedded browser.

internal structure

Figure 1. The HTML component architecture

The JWebPane component provides basic web page browsing functionality. It renders web pages and provides basic user interaction, such as navigating links, and submitting HTML forms. The JWebPane component displays one web page at a time. The PolicyDelegate is intended for implementing a browser policy. Implementations may use arbitrary logic to enable or reject sensitive operations such as loading web pages, opening new browser windows or running scripts on pages. An implementation may thus act as a list-based URL filter or a popup blocker. A single PolicyDelegate may be associated with a JWebPane object. It then receives notifications from the JWebPane about changes to the browser state that are about to happen. The PolicyDelegate may either accept or reject these changes. The LoadStateListener tracks the state of a page load.

At the moment the project is 70% complete. The JWebPane component implemented as a lightweight component extending the JComponent class, which enables easy embedding into an application UI context. Moreover, the JWebPane component may contain several web frames with the specified icon, title, and URL. The following browsing features are available:

  • Loading control — load, stop, and reload functions.
  • Listeners handling. — typical function enabling a developer to get, add, and remove listeners.
  • JavaScript support
The current implementation of the embedded browser supports handling of the following events:
  • Page loading started
  • HTTP server redirection processed
  • Icon for the page received
  • Page title received
  • Page content loaded completely
  • An image contained in the page loaded
  • Page and all its resources loaded completely
  • Loading Failed
In spite of limited functionality, the embedded browser can be successfully employed in Rich Internet Application. The following figure shows a simple JavaFX application, where the HTML component has been embedded into the frame and rotated using the scene graph functionally. Note that the embedded browser possesses all the declared capabilities. The page is live! If you right click the hyperlink, the pop up menu appears.

HTML component demo screen shot

Figure 2. The HTML component embedded into the JavaFX application Click the image to view it at its natural size.

The following new features are scheduled to be implemented by August'08:

  • Viewing the History, including Back and Forward functions.
  • Notifications of external resources loading
  • Progress status
  • Viewing page source
To put it briefly with the HTML component developers can substantially extend the capabilities of desktop applications, thereby enabling all commonly used browsing features and easily retrieving functionality of the embedded lightweight component. Find more information about the JWebPane component in the Artem Ananiev's Blog.

-- Alla Redko

pageicon Thursday May 08, 2008

Tutorial Examples and Model View Controller (MVC) Design

On the Java Tutorials Community Portal forum, developer Arjan Vermeij recently posted an update to an old Swing demo -- SliderDemo3. (Actually, he first posted his demo some time ago on a different java.net forum, but I asked him to post it on our forum.)

I'm sure many of you are familiar with Model-View-Controller (MVC) design. If you aren't, the purpose of MVC design is to separate the data and logic from the GUI, or the display, of an application. In fact, Arjan has written an article on this very subject: A Generic MVC Model in Java if you would like more information.

For program design, this just makes good sense.

However, Arjan points out that we don't use MVC design in our tutorial examples. He has taken SliderDemo3 and re-designed it using MVC architecture. He illustrates the point of MVC design by extending the GUI of the example without affecting the rest of the code. It's nicely done.

I posted some commentary about his example in the slider-demo-3 thread. I won't repeat the whole entry here, but this is one of those trade offs we look at when working on the tutorial. To create tutorial examples with perfect design principles, we would have to bloat examples that are designed to illustrate a specific piece of information. Sometimes, we just don't want to do that.

However, I do think there is room for more sophisticated "real world" examples and we haven't addressed that need as well as we might. It's an issue I don't see being resolved in the near future, with resources being what they are.

This is why the Java Community Portal is a needed resource. People like Arjan can share and leverage this sort of information.

To follow (or contribute to) the discussion, check out the slider-demo-3 thread.

-- Sharon Zakhour

pageicon Wednesday Apr 16, 2008

Books about Java

Most of you are aware that the Java Tutorial is available as a published book, but sometimes we are asked what portion of the website is included in the published book. The answer to that can be found on the tutorial's main page, but sometimes people miss the information.

If you look at the tutorial's main page, you will see the section titled Trails Covering the Basics. Everything listed in that section is included in the printed book.

I should add that, as of the last report I received from Addison Wesley, there are German, Japanese and "simplified" Chinese translations of the book available.

Once you've mastered the basics of Java, what other books are recommended?

My favorite book that takes you to the next level is Effective Java by Joshua Bloch. (I see there is a 2nd edition in the works.) Josh has been a contributor to the Java Tutorials (he wrote the Collections lesson). Effective Java is an excellent resource for the Java programmer, full of nuggets you might not find anywhere else. The first section is a useful discussion of garbage collection. I highly recommend it.

Another book I like for those who write Swing applications is Swing Hacks: Tips and Tools for Killer GUIs by Joshua Marinacci. Josh is a former member of the Swing team and he really knows how to exploit the features of Swing. This book contains many nuggets on how to do exactly that. For the basics, I recommend our own Swing tutorial (the online version reflects release 6 though the most recent printed version reflects release 1.4), but then you should check out Josh's book to take it to the next level.

-- Sharon Zakhour


« November 2009
SunMonTueWedThuFriSat
1
2
3
4
5
6
7
8
9
10
12
14
15
16
18
19
20
21
22
23
26
27
28
29
30
     
       
Today

Feeds

Search this blog

Links

Weblog menu

Today's referrers

Today's Page Hits: 944