Java 15
Java 15
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
• Semaphores
• Metadata
java.util.Scanner
Scanner stdin = Scanner.create(System.in);
int n = stdin.nextInt();
String s = stdin.next();
boolean b = stdin.hasNextInt()
printf method
• Similar to C style printf
• Handles
– strings
– native types
– numeric types
– java.util.Date
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/Integer.valueOf:(I)Ljava/lang/Integer;
5: astore_1
6: iconst_2
7: aload_1
8: invokevirtual #3;
//Method java/lang/Integer.intValue:()I
11: imul
12: invokestatic #2;
//Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
15: astore_2
Object Only Performance
Integer x = Integer.valueOf(6);
Integer y = Integer.valueOf(2 * x.IntValue);
//used
Day today = Day.WEDNESDAY;
switch(today){
case SUNDAY:
break;
//…
}
More Complex Enum
enum Suit {
CLUBS(Color.BLACK),
DIAMONDS(Color.RED),
HEARTS(Color.RED),
SPADES(Color.BLACK);
list.add(new Integer(5));
list.add(6);
list.add(new Double(3.14159/2));
list.add(new
BigInteger("123456789012301234567890"));
list.add(new Long(127L));
Number n = list.get(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) { … }
for(double d: array)
{
System.out.println(d);
}
• Operator Overloading
– Assignment
– Equality
– [ ] for Lists
Classroom Incorporation
• Investigate use with undergrad.
http://cs.gettysburg.edu/~cpresser/java
email: [email protected]
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