New Features in Java 1.2

Java 1.2, also known as Java 2, was released in December 1998 and introduced several significant features and improvements.



Key Features Introduced in Java 1.2:

  • Swing GUI Framework: A more flexible and customizable set of GUI components compared to the older AWT.
  • Collections Framework: Introduced a unified architecture for representing and manipulating collections, including interfaces like List, Set, and Map, along with their implementations.
  • JIT (Just-In-Time) Compiler: Significantly improved Java's performance by compiling bytecode to native machine code at runtime.
  • strictfp Keyword: Ensured floating-point calculations are strictly consistent across different platforms.


Code Example: Using the new Collections Framework

public class Java12Example {

    public static void main(String[] args) {
        // Using the new ArrayList class from the Collections Framework
        List cities = new ArrayList();
        cities.add("New York");
        cities.add("London");
        cities.add("Tokyo");

        // Using the new HashMap class
        Map cityPopulation = new HashMap();
        cityPopulation.put("New York", new Integer(8336817));
        cityPopulation.put("London", new Integer(8982000));
        cityPopulation.put("Tokyo", new Integer(13929286));

        // Iterating over the List
        System.out.println("Cities:");
        for (int i = 0; i < cities.size(); i++) {
            System.out.println(cities.get(i));
        }

        // Iterating over the Map
        System.out.println("\nCity Populations:");
        Iterator it = cityPopulation.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry entry = (Map.Entry)it.next();
            System.out.println(entry.getKey() + ": " + entry.getValue());
        }
    }
}

Detailed overview of Java 1.2 in relation to its previous and next versions:

Aspect Details
Version Java 1.2 (Java 2)
Release Date December 8, 1998
Previous Version Java 1.1 (February 19, 1997)
Next Version Java 1.3 (May 8, 2000)
Days after Previous Release Approximately 657 days
Days before Next Release Approximately 517 days

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!