0% found this document useful (0 votes)
18 views27 pages

Java 1.5 Features Overview

Java has evolved significantly over time, growing from 8 packages and 212 classes in version 1.0 to 131 packages and 2656 classes in version 1.5. Some of the major new features introduced in Java 1.5 include generics, autoboxing/unboxing, enumerated types, foreach loops, and the Scanner class.

Uploaded by

Uday Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views27 pages

Java 1.5 Features Overview

Java has evolved significantly over time, growing from 8 packages and 212 classes in version 1.0 to 131 packages and 2656 classes in version 1.5. Some of the major new features introduced in Java 1.5 include generics, autoboxing/unboxing, enumerated types, foreach loops, and the Scanner class.

Uploaded by

Uday Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd

Java 1.

5 New Features
Java 1.0 Java 1.1 Java 1.2 Java 1.3 Java 1.4 Java 1.5
8 packages 23 packages 59 packages 77 packages 103 packages 131 packages
212 classes 504 classes 1520 classes 1595 classes 2175 classes 2656 classes

New Events JFC/Swing JNDI Regular Exp [Link],


Logging javax.
Inner class Drag and Java Sound Assertions management
Drop NIO
Object Timer
Serialization Java2D [Link], [Link],
Jar Files CORBA [Link], [Link],
[Link], org.w3c
International
Reflection [Link], [Link],
[Link]
JDBC
RMI

[Link], [Link], [Link]

[Link], [Link], [Link], [Link], [Link], [Link]

[Link], [Link], [Link], [Link], [Link], [Link]


New Features
• Scanner
• Printf
• Autoboxing
• Enumerated Types
• Foreach loop
• Generic Types
Other New Features
• Static import: import static [Link].*;

• Variable length argument lists.

• Semaphores

• Metadata
[Link]
Scanner stdin = [Link]([Link]);

int n = [Link]();
String s = [Link]();

boolean b = [Link]()
printf method
• Similar to C style printf
• Handles
– strings
– native types
– numeric types
– [Link]

• See [Link] for details


Autoboxing/Unboxing
• Wrap ints into Integers
• Extract ints from Integers

This is now legal:


Integer x = 6; //6 is boxed
Integer y = 2*x + 3; //x is unboxed, 15 is boxed

You could hide primitives entirely!


Object Only Performance
int x = 6;
int y = 2*x;

Code:
0: bipush 6
2: istore_1
3: iconst_2
4: iload_1
5: imul
6: istore_2
Object Only Performance
Integer x = 6;
Integer y = 2*x;

Code:
0: bipush 6
2: invokestatic #2;
//Method java/lang/[Link]:(I)Ljava/lang/Integer;
5: astore_1
6: iconst_2
7: aload_1
8: invokevirtual #3;
//Method java/lang/[Link]:()I
11: imul
12: invokestatic #2;
//Method java/lang/[Link]:(I)Ljava/lang/Integer;
15: astore_2
Object Only Performance

Integer x = [Link](6);
Integer y = [Link](2 * [Link]);

Generates the same byte code.


Type-safe enum
enum Day { SUNDAY, MONDAY, TUESDAY,
WEDNESDAY, THURSDAY,
FRIDAY, SATURDAY }

//used
Day today = [Link];

switch(today){
case SUNDAY:
break;
//…
}
More Complex Enum
enum Suit {
CLUBS([Link]),
DIAMONDS([Link]),
HEARTS([Link]),
SPADES([Link]);

private Color color;

Suit(Color color) { [Link] = color; }

public Color getColor() { return color; }


}
Generics
ArrayList<Number> list = new
ArrayList<Number>();

[Link](new Integer(5));
[Link](6);
[Link](new Double(3.14159/2));
[Link](new
BigInteger("123456789012301234567890"));
[Link](new Long(127L));

Number n = [Link](i);
Defining Generics
public class GenericStack<T> implements Iterable<T> {
private T[] data; …
public GenericStack() {
data = (T[])new Object[MIN_SIZE]; …
}

public T pop(){ … }
public void push(T item) { … }

public Iterator<T> iterator(){ … } //since it is iterable


}
Defining Generic Iterator
//inner class of GenericStack
private class GenericStackIterator implements Iterator<T> {
int index;
GenericStackTestIterator() {
index = top;
}

public boolean hasNext() { return index >= 0; }


public T next() {
if(index < 0) {
throw new [Link]();
}
T item = data[index];
index--;
return item;
}

public void remove() {


throw new UnsupportedOperationException( )
}
}
For each loop (arrays)
double[] array = {2.5, 5.2, 7.9, 4.3, 2.0};

for(double d: array)
{
[Link](d);
}

Iterate (forward) through the array without paying


attention to indices.
For each loop (Collections)
ArrayList<Integer> list = new
ArrayList<Integer>();
[Link](7);
[Link](15);
[Link](-67);
for(Integer number: list)
{ [Link](number);
}
For each loop enums
for( Suit s: [Link]()){
[Link]([Link]());
}

values() returns an Iterator for enum types


Wish list
• Preprocessor
– Embedded languages: SQL,
Regular Expression syntax.

• Operator Overloading
– Assignment
– Equality
– [ ] for Lists
Classroom Incorporation
• Investigate use with undergrad.

• Example: Servlets/JSP in Databases


JavaCard in Architecture.

• Metadata for Generating Code in


Compilers
References
• Calvin Austin. J2SE 1.5 in a Nutshell.
[Link]
2se15

• Gilad Bracha. Generics in the Java Programming


Language.
[Link]

• David Flanagan. Java in a Nutshell. O’Reilly. 1st, 2nd and


3rd editions.

• Cay Hortsmann and Gary Cornell. Core Java 2. Prentice


Hall.
Examples online

[Link]

The latest additions will be made next week


Including this presentation.

email: cpresser@[Link]
The End….
No, really.
Stop clicking.
Java History
Java 1.0 8 Packages, 212 Classes
Java 1.1 23 Packages, 504 Classes
– New event model
– Inner classes
– Object Serialization
– JAR files
– Internationalization
– Reflection
– Java Database Connectivity (JDBC)
– Remote Method Invocation (RMI)
Java History
Java 1.2 59 Packages, 1520 Classes
– JFC (Swing)
– Drag and Drop
– Java 2D

Java 1.3 77 Packages, 1595 Classes


– Java Naming and Directory Interface (JNDI)
– Java Sound
– Timer class
Java History
Java 1.4 103 Packages, 2175 Classes
– Regular Expressions
– Assertions
– Logging
– New I/O (NIO)

Java 1.5 131 Packages, 2656 Classes


– What, and ruin the surprise?

You might also like