Tuesday, May 22nd 2012, 12:54am UTC+2

You are not logged in.

  • Login
  • Register

theuserbl

Intermediate

1

Tuesday, May 31st 2011, 10:24pm

Java 7 and Java 8 features

If you want to know, which are the new features of the upcomming Java 7 and shrtly after that comming Java 8, then have a look at that RedHat Summit 2011 slides:
http://www.redhat.com/summit/2011/presen…_lies_ahead.pdf

For example in Java 7 it will be - like in Jabaco - possible to use switch for Strings:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public static void printFullMonthName(String month) {
  switch (month) {
    case "jan" :
      System.out.println("Januaray");
      break;
    case "feb" :
      System.out.println("February");
      break;
    case "mar" :
      System.out.println("March");
      break;
    case "apr" :
      System.out.println("April");
      break;
      /* rest of the month */
    default :
      System.out.println("Unknown month");
      break;
  }
}



It will support binary literals:

Jabaco Source

1
2
3
4
5
6
7
8
9
public class WindowProperties {
  public static final int SHOW_STATUS = 0b00000001;
  public static final int SHOW_MENU   = 0b00000010;
  public static final int SHOW_BORDER = 0b00000100;

  private int properties = SHOW_STATUS | SHOW_MENU;

  /* Rest of the code */
}



Underscores in numeric literals for eaier reading:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
public void foo {
  System.out.println(0b001000100001);   // 545
  System.out.println(0b001_0001_00001); // 545

  System.out.println(0202122);          // 66642
  System.out.println(0_20_21_22);       // 66642
  System.out.println(020_21_22);        // 66642

  System.out.println(200201202);        // 200201202
  System.out.println(200_201_202);      // 200201202

  System.out.println(0xCAFEBABE);       // -889275714
  System.out.println(0xCAFE_BABE);      // -889275714
}



Multi-catch in JDK 7:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public class DavesNotHere extends Exception {}
public class DavesSleeping extends Exception {}

public void askForDave() throws DavesNotHere, DavesSleeping {
  try {
    switch (state)  {
      case NOT_HERE:
         throw new DavesNotHere();
      case SLEEPING:
         throw new DavesSleeping();
      case HERE:
         getDave();
         break();
    } catch (DavesNotHere | DavesSleeping e)  {    // !!! Multi catch !!!
      log(e);
      throw e;
    } catch (Throwable t) {
      logUnexpected(t);
    }
  }
}



Quoted

And with Java 8 there comes the results of project Jigsaw:
- JDK broken into modules based on functionality
- No more CLASSPATH
- New format to replace JAR files


Don'z know how to add additinal libaries without setting a CLASSPATH. And don't know what the new format would be, that replaces JAR-files. Would it again a compression algorithm?
I let me surprise.

For more additional features and informations of the upcomming Java-Versions read the PDF-file I mentioned.

Rate this thread
WoltLab Burning Board