I am in the Beginner phase of learning Java. In all docs I have read till now, its mentioned that Java uses secure references to access objects instead of memory pointers. And also that when a method returns, its locally scoped variables become eligible for Garbage Collection.
So why in this below code, the JFrame object isn't destroyed along with the window after the createFrame method returns?
import javax.swing.*;
public class HelloJava {
public static void main( String[] args ) {
createFrame();
}
private static void createFrame() {
JFrame frame = new JFrame( "Hello, Java!" );
JLabel label = new JLabel( "Hello, Java!", JLabel.CENTER );
frame.getContentPane().add( label );
frame.setSize( 300, 300 );
frame.setVisible( true );
}
}
Not only the window is visible, I can do all the actions on that window like drag, maximize, minimize etc.