Bart van Kuik Application Developer Oracle Corporation.

Slides:



Advertisements
Similar presentations
New features in JDK 1.5 Can these new and complex features simplify Java development?
Advertisements

Arrays.
Singleton vs utility class  at first glance, the singleton pattern does not seem to offer any advantages to using a utility class  i.e., a utility class.
1-May-15 Java 1.5. Reason for changes “The new language features all have one thing in common: they take some common idiom and provide linguistic support.
1 ADT and Data Structure Example Generics / Parameterized Classes Using a Set Implementing a Set with an Array Example: SetADT interface Example: ArraySet.
Week 9: Methods 1.  We have written lots of code so far  It has all been inside of the main() method  What about a big program?  The main() method.
Nov 10, Fall 2006IAT 8001 Debugging. Nov 10, Fall 2006IAT 8002 How do I know my program is broken?  Compiler Errors –easy to fix!  Runtime Exceptions.
Java Generics.
11-Jun-15 Generics. A generic is a method that is recompiled with different types as the need arises The bad news: Instead of saying: List words = new.
Compilation 2007 Java 1.5 Features Michael I. Schwartzbach BRICS, University of Aarhus.
Java 1.5 & Effective Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Generic Subroutines and Exceptions CS351 – Programming Paradigms.
15-Jul-15 Generics. ArrayList s and arrays A ArrayList is like an array of Object s, but... Arrays use [ ] syntax; ArrayList s use object syntax An ArrayList.
16-Jul-15 Java Versions of Java Java 1 Java 2 Java 5.0 Oak: Designed for embedded devices Java 1.1: Adds inner classes and a completely new event-handling.
Generic Java 21/ What is generics? To be able to assign type variables to a class These variables are not bound to any specific type until the.
Classes, Objects, Arrays, Collections and Autoboxing Dr. Andrew Wallace PhD BEng(hons) EurIng
Presented by: Mojtaba Khezrian. Agenda Object Creation Object Storage More on Arrays Parameter Passing For Each VarArgs Spring 2014Sharif University of.
P Object type and wrapper classes p Object methods p Generic classes p Interfaces and iterators Generic Programming Data Structures and Other Objects Using.
Chapter 21 Generics 1. Generics - Overview Generic Methods specify a set of related methods Generic classes specify a set of related types Software reuse.
Chapter 2: Everything is an Object ● C++ has many non object oriented features inherited from C. It is a hybrid language meaning that it support different.
7. Arrays. Topics Declaring and Using Arrays Some Array Algorithms Arrays of Objects Variable Length Parameter Lists Two-Dimensional Arrays The ArrayList.
Effective Java: Generics Last Updated: Spring 2009.
1162 JDK 5.0 Features Christian Kemper Principal Architect Borland.
Dale Roberts Object Oriented Programming using Java - Enumerations Dale Roberts, Lecturer Computer Science, IUPUI Department.
24-Oct-15 Java Java beta 1 (“Tiger”) Released February 4, Themes Ease of Development Scalability.
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
A First Simple Program /* This is a simple Java program. Call this file "Example.java".*/ class Example { // Your program begins with a call to main().
Java 5 Part 1 CSE301 University of Sunderland Harry Erwin, PhD.
Peyman Dodangeh Sharif University of Technology Fall 2013.
Java Generics Compiled from Core Java Technologies Tech Tips By Billy B. L. Lim.
Java Basics.  To checkout, use: svn co scb07f12/UTORid  Before starting coding always use: svn update.
1 Generics Chapter 21 Liang, Introduction to Java Programming.
ArrayList Class An ArrayList is an object that contains a sequence of elements that are ordered by position. An ArrayList is an object that contains a.
CompSci 100E 40.1 Java 5 New Features  Generics  Enhanced for loop  Autoboxing/unboxing  Typesafe enums  Other  Varargs  Static Import  Metadata.
G ENERICS I N J AVA BY: Ankit Goyal Sankalp Singh.
Types in programming languages1 What are types, and why do we need them?
Java 1.5 The New Java Mike Orsega Central Carolina CC.
Objects First With Java A Practical Introduction Using BlueJ Supplementary Material for Java
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors
Java 5 Part 2 CSE301 University of Sunderland Harry Erwin, PhD.
Java Nuts and Bolts Variables and Data Types Operators Expressions Control Flow Statements Arrays and Strings.
1 CSE 331 Generics (Parametric Polymorphism) slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
©SoftMoore ConsultingSlide 1 Generics “Generics constitute the most significant change in the Java programming language since the 1.0 release.” – Cay Horstmann.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Object Oriented Programming in Java Lecture 14. Review Quiz 1. Write a method which gets an Object and call all its available ‘get’ Methods and print.
Enterprise Java Java SE 5 TM Language Feature Enhancement Primary Source: New Features and Enhancements J2SE 5.0
Peyman Dodangeh Sharif University of Technology Spring 2014.
More Java: Static and Final, Abstract Class and Interface, Exceptions, Collections Framework 1 CS300.
1 CSC 2053 New from AutoBoxing 3 Before J2SE 5.0, working with primitive types required the repetitive work of converting between the primitive.
Arrays and ArrayLists Topic 6. One Dimensional Arrays Homogeneous – all of the same type Contiguous – all elements are stored sequentially in memory For.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
Methods What is a method? Main Method the main method is where a stand alone Java program normally begins execution common compile error, trying.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
New Java Features Advanced Programming Techniques.
Chapter 8 Arrays and the ArrayList Class Arrays of Objects.
Intro to Java L. Grewe.
Generics, Lambdas, Reflections
Generics A Brief Review 16-Nov-18.
Conditional Statements
An Introduction to Java – Part I, language basics
Generics 27-Nov-18.
More On Enumeration Types
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Generics, Lambdas, Reflections
Class.
CMPE212 – Reminders Course Web Site:
Java 5 New Features 1-May-19.
Generics 2-May-19.
Corresponds with Chapter 5
Presentation transcript:

Bart van Kuik Application Developer Oracle Corporation

Java 1.5 New Language Features

Java 1.5: Tiger  Less boilerplate code through syntax changes  But no new keywords so compatibility with existing code, except the enum keyword

Additions to Syntax  Generics  Enhanced for loop  Autoboxing/unboxing  Typesafe enums  Static Imports  Varargs  Metadata

Generics  Also called 'parameterized types', since you pass a parameter upon declaration and instantiation: List lijstMetNamen = new ArrayList (); // 1.4: runtime error / 1.5: compiler error lijstMetNamen.add(new Integer(1));  Feature: covariant return types

Enhanced for loop // Old syntax with iterators: List list = new ArrayList(); for(Iterator i = list.iterator(); i.hasNext();) { String s = (String) i.next(); System.out.println("String: " + s); } // New syntax List list = new ArrayList (); for (String s : list) { // do something} // The following is also possible: String naam = "Harry"; for (char c : naam.toCharArray()) { // do something }

Autoboxing/unboxing  public static void Cow.milk(Integer liter); public static void Monkey.throw(int distance);  From primitive to reference and back: int i = 4; Cow.milk(new Integer(i)); // 1.4 Cow.milk(i); // 1.5 Object obj = new Integer(3); Monkey.throw(((Integer)obj).intValue()); // 1.4 Monkey.throw((Integer)obj); // 1.5  Boxing null gives a NullPointerException

Typesafe enum s  Various disadvantages: class Kaart { static final int HARTEN = 0; static final int KLAVEREN = 1; static final int RUITEN = 2; static final int SCHOPPEN = 3; }  New syntax: public enum Kaart { harten, klaveren, ruiten, schoppen }

Static Imports  Before 1.5: lots of typing work to get a constant: ErrorConstants.XML_NOT_VALID  New type of import statement: import static com.elsevier.ew.ErrorConstants.*;  Both static attributes and methods

Varargs  Pass a variable number of arguments to a method  Like the C function: printf("value: %d", 15);  Compiler now understands this syntax: public static int optellen(int args...) { int resultaat = 0; for(i = 0; i < args.length; i++) restultaat = resultaat + args[i]; }

Metadata  Newest addition, separate JSR  Clues for precompilers, testtools, e.d.  C# attribute syntax: [xxx]  Java public static int add(int... params) { // blah }

Conclusie  Gone through the JCP  Early access 2.2 is downloadable  Beta and Final release somewhere in 2004  Big names: Joshua Blog, Neil Gafter

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