The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Re: NullPointerException

That may be good and all for small programs, but when you get into a large program or start using a lot of objects you don't want to initialize anything until you use it. Less memory allocated, less operations, and easier to debug in your IDE. Good for beginners who cant overcome these error, but it is bad practice and should be avoided.

Re: NullPointerException

Originally Posted by Chris.Brown.SPE

That may be good and all for small programs, but when you get into a large program or start using a lot of objects you don't want to initialize anything until you use it. Less memory allocated, less operations, and easier to debug in your IDE. Good for beginners who cant overcome these error, but it is bad practice and should be avoided.

I find it easier to initialize objects but then again, there are people that don't like it. Nothing wrong with it though just my style of coding.

Re: NullPointerException

I agree that it is easier and it can help avoid unnecessary errors that noone wants to deal with, but saying there is nothing wrong with it is just naive. It uses memory when initialized and takes cpu cycles to initialize it. That is terrible practice when it is not needed. It is bloated code and is a common mistake to beginners. If you are writing small meaningless programs you wont notice, but you will if you ever write anything large.

Re: NullPointerException

Originally Posted by Chris.Brown.SPE

I agree that it is easier and it can help avoid unnecessary errors that noone wants to deal with, but saying there is nothing wrong with it is just naive. It uses memory when initialized and takes cpu cycles to initialize it. That is terrible practice when it is not needed. It is bloated code and is a common mistake to beginners. If you are writing small meaningless programs you wont notice, but you will if you ever write anything large.

I've created quite some java applications (and non java software) but thats not the whole point. Your points are all valid but i'm assuming that when you create an object the object will used it later on so its better to initialize it beforehand instead of try catching the whole thing or wait for a compile error to show up the message. Also the memory usage of initializing an object is minimal. If you want microperformance java isnt the langauge to code in anyway.

Re: NullPointerException

Now i think that is something we can agree on. Java is way too bloated as it is. But then again i've seen other languages that claim to be better that have default values initialized into every variable. I'm just glad i dont have to worry about space and speed in my job (for the most part), but i do have to worry about goverment standards. I'm not sure what there opinion on variable inicialization is. Haven't gotten that far yet.