Results 1 to 8 of 8
- 01-10-2013, 09:21 AM #1
Member
- Join Date
- Jan 2013
- Posts
- 3
- Rep Power
- 0
Why this java code has written this way?
Can someone tell me about this style of writing in java?
Java Code:private static final String[] NORM_STRINGS = new String['z' - 'a' + 1]; { COLLATOR.setStrength(Collator.PRIMARY); for (char b = 'a'; b <= 'z'; b++) { NORM_STRINGS[b - 'a'] = new String(new char[] { b }); } }Last edited by talenone; 01-10-2013 at 09:28 AM.
- 01-10-2013, 09:40 AM #2
Re: Why this java code has written this way?
What about it?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 01-10-2013, 09:44 AM #3
Member
- Join Date
- Jan 2013
- Posts
- 3
- Rep Power
- 0
Re: Why this java code has written this way?
I'm trying to understand the way syntax has been written; the block of code in braces soon after the declaration seems like method, isn't it?
- 01-10-2013, 10:19 AM #4
AN21XX
- Join Date
- Mar 2012
- Location
- Munich
- Posts
- 297
- Rep Power
- 2
Re: Why this java code has written this way?
Well it is not a good or nice code style. It is probably written like that to confuse someone intentionally.
I like likes!.gif)
- 01-10-2013, 10:34 AM #5
Member
- Join Date
- Jan 2013
- Posts
- 3
- Rep Power
- 0
Re: Why this java code has written this way?
My question is how the Java compiler interpret this code?
- 01-10-2013, 10:47 AM #6
AN21XX
- Join Date
- Mar 2012
- Location
- Munich
- Posts
- 297
- Rep Power
- 2
Re: Why this java code has written this way?
It depends on what is enclosing all this... it is not the whole code, so we cannot tell you that.
The first line is a declaration so the assumption is that this level is inside a class declaration.
Then follows a code block which is executed as is at the beginning straight away as far as I know it.I like likes!.gif)
- 01-10-2013, 10:54 AM #7
Member
- Join Date
- Jan 2013
- Location
- INDIA
- Posts
- 18
- Rep Power
- 0
Re: Why this java code has written this way?
its simple code just replace 'a' and 'z' with its ascii value. and you will get answer. :)
- 01-10-2013, 11:09 AM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,399
- Blog Entries
- 7
- Rep Power
- 17
Re: Why this java code has written this way?
I would've written the above snippet as:
I don't know if it matters much but the original version allocates two objects (a char array and a String) and I hope those Sun folks were a bit more clever ...Java Code:NORM_STRINGS[b - 'a'] = new String.valueOf(b);
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Need some help with java coding
By iamamyth in forum New To JavaReplies: 5Last Post: 01-05-2013, 09:43 AM -
does gui coding in netbeans is just the same with coding without nebeans?
By maizuddin35 in forum NetBeansReplies: 4Last Post: 10-25-2010, 03:49 PM -
help with java coding
By helpisontheway in forum New To JavaReplies: 4Last Post: 11-14-2009, 07:00 AM -
Long boolean coding style
By Aldius in forum New To JavaReplies: 10Last Post: 10-23-2009, 12:51 AM -
java coding
By zawad in forum Suggestions & FeedbackReplies: 1Last Post: 07-07-2009, 01:55 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks