Welcome Java 6
Wednesday, 13 December 2006
With great fanfare, Java 6 was released to the world. Ok, that was a joke. Sun has the ability to make a major release without any fanfare or hullabaloo. Even Spring had a countdown to their 2.0 release. Oh well.
Java 5 was the really big release and added a lot of new functionality to the core language. Back in October of 2005 I wrote about the new features in Java 5 and did a little bit of prognostication about what might be next for Java. Well, if you look at it, you will soon realize that I was totally wrong. It turned into more of a “what I like in scripting languages that I wish I had in Java”. Oh well, I won’t quit my day job to try and predict the future. Java 5 added number of new language constructs like Generics, foreach loops, and enums. Java 6 on the other hand doesn’t seem to add any new language constructs, but is all about extending the APIs. Where Java 5 almost had a theme of catching up to .NET 2.0, Java 6 seems like a relatively random collection of new things.
Scripting
The Scripting API is one of the bigger and more talked about features. It’s definitely the thing that I’m most excited about. We’ve had Jython for years, Groovy for a while and more recently JRuby which allowed us to use more scripting languages on top of the JVM. Java 6 has really extended support for using these languages on the JVM. Java 6 comes with support for using JavaScript built in. This support is built on top of the Rhino engine originally from Mozilla.
The API seems to offer everything you could want. It allows you to access Java APIs from the scripting language (this is likely implementation dependent, but is done in the built in JavaScript implementation), it allows you to execute the scripting language methods in Java. It even allows you to mold dynamic languages to Java by forcing them into implementing specific interfaces.
As with most Java APIs, it has an extension mechanism to support various languages. There are already implementations of a lot of different languages available for download, so you can start trying your favorite scripting language.
Check out the Java 6 Scripting Guide for some great examples on various pieces of the API.
Database and JDBC 4.0
JDBC 4.0 offers a number of improvements to database access in Java. One of the bigger changes is that Java now comes with a 100% Java database implementation based on Apache Derby. That makes it really easy to get started with an application. You can graduate to a standalone database if you need to later. JDBC 4 makes some improvements to loading of database drivers. It can now use meta-data in a file under META-INF. This means that you don’t have to add the old Class.forName(”some.db.Driver”) in your code. It also means that changing the database is no longer a code-recompile, but just a simple file change (ok, so any serious application would have that string externalized already, but this is a nice thing to standardize).
Check out this article for a good overview of the changes in JDBC 4.0.
Desktop Integration
The Java 6 release has seen a number of improvements in terms of desktop integration so that Java Swing applications won’t feel like aliens. They’ve added support for splash screens so that users can get immediate feedback that your application is starting. They’ve also added APIs for dealing with Tray Icons and the System Tray which are really handy for a lot of applications.
Monitoring, Instrumentation and Tools Interface
I haven’t looked at a lot of the details of what’s been added, but it seems like they’ve put a lot of work into the monitoring and instrumentation side of a running VM. JConsole, a great tool for looking at the various memory areas in your JVM, is now officially supported.
One of the more interesting areas is the ability to transform already loaded Classes. The new classes in java.lang.instrumentation seem like they will be a great boon for a number of different uses. AOP and other Proxy implementations could make use of this. It also seems like this could be a very useful feature in conjunction with the new Scripting support. Languages like Ruby and JavaScript support dynamically adding methods and changing method definitions at runtime. Will this new code allow Script plugin developers to introduce that dynamic functionality into Java?
These are the things that seem most interesting to me. Check out all of the new features in Java 6 for yourself. What are you excited about?
No. 1 — December 14th, 2006 at 9:21 pm
I am excited that it is open source now. That should give it a real chance to move to more platforms quickly, such as MacOS X or FreeBSD which Sun has never supported directly. It will also continue to foster a larger community which will hopefully contribute valuable features back to the platform.
I am not thrilled about the scripting languages. With .NET projects I have to go back and forth between C# and VB.NET depending on the client. I cannot imagine walking into an environment with the very real possibility that the project could be implemented with any number of scripting languages which introduces a whole new set of concerns. There was a recent announcement for IronPython for .NET. I had the same reaction when it was announced. But at least when you do use those scripting languages in this way you have the same core framework so you will have at least a familiarity with the platform if not for the syntax of the scripting language of the week.
The ability to use the system tray is encouraging. I would really like to see a screenshot of what that looks like in MacOS X and Linux.
No. 2 — January 24th, 2007 at 8:54 pm
1.when run with scite noclass definition error . 2. when run with netbeans null pointer exception error in the code below:
import java.io.*;
import java.util.*;
import java.util.COLLECTIONS;
public class FilzLoc {
public class FilzLoc implements IDictionary,
ICollection,
IEnumerable,
ICloneable {
protected Hashtable innerHash;
public static void main(String[] args) {
}
public FilzLoc() {
innerHash = new Hashtable();
}
public FilzLoc(FilzLoc original) {
innerHash = new Hashtable(original.innerHash);
}
public FilzLoc(IDictionary dictionary) {
innerHash = new Hashtable(dictionary);
}
public FilzLoc(int capacity) {
innerHash = new Hashtable(capacity);
}
public FilzLoc(IDictionary dictionary, float loadFactor) {
innerHash = new Hashtable(dictionary, loadFactor);
}
public FilzLoc(IHashCodeProvider codeProvider, IComparer comparer) {
innerHash = new Hashtable(codeProvider, comparer);
}
public FilzLoc(int capacity, int loadFactor) {
innerHash = new Hashtable(capacity, loadFactor);
}
public FilzLoc(IDictionary dictionary, IHashCodeProvider codeProvider, IComparer comparer) {
innerHash = new Hashtable(dictionary, codeProvider, comparer);
}
public FilzLoc(int capacity, IHashCodeProvider codeProvider, IComparer comparer) {
innerHash = new Hashtable(capacity, codeProvider, comparer);
}
public FilzLoc(IDictionary dictionary, float loadFactor, IHashCodeProvider codeProvider, IComparer comparer) {
innerHash = new Hashtable(dictionary, loadFactor, codeProvider, comparer);
}
public FilzLoc(int capacity, float loadFactor, IHashCodeProvider codeProvider, IComparer comparer) {
innerHash = new Hashtable(capacity, loadFactor, codeProvider, comparer);
}
}
public IDictionaryEnumerator GetEnumerator() {
return new DictionaryEnumerator(this);
}
public interface IDictionaryEnumerator implements IDictionary.GetEnumerator() {
return new1 DictionaryEnumerator(this1);
}
IEnumerator IEnumerable.GetEnumerator() {
return GetEnumerator();
}
public void Remove(java key) {
innerHash.Remove(key);
}
void IDictionary.Remove(object key) {
Remove((java) key);
}
public bool Contains(java key) {
return innerHash.Contains(key);
}
bool IDictionary.int Contains(object key) {
return Contains((java) key);
}
public void Clear() {
innerHash.Clear();
}
public void Add(java key, xml value) {
innerHash.Add(key, value);
}
void IDictionary.int Add(object key, object value) {
return Add((java) key, (xml) value);
}
public bool IsReadOnly {
get {
return innerHash.IsReadOnly;
}
}
public xml this[java key]{
get {
return (xml) innerHash[key];
}set {
innerHash[key] = value;
}}
object IDictionary.this[object key]{
get {
return this[(java) key];
}set {
this[(java) key] = (xml) value;
}}
public System.Collections.ICollection Values {
get {
return innerHash.Values;
}
}
public System.Collections.ICollection Keys {
get {
return innerHash.Keys;
}
}
public bool IsFixedSize {
get {
return innerHash.IsFixedSize;
}
}
public void CopyTo(System.Array array, int index) {
innerHash.CopyTo(array, index);
}
public bool IsSynchronized {
get {
return innerHash.IsSynchronized;
}
}
public int Count {
public object SyncRoot {
get {
return innerHash.SyncRoot;
}
}
public FilzLoc Clone() {
FilzLoc clone = new FilzLoc();
clone.innerHash = (Hashtable) innerHash.Clone();
return clone;
}
object ICloneable.int Clone() {
return Clone();
}
public bool ContainsKey(java key) {
return innerHash.ContainsKey(key);
}
public bool ContainsValue(xml value) {
return innerHash.ContainsValue(value);
}
public static FilzLoc Synchronized(FilzLoc nonSync) {
FilzLoc sync = new FilzLoc();
sync.innerHash = Hashtable.Synchronized(nonSync.innerHash);
return sync;
}
internal Hashtable InnerHash {
get {
return innerHash;
}
}
public void IDictionaryEnumerator {
private IDictionaryEnumerator innerEnumerator;
internal FilzLocEnumerator(FilzLoc enumerable) {
innerEnumerator = enumerable.InnerHash.GetEnumerator();
}
public java Key {
get {
return (java) innerEnumerator.Key;
}
}
object IDictionaryEnumerator.Key {
get {
return Key;
}
}
public xml Value {
get {
return (xml) innerEnumerator.Value;
}
}
public class FilzLoc {
object IDictionaryEnumerator.Value;
get {
return Value;
}
}
public System.COLLECTIONS.DictionaryEntry Entry {
get {
return innerEnumerator.Entry;
}
}
region Implementation of IEnumerator public void Reset() {
innerEnumerator.Reset();
}
public bool MoveNext() {
return innerEnumerator.MoveNext();
}
public object Current {
get {
return innerEnumerator.Current;
}
}
}
}
*/
No. 3 — January 24th, 2007 at 9:14 pm
could you help me fix the error. I posted without comments because of time
constraints but I know about comments from my specifications and algorithm
formulated
No. 4 — January 25th, 2007 at 11:15 am
Mark,
It looks like you’re trying to use C# code in Java. That’s not going to work…