Your SlideShare is downloading. ×
0
Java15
Java15
Java15
Java15
Java15
Java15
Java15
Java15
Java15
Java15
Java15
Java15
Java15
Java15
Java15
Java15
Java15
Java15
Java15
Java15
Java15
Java15
Java15
Java15
Java15
Java15
Java15
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Java15

1,514

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,514
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
19
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Java 1.5 New Features
  • 2. java.applet, java.awt, java.io, java.lang, java.net, java.util java.math, java.rmi, java.security, java.sql, java.text, java.beans javax.accessibility, javax.swing, org.omg javax.naming, javax.sound, javax.transaction java.nio, javax.imageio, javax.net, javax.print, javax.security, org.w3c javax.activity, javax. management Java 1.0 8 packages 212 classes Java 1.1 23 packages 504 classes Java 1.2 59 packages 1520 classes Java 1.3 77 packages 1595 classes Java 1.4 103 packages 2175 classes Java 1.5 131 packages 2656 classes New Events Inner class Object Serialization Jar Files International Reflection JDBC RMI JFC/Swing Drag and Drop Java2D CORBA JNDI Java Sound Timer Regular Exp Logging Assertions NIO
  • 3. New Features <ul><li>Scanner </li></ul><ul><li>Printf </li></ul><ul><li>Autoboxing </li></ul><ul><li>Enumerated Types </li></ul><ul><li>Foreach loop </li></ul><ul><li>Generic Types </li></ul>
  • 4. Other New Features <ul><li>Static import: import static java.Math.*; </li></ul><ul><li>Variable length argument lists. </li></ul><ul><li>Semaphores </li></ul><ul><li>Metadata </li></ul>
  • 5. java.util.Scanner <ul><li>Scanner stdin = Scanner.create(System.in); </li></ul><ul><li>int n = stdin.nextInt(); </li></ul><ul><li>String s = stdin.next(); </li></ul><ul><li>boolean b = stdin.hasNextInt() </li></ul>
  • 6. printf method <ul><li>Similar to C style printf </li></ul><ul><li>Handles </li></ul><ul><ul><li>strings </li></ul></ul><ul><ul><li>native types </li></ul></ul><ul><ul><li>numeric types </li></ul></ul><ul><ul><li>java.util.Date </li></ul></ul><ul><li>See java.util.Formatter for details </li></ul>
  • 7. Autoboxing/Unboxing <ul><li>Wrap ints into Integers </li></ul><ul><li>Extract ints from Integers </li></ul><ul><li>This is now legal: </li></ul><ul><li>Integer x = 6; //6 is boxed </li></ul><ul><li>Integer y = 2*x + 3; //x is unboxed, 15 is boxed </li></ul><ul><li>You could hide primitives entirely! </li></ul>
  • 8. Object Only Performance <ul><li>int x = 6; </li></ul><ul><li>int y = 2*x; </li></ul><ul><li>Code: </li></ul><ul><li>0: bipush 6 </li></ul><ul><li>2: istore_1 </li></ul><ul><li>3: iconst_2 </li></ul><ul><li>4: iload_1 </li></ul><ul><li>5: imul </li></ul><ul><li>6: istore_2 </li></ul>
  • 9. Object Only Performance <ul><li>Integer x = 6; </li></ul><ul><li>Integer y = 2*x; </li></ul><ul><li>Code: </li></ul><ul><li>0: bipush 6 </li></ul><ul><li>2: invokestatic #2; </li></ul><ul><li>//Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer; </li></ul><ul><li>5: astore_1 </li></ul><ul><li>6: iconst_2 </li></ul><ul><li>7: aload_1 </li></ul><ul><li>8: invokevirtual #3; </li></ul><ul><li>//Method java/lang/Integer.intValue:()I </li></ul><ul><li>11: imul </li></ul><ul><li>12: invokestatic #2; </li></ul><ul><li>//Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer; </li></ul><ul><li>15: astore_2 </li></ul>
  • 10. Object Only Performance <ul><li>Integer x = Integer.valueOf(6); </li></ul><ul><li>Integer y = Integer.valueOf(2 * x.IntValue); </li></ul><ul><li>Generates the same byte code. </li></ul>
  • 11. Type-safe enum <ul><li>enum Day { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, </li></ul><ul><li>FRIDAY, SATURDAY } </li></ul><ul><li>//used </li></ul><ul><li>Day today = Day.WEDNESDAY; </li></ul><ul><li>switch(today){ </li></ul><ul><li>case SUNDAY: </li></ul><ul><li>break; </li></ul><ul><li>//… </li></ul><ul><li>} </li></ul>
  • 12. More Complex Enum <ul><li>enum Suit { </li></ul><ul><li>CLUBS(Color.BLACK), </li></ul><ul><li>DIAMONDS(Color.RED), </li></ul><ul><li>HEARTS(Color.RED), </li></ul><ul><li>SPADES(Color.BLACK); </li></ul><ul><li>private Color color; </li></ul><ul><li>Suit(Color color) { this.color = color; } </li></ul><ul><li>public Color getColor() { return color; } </li></ul><ul><li>} </li></ul>
  • 13. Generics <ul><li>ArrayList<Number> list = new ArrayList<Number>(); </li></ul><ul><li>list.add(new Integer(5)); </li></ul><ul><li>list.add(6); </li></ul><ul><li>list.add(new Double(3.14159/2)); </li></ul><ul><li>list.add(new BigInteger(&quot;123456789012301234567890&quot;)); </li></ul><ul><li>list.add(new Long(127L)); </li></ul><ul><li>Number n = list.get(i); </li></ul>
  • 14. Defining Generics <ul><li>public class GenericStack<T> implements Iterable<T> { </li></ul><ul><li>private T[] data; … </li></ul><ul><li>public GenericStack() { </li></ul><ul><li>data = (T[])new Object[MIN_SIZE]; … </li></ul><ul><li>} </li></ul><ul><li>public T pop(){ … } </li></ul><ul><li>public void push(T item) { … } </li></ul><ul><li>public Iterator<T> iterator(){ … } //since it is iterable </li></ul><ul><li>} </li></ul>
  • 15. Defining Generic Iterator <ul><li>//inner class of GenericStack </li></ul><ul><li>private class GenericStackIterator implements Iterator<T> { </li></ul><ul><li>int index; </li></ul><ul><li>GenericStackTestIterator() { </li></ul><ul><li>index = top; </li></ul><ul><li>} </li></ul><ul><li>public boolean hasNext() { return index >= 0; } </li></ul><ul><li>public T next() { </li></ul><ul><li>if(index < 0) { </li></ul><ul><li>throw new java.util.NoSuchElementException(); </li></ul><ul><li>} </li></ul><ul><li>T item = data[index]; </li></ul><ul><li>index--; </li></ul><ul><li>return item; </li></ul><ul><li>} </li></ul><ul><li>public void remove() { </li></ul><ul><li>throw new UnsupportedOperationException( ) </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  • 16. For each loop (arrays) <ul><li>double[] array = {2.5, 5.2, 7.9, 4.3, 2.0}; </li></ul><ul><li>for(double d: array) </li></ul><ul><li>{ </li></ul><ul><li>System.out.println(d); </li></ul><ul><li>} </li></ul><ul><li>Iterate (forward) through the array without paying attention to indices. </li></ul>
  • 17. For each loop (Collections) <ul><li>ArrayList<Integer> list = new ArrayList<Integer>(); </li></ul><ul><li>list.add(7); </li></ul><ul><li>list.add(15); </li></ul><ul><li>list.add(-67); </li></ul><ul><li>for(Integer number: list){ System.out.println(number); </li></ul><ul><li>} </li></ul>
  • 18. For each loop enums <ul><li>for( Suit s: Suit.values()){ </li></ul><ul><li>System.out.println(s.getColor()); </li></ul><ul><li>} </li></ul><ul><li>values() returns an Iterator for enum types </li></ul>
  • 19. Wish list <ul><li>Preprocessor </li></ul><ul><ul><li>Embedded languages: SQL, </li></ul></ul><ul><ul><li>Regular Expression syntax. </li></ul></ul><ul><li>Operator Overloading </li></ul><ul><ul><li>Assignment </li></ul></ul><ul><ul><li>Equality </li></ul></ul><ul><ul><li>[ ] for Lists </li></ul></ul>
  • 20. Classroom Incorporation <ul><li>Investigate use with undergrad. </li></ul><ul><li>Example: Servlets/JSP in Databases </li></ul><ul><li> JavaCard in Architecture. </li></ul><ul><li>Metadata for Generating Code in Compilers </li></ul>
  • 21. References <ul><li>Calvin Austin. J2SE 1.5 in a Nutshell . http://java.sun.com/developer/technicalArticles/releases/j2se15 </li></ul><ul><li>Gilad Bracha. Generics in the Java Programming Language . http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf </li></ul><ul><li>David Flanagan. Java in a Nutshell . O’Reilly. 1 st , 2 nd and 3 rd editions. </li></ul><ul><li>Cay Hortsmann and Gary Cornell. Core Java 2 . Prentice Hall. </li></ul>
  • 22. Examples online <ul><li>http://cs.gettysburg.edu/~cpresser/java </li></ul><ul><li>The latest additions will be made next week </li></ul><ul><li>Including this presentation. </li></ul><ul><li>email: cpresser@gettysburg.edu </li></ul>
  • 23. The End….
  • 24. No, really. Stop clicking.
  • 25. Java History <ul><ul><li>New event model </li></ul></ul><ul><ul><li>Inner classes </li></ul></ul><ul><ul><li>Object Serialization </li></ul></ul><ul><ul><li>JAR files </li></ul></ul><ul><ul><li>Internationalization </li></ul></ul><ul><ul><li>Reflection </li></ul></ul><ul><ul><li>Java Database Connectivity (JDBC) </li></ul></ul><ul><ul><li>Remote Method Invocation (RMI) </li></ul></ul>Java 1.0 8 Packages, 212 Classes Java 1.1 23 Packages, 504 Classes
  • 26. Java History <ul><ul><li>JFC (Swing) </li></ul></ul><ul><ul><li>Drag and Drop </li></ul></ul><ul><ul><li>Java 2D </li></ul></ul>Java 1.2 59 Packages, 1520 Classes <ul><ul><li>Java Naming and Directory Interface (JNDI) </li></ul></ul><ul><ul><li>Java Sound </li></ul></ul><ul><ul><li>Timer class </li></ul></ul>Java 1.3 77 Packages, 1595 Classes
  • 27. Java History <ul><ul><li>Regular Expressions </li></ul></ul><ul><ul><li>Assertions </li></ul></ul><ul><ul><li>Logging </li></ul></ul><ul><ul><li>New I/O (NIO) </li></ul></ul>Java 1.4 103 Packages, 2175 Classes <ul><ul><li>What, and ruin the surprise? </li></ul></ul>Java 1.5 131 Packages, 2656 Classes

×