Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6619757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:00:40+00:00 2026-05-25T21:00:40+00:00

My program looks like this: import java.awt.*; import javax.swing.*; public class Main { public

  • 0

My program looks like this:

import java.awt.*;
import javax.swing.*;

public class Main {
    public static void main(String[] args) {
        JFrame jf = new JFrame();
        jf.setSize(new Dimension(200, 200));
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jf.setVisible(true);
    }
}

I’m just confused why after JVM’s quitting from main(), my program does not end instantly? I noticed that if I remove the line “jf.setVisible(true);”, it will end.

Is it implemented though techniques like garbage collecting or class destructors? I’m interested that if I want to write something similar, how could I do it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:00:41+00:00Added an answer on May 25, 2026 at 9:00 pm

    The reason is that when you call setVisible(true) on the JFrame, behind the scenes a non-daemon thread is started, and the JVM will not exit until all non-daemon threads terminate.

    Please have a look here for more on AWT/Swing Threading issues.
    It states:

    “There is at least one alive non-daemon thread while there is at least one displayable AWT or Swing component within the application (see Component.isDisplayable).”

    While this is for Java 1.5, I think that it is still valid information.

    Also, I believe that the Event Dispatch Thread or EDT is not a daemon thread, and so it is another thread associated with Swing that drives this.

    Edit 1
    This suggests that the EDT is in fact a non-Daemon thread:

    import javax.swing.JFrame;
    import javax.swing.SwingUtilities;
    
    public class IsEdtDaemon {
       public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
             public void run() {
                 JFrame frame = new JFrame();
                 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                 frame.setVisible(true);
    
                 System.out.printf("Is the current thread the EDT thread: %b%n",  SwingUtilities.isEventDispatchThread());
                 System.out.printf("Is our EDT Thread a daemon thread:    %b%n",  Thread.currentThread().isDaemon());
             }
          });
       }
    }
    

    The output from the code is:

    Is the current thread the EDT thread: true
    Is our EDT Thread a daemon thread: false

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My Java program look like this : public class Biz_Manager { static Contact_Info_Setting Customer_Contact_Info_Panel;
I have a program that looks something like this: public partial class It {
I am really struggling with this question: import java.util.regex.*; class Regex2 { public static
I have a Python program for Linux almost looks like this one : import
Please see the following block of code import java.awt.Color; import java.awt.Dimension; import javax.swing.JFrame; import
My program looks like this: -(id)init { if ( (self = [super init]) )
For the moment my batch file look like this: myprogram.exe param1 The program starts
I have a program that looks like the following: double[4][4] startMatrix; double[4][4] inverseMatrix; initialize(startMatrix)
Have a look at this very simple example WPF program: <Window x:Class=WpfApplication1.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
I have a program that I run from the command line that looks like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.