Java programming style
<p>its a maybe a dumb question but i am curious to understand this thing....
The below code works but the one below that doesn't work.</p>

<pre><code>import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Menu extends JFrame
{

public Menu()
{

JMenuBar menubar = new JMenuBar();
ImageIcon icon = new ImageIcon("exit.png");
JMenu file = new JMenu("File");
file.setMnemonic(KeyEvent.VK_F);
JMenuItem fileClose = new JMenuItem("Close",icon);
fileClose.setMnemonic(KeyEvent.VK_C);
fileClose.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event)
{System.exit(0);}
});


file.add(fileClose);
menubar.add(file);
setJMenuBar(menubar);


setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(300,200);
setLocationRelativeTo(null);
}


public static void main (String args[])
{
new Menu();
}


}
</code></pre>

<p>The below one doesn't work</p>

<pre><code>import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Menu extends JFrame
{

public Menu()
{


setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(300,200);
setLocationRelativeTo(null);

JMenuBar menubar = new JMenuBar();
ImageIcon icon = new ImageIcon("exit.png");
JMenu file = new JMenu("File");
file.setMnemonic(KeyEvent.VK_F);
JMenuItem fileClose = new JMenuItem("Close",icon);
fileClose.setMnemonic(KeyEvent.VK_C);
fileClose.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event)
{System.exit(0);}
});


file.add(fileClose);
menubar.add(file);
setJMenuBar(menubar);


}


public static void main (String args[])
{
new Menu();
}


}
</code></pre>

<p>I thought Java supports free style coding !!! (that's what it says in my Book)</p>

<p><em>PS: Please Someone Edit the Tile to suit the question correctly, I am not sure what to put in Title.</em></p>
