Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-28-2008, 09:46 AM
Senior Member
 
Join Date: Nov 2007
Posts: 115
ravian is on a distinguished road
initialization value problem
Hi,

I am confused about the initialization values in Java. I tried the following code and got an error:


Code:
boolean flag; System.out.println("Printing boolean flag's value: " + flag);
Exception:
Code:
The local variable flag may not have been initialized
I assumed that flag will have false in it. I tried a boolean array and it had false in all the indexes by default.

Please guide me.

Thanks a lot.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-28-2008, 09:57 AM
Member
 
Join Date: Nov 2007
Posts: 14
kureikougaiji is on a distinguished road
hmm..
it depends on what you want.. if you want it to be false in the start of your program, initialize it..

boolean flag=false;
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-28-2008, 11:54 AM
roots's Avatar
Moderator
 
Join Date: Jan 2008
Location: Dallas
Posts: 263
roots is on a distinguished road
This behavior doesnot work with local variables .. If you have code like this then it will be perfectly okay
Code:
public class NativeTypeInitializationDemo { public boolean flag; NativeTypeInitializationDemo(){ System.out.println("apple" + flag); } public static void main(String[] args){ new NativeTypeInitializationDemo(); } }
__________________
dont worry newbie, we got you covered.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Initialization and re-assignment of arrays Java Tip java.lang 0 04-14-2008 09:38 PM
How to use Initialization callbacks in Spring Framework Java Tip Java Tips 0 03-31-2008 11:16 AM
Icon initialization problem saz25 AWT / Swing 1 12-24-2007 11:37 PM
Lazy Initialization onegcr New To Java 1 08-14-2007 04:29 PM
log4j initialization arfatkhan Web Frameworks 3 08-10-2007 08:42 PM


All times are GMT +3. The time now is 11:52 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org