The Java Tutorials have been written for JDK 8. Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.
See Dev.java for updated tutorials taking advantage of the latest releases.
See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.
public final class Algorithm { public staticT max(T x, T y) { return x > y ? x : y; } }
public class Pair{ public Pair(K key, V value) { this.key = key; this.value = value; } public K getKey() { return key; } public V getValue() { return value; } public void setKey(K key) { this.key = key; } public void setValue(V value) { this.value = value; } private K key; private V value; }
public static> int findFirstGreaterThan(T[] at, T elem) { // ... }
public static void print(List extends Number> list) { for (Number n : list) System.out.print(n + " "); System.out.println(); }
public class Singleton{ public static T getInstance() { if (instance == null) instance = new Singleton (); return instance; } private static T instance = null; }
class Shape { /* ... */ } class Circle extends Shape { /* ... */ } class Rectangle extends Shape { /* ... */ } class Node{ /* ... */ }
Nodenc = new Node<>(); Node ns = nc;
class Nodeimplements Comparable { public int compareTo(T obj) { /* ... */ } // ... }
Nodenode = new Node<>(); Comparable comp = node;
public staticint findFirst(List list, int begin, int end, UnaryPredicate p)