Explain the internal working of HashMap in Java. How are collisions handled, and how does the resizing mechanism work?