There's little difference between the two. The first example simply uses the default content pane create by the parent window, where by the second creates its own content pane and uses the reference directly.
You could also use...
Container contentPane = getContentPane();
JLabel lblNewLabel = new JLabel("Name");
contentPane.add(lblNewLabel, BorderLayout.NORTH);
Take a look at How to use Root Panes for more details
I should highlight the fact that, by default, JFrame
's content pane uses a BorderLiayout
, meaning you first example doesn't need to set the layout, but JPanel
uses FlowLayout
, so it changed the layout manager to confirm to the expections of a JFrame
...I guess ;)