The Artima Developer Community
Sponsored Link

Java Answers Forum
Declaration

1 reply on 1 page. Most recent reply: Jul 4, 2005 12:53 AM by Matthias Neumair

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Lynn Hollerman

Posts: 67
Nickname: gmholler
Registered: Mar, 2002

Declaration Posted: Jul 1, 2005 6:14 PM
Reply to this message Reply
Advertisement
I'm confused; a lot of it has to do with mixing another programmer's code and my own. But right now I'm looking at something and wondering why I never noticed this before. Let's say that I want to use a variable called "MyString" after some other, unrelated stuff in my class, but I keep all the declarations together at the top of the file for simplicity's sake. What is the difference between saying

String MyString = new String();

and

String MyString = null;

(Past the obvious, naturally. For some reason, the answer is not coming to me the way it should!)

Thanks!

Lynn.


Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Declaration Posted: Jul 4, 2005 12:53 AM
Reply to this message Reply
There is no difference.

In both cases all variables get declared, after that they get initialized.

You wrote the variables outside any method, right?
If you do so, they get declared and eentually initialized even before the constructor method is called.

Flat View: This topic has 1 reply on 1 page
Topic: how do we store a hashtable in Cache database Previous Topic   Next Topic Topic: Adding JMenu To a Jbutton

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use