Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2006

Tip: Looking for answers? Try searching our database.

new byte always initialized to 0?

Thread view: 
34stunts@gmail.com - 19 Sep 2006 23:58 GMT
Consider the following code:
byte b[] = new byte[34];
for (int x = 0; x < b.length; x++)
{
    System.out.println((int) b[x] );
}

Java compiles it and runs it. This prints a bunch of "0".

So my question is this correct code? Or should/must I have a loop to
assign it to 0. Is it a rule that a newly created byte is 0 or is this
merly a coincidence?

-
Fred
34stunts@gmail.com - 20 Sep 2006 00:08 GMT
Sorry for the spam :-(
Andrew Thompson - 20 Sep 2006 02:17 GMT
> Sorry for the spam :-(

Posting a single post 3 times to one group may be overkill,
but it is not spam.  I think the term is 'reposting'.

The term spam generally refers to advertising of products.

Noting that you are posting through Google groups, I
think I can guess the basic reason ..the Google groups
server told you it 'could not complete that action' (or
similar words)?

A tip is to keep a second browser open, pointing to the group.
After posting, or when you get a message like that - wait
a few seconds and refresh the page showing the group
'titles' list - the podt will often make it through - depsite
what the server claimed.

(I am not sure on your technical query - I'll leave that for
the JLS gurus)

Andrew T.
Ian Shef - 26 Sep 2006 22:54 GMT
34stunts@gmail.com wrote in news:1158706730.366377.71600
@b28g2000cwb.googlegroups.com:

> Consider the following code:
> byte b[] = new byte[34];
[quoted text clipped - 8 lines]
> assign it to 0. Is it a rule that a newly created byte is 0 or is this
> merly a coincidence?

The JLS (3rd edition) at paragraph 4.12.5 says:

   4.12.5  Initial Value of Variables

   Every variable in a program must have a value before its value is used:
     • Each class variable, instance variable, or array component is
       initialized with a default value when it is created (§15.9, §15.10):
        For type byte, the default value is zero, that is,
         the value of (byte)0.

... so the answer is that this is a rule and not a coincidence.

Signature

Ian Shef     805/F6      *    These are my personal opinions    
Raytheon Company         *    and not those of my employer.
PO Box 11337             *
Tucson, AZ 85734-1337    *



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.