1 / 15

Bart van Kuik Application Developer Oracle Corporation

Bart van Kuik Application Developer Oracle Corporation. Java 1.5 New Language Features. Java 1.5: Tiger. Minder "standaard" code door syntax veranderingen Geen nieuwe keywords i.v.m. oude code, behalve enum. Toevoegingen Aan Syntax. Generics Enhanced for loop Autoboxing/unboxing

paloma-hall
Download Presentation

Bart van Kuik Application Developer Oracle Corporation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Bart van KuikApplication Developer Oracle Corporation

  2. Java 1.5 New Language Features

  3. Java 1.5: Tiger • Minder "standaard" code door syntax veranderingen • Geen nieuwe keywords i.v.m. oude code, behalve enum

  4. Toevoegingen Aan Syntax • Generics • Enhanced for loop • Autoboxing/unboxing • Typesafe enums • Static Imports • Varargs • Metadata

  5. Generics • Ook wel 'parameterized types' List<String> lijstMetNamen = new ArrayList<String>(); // 1.4: runtime error / 1.5: compiler error lijstMetNamen.add(new Integer(1)); • Feature: covariant return types

  6. Enhanced for loop List list = new List(); for(Iterator i = list.iterator(); i.hasNext();) { String s = (String) i.next(); System.out.println("String: " + s); } List<String> list = new List(); for (String s : list) { System.out.println("String: " + s); } String naam = "Harry"; for (char c : naam.toCharArray()) {}

  7. Autoboxing/unboxing • public static void Koe.melken(Integer liter);public static void Aap.gooien(int Aantal); • Automatisch primitive van/naar reference:int i = 4;Koe.melken(new Integer(i)); // 1.4Koe.melken(i); // 1.5Object obj = new Integer(3);Aap.gooien(((Integer)obj).intValue()); // 1.4Aap.gooien((Integer)obj); // 1.5 • null geeft een NullPointerException

  8. Typesafe enums • Diverse nadelen:class Kaart { static final int HARTEN = 0; static final int KLAVEREN = 1; static final int RUITEN = 2; static final int SCHOPPEN = 3;} • Nieuw:public enum Kaart { harten, klaveren, ruiten, schoppen}

  9. Static Imports • Pre 1.5: veel tikwerk om constanten te gebruiken, bijvoorbeeld:ErrorConstants.XML_NOT_VALID • Nieuwe vorm van import-statement:import static com.elsevier.ew.ErrorConstants.*; • Zowel static methods als attributes

  10. Varargs • Variabel aantal argumenten aan methoden • printf("Waarde: %d", 15); • Compiler begrijpt de volgende syntaxpublic static int optellen(int args...) { int resultaat = 0; for(i = 0; i < args.length; i++) restultaat = resultaat + args[i];}

  11. Metadata • Nieuwste toevoeging • Aanwijzing voor precompilers, testtools, e.d. • C# attribute syntax: [xxx] • Java metadata syntax: @xxx@testpublic static int optellen(int... params) { // blah}

  12. Conclusie • Door JCP gelopen • Early access 2.2 is te bewonderen • Beta en Final release ergens in 2004 • Grote namen: Joshua Blog, Neil Gafter

  13. Q & Q U E S T I O N S A N S W E R S A

More Related