A comprehensive guide to all Java 1.2 concepts with practical examples for interview preparation.
Java 1.2 introduced the Collections Framework, providing a unified architecture for representing and manipulating collections.
The Collections Framework provides implementations of data structures like lists, sets, and maps.
import java.util.*;
// List - Ordered collection
List<String> list = new ArrayList<>();
list.add("Java");
list.add("Python");
list.add("C++");
// Set - No duplicates
Set<Integer> set = new HashSet<>();
set.add(1);
set.add(2);
set.add(1); // Duplicate, ignored
// Map - Key-value pairs
Map<String, Integer> map = new HashMap<>();
map.put("Java", 1995);
map.put("Python", 1991);- ArrayList: Dynamic array implementation
- LinkedList: Doubly-linked list
- HashSet: Hash table-based set
- TreeSet: Sorted set
- HashMap: Hash table-based map
- TreeMap: Sorted map
- Unified API
- Reusable data structures
- Type-safe collections
- High performance
- Standard implementations
See CollectionsFrameworkExample.java for complete example.
Swing provides a rich set of GUI components, replacing AWT for most GUI applications.
Swing is built on AWT but provides lightweight, platform-independent components.
import javax.swing.*;
public class SwingExample extends JFrame {
public SwingExample() {
setTitle("Swing Example");
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton button = new JButton("Click Me");
JLabel label = new JLabel("Hello Swing");
setLayout(new FlowLayout());
add(label);
add(button);
setVisible(true);
}
}- Lightweight components
- Pluggable look and feel
- Rich component set
- Better than AWT
- MVC architecture
See SwingExample.java for complete example.
The strictfp keyword ensures consistent floating-point calculations across platforms.
strictfp guarantees that floating-point calculations produce the same results on all platforms.
strictfp class Calculator {
strictfp double calculate(double a, double b) {
return a * b / 3.14;
}
}- Platform-independent floating-point
- Consistent results
- IEEE 754 compliance
- Can be applied to classes, interfaces, and methods
See StrictfpExample.java for complete example.
Java Plug-in allows applets to run in web browsers with better control.
Java Plug-in provides a way to run Java applets in browsers with improved security and performance.
- Better applet execution
- Improved security
- Better performance
- Cross-browser support
Note: Java Plug-in and applets are deprecated in modern Java.
A: Unified architecture for collections:
- Core interfaces: List, Set, Map
- Implementations: ArrayList, HashSet, HashMap
- Algorithms: Sorting, searching
- Type-safe collections
A:
- ArrayList: Array-based, fast random access, slower insertions
- LinkedList: Node-based, slow random access, fast insertions
- Use ArrayList for frequent access
- Use LinkedList for frequent insertions/deletions
A: GUI framework:
- Lightweight components
- Platform-independent
- Rich component set
- Better than AWT
- Pluggable look and feel
A: Keyword for consistent floating-point:
- Ensures same results on all platforms
- IEEE 754 compliance
- Can be applied to classes, interfaces, methods
A:
- Set: No duplicates, unordered (HashSet) or sorted (TreeSet)
- List: Allows duplicates, maintains insertion order
- Set for unique elements
- List for ordered collections with duplicates
Last Updated: 2025
Version: 1.0
This guide covers the features of Java 1.2, released on December 8, 1998.