I took the following code from a tutorial:
import javax.swing.*;
import java.util.Date;
public class SwingGUI {
public static void main( String[] args
The problem is not in code.
It is due to JRE misconfiguration for project. It may be due to difference between the project's JRE and workspace's Jre.
It may be solved by Updating Eclipse or Jre...
But from my side, I recommend you to do so..
Goto Window-->Preferences-->Java-->Installed JREs--->Execution Environments-->Select Project's JRE and tick the perfect matching installed JRE.
If you have not a matching JRE download and add it in Installed JREs using Add Button.
At last, RESTART your Eclipse IDE. This worked fine for me...
If it does not work, UPDATE Eclipse..