Java 7 and Beyond

Elliotte Rusty Harold

Monday, April 30, 2007

elharo@metalab.unc.edu

http://www.cafeaulait.org/


What's Going to Change? Everything


GPL!



Possible Language Changes


Array Syntax for Collections


Properties


Property Literals


Internal Property Identifiers


Type Inference


Factory Methods


Arbitrary Precision Arithmetic


Subpackage Access


Closures


Closure Use Cases


Closures


Sorting


Annotations on Java Types


Possible Library Additions


This time for sure: File systems



Copying a File

import java.nio.filesystems.*;
import java.io.*;

public class FileCopier {

  public static void main(String[] args) throws IOException {

    if (args.length != 2) {
      System.err.println("Usage: java FileCopier infile outfile");
      return;
    }

    PathReference source = PathReference.from(args[0]);
    PathReference target = PathReference.from(args[1]);

    int flags = CopyFlag.COPY_ATTRIBUTES | CopyFlag.REPLACE_EXISTING;
    source.copyTo(target, flags);

  }

}

Moving a File

import java.nio.filesystems.*;
import java.io.*;

public class FileMover {

  public static void main(String[] args) throws IOException {

    if (args.length != 2) {
      System.err.println("Usage: java FileCopier infile outfile");
      return;
    }

    File in = new File(args[0]);
    File out = new File(args[1]);
    
    PathReference source = in.toPathReference();
    PathReference target = out.toPathReference();

    int flags = CopyFlag.ATOMIC_MOVE 
      | CopyFlag.REPLACE_EXISTING | CopyFlag.COPY_ATTRIBUTES;
    source.moveTo(target, flags);

  }

}

Directories

import java.nio.filesystems.*;
import java.io.*;

public class FileSystemLister {

  public static void main(String[] args) throws IOException {

    File[] roots = File.listRoots();
    for (int i = 0; i < roots.length; i++) {
       FileReference ref = roots[i].toFileReference();
       Directory root = ref.openDirectory();
       list(root);
    }

  }

  public static void list(Directory dir) {
    try {
      for (Directory.Entry entry : dir) {
         FileReference ref = entry.asFileReference();
         System.out.println(entry.getName());
         try {
           Directory child = ref.openDirectory();
           // aliases?
           list(child);
         }
         catch (NotDirectoryException ex) {
           // There must be a better way to tell 
           // if a file is a directory before we open it
         }
      }
    } 
    finally {
      dir.close();
    }
  }
  

}

Basic attributes

import java.nio.filesystems.*;
import java.io.*;

public class FileSystemLister {

  public static void main(String[] args) throws IOException {

    File[] roots = File.listRoots();
    for (int i = 0; i < roots.length; i++) {
       FileReference ref = roots[i].toFileReference();
       Directory root = ref.openDirectory();
       list(root);
    }

  }

  public static void list(Directory dir) {
    try {
      for (Directory.Entry entry : dir) {
         FileReference ref = entry.asFileReference();
         System.out.println(entry.getName());

         // Now let's see what it is:
         BasicFileAttributes atts = ref.readBasicFileAttributes();
         BasicFileType = atts.getFileType(); 
         if (type == BasicFileType.LINK) continue;
         else if (type == BasicFileType.DIRECTORY) {
           Directory child = ref.openDirectory();
           list(child);
         }
      }
    } 
    finally {
      dir.close();
    }
  }
  
}

File Attributes

BasicFileAttributes
PosixFileAttributes
FATFileAttributes
ACLFileAttributes
ExtendedAttributeView
Arbitrary lists of attributes
NTFS????

Using a FileWalker

import java.nio.filesystems.*;
import java.io.*;

public class FileSystemLister {

  public static void main(String[] args) throws IOException {

    File[] roots = File.listRoots();
    for (int i = 0; i < roots.length; i++) {
       FileReference ref = roots[i].toFileReference();
       Files.walkFileTree(ref, false, new NamePrinter());
    }

  }


  class NamePrinter implements FileVisitor {

    void visit(FileReference file, Path path, BasicFileAttributes attrs) {
        System.out.println(path.getName());
    }

    void visit(FileReference file, Path path, IOException ex) {
        System.err.println(ex.getMessage());
    }

  }
  
}

This Time For Sure: Dates and Times


Units

JSR-275 specifies one or more Java packages for the programmatic handling of physical quantities and their expression as numbers of units. The specification includes:


Swing

I've used both SWT and Swing to develop client-side Java applications on and for the Mac - although nothing particularly complicated. Swing is complex as hell for anything other than trivial applications, and has a deserved reputation for bugs, performance problems, and lack of platform fidelity. SWT is much simpler, faster, and has the enormous advantage of actually using native UI widgets.

--Bill Hutten on the java-dev mailing list, Sunday, 5 Jun 2005 19:04:23

The biggest problem with Swing was that it can do so much that it’s kind of become like the 747 cockpit if you like APIs. There’s a lot of complexity there, and the hard part is figuring out how to use it. It’s in this weird situation where pretty much anything you can want to do in Swing, you can do easily. But what’s hard is to figure out the easy path through all of the different options, the different ways you can do things. Once you figure out the one true path to get what you want done, then it’s pretty easy. People often say “Why don’t you just make it easier by simplifying it?”, and say, “so you simplify it in this way, it would make my life better”. But then for the next guy it would be worse, because he wants to not go there, he wants to go on this particular path. So it’s been difficult to manage the complexity right.

--James Gosling
Read the rest in James Gosling Q & A: Builder AU: Program: At Work


Swing Application Framework


Bean Binding


Validation


What do we really need for Swing to work?


It's all about the tools


Possible Environment/VM Changes


Taking the JAM out of the JAR


Scripting


JavaDoc


Java Kernel


Tiered Compilation


To Learn More