Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #23918 > unrolled thread
| Started by | sout saret <saretmis097@gmail.com> |
|---|---|
| First post | 2013-05-07 23:30 -0700 |
| Last post | 2013-05-15 03:50 -0700 |
| Articles | 20 on this page of 49 — 12 participants |
Back to article view | Back to comp.lang.java.programmer
How to convert image into Hex 2 Dimensional Array? sout saret <saretmis097@gmail.com> - 2013-05-07 23:30 -0700
Re: How to convert image into Hex 2 Dimensional Array? lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-05-08 09:06 +0100
Re: How to convert image into Hex 2 Dimensional Array? Joerg Meier <joergmmeier@arcor.de> - 2013-05-08 12:29 +0200
Re: How to convert image into Hex 2 Dimensional Array? lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-05-08 13:28 +0100
Re: How to convert image into Hex 2 Dimensional Array? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-05-08 15:19 +0200
Re: How to convert image into Hex 2 Dimensional Array? lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-05-08 14:57 +0100
Re: How to convert image into Hex 2 Dimensional Array? Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-05-08 08:22 -0700
Re: How to convert image into Hex 2 Dimensional Array? lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-05-08 17:03 +0100
Re: How to convert image into Hex 2 Dimensional Array? Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-05-08 13:44 -0700
Re: How to convert image into Hex 2 Dimensional Array? lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-05-08 17:48 +0100
Re: How to convert image into Hex 2 Dimensional Array? Arne Vajhøj <arne@vajhoej.dk> - 2013-05-08 21:10 -0400
Re: How to convert image into Hex 2 Dimensional Array? Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-05-08 12:52 -0400
Re: How to convert image into Hex 2 Dimensional Array? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-05-08 17:32 +0200
Re: How to convert image into Hex 2 Dimensional Array? lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-05-08 17:17 +0100
Re: How to convert image into Hex 2 Dimensional Array? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-05-08 18:46 +0200
Re: How to convert image into Hex 2 Dimensional Array? lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-05-08 18:25 +0100
Re: How to convert image into Hex 2 Dimensional Array? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-05-08 23:24 +0200
Re: How to convert image into Hex 2 Dimensional Array? Joshua Cranmer 🐧 <Pidgeot18@verizon.invalid> - 2013-05-08 11:46 -0500
Re: How to convert image into Hex 2 Dimensional Array? Arne Vajhøj <arne@vajhoej.dk> - 2013-05-08 21:04 -0400
Re: How to convert image into Hex 2 Dimensional Array? Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-05-08 21:45 -0400
Re: How to convert image into Hex 2 Dimensional Array? Arne Vajhøj <arne@vajhoej.dk> - 2013-05-08 21:59 -0400
Re: How to convert image into Hex 2 Dimensional Array? Arne Vajhøj <arne@vajhoej.dk> - 2013-05-08 22:03 -0400
Re: How to convert image into Hex 2 Dimensional Array? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-05-09 04:09 +0200
Re: How to convert image into Hex 2 Dimensional Array? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-05-09 04:09 +0200
Re: How to convert image into Hex 2 Dimensional Array? Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-05-08 23:18 -0400
Re: How to convert image into Hex 2 Dimensional Array? Arne Vajhøj <arne@vajhoej.dk> - 2013-05-09 22:05 -0400
Re: How to convert image into Hex 2 Dimensional Array? Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-05-10 09:46 -0700
Re: How to convert image into Hex 2 Dimensional Array? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-05-10 19:02 +0200
Re: How to convert image into Hex 2 Dimensional Array? Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-05-10 11:00 -0700
Re: How to convert image into Hex 2 Dimensional Array? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-05-10 23:42 +0200
Re: How to convert image into Hex 2 Dimensional Array? Arne Vajhøj <arne@vajhoej.dk> - 2013-05-10 18:20 -0400
Re: How to convert image into Hex 2 Dimensional Array? Jeff Higgins <jeff@invalid.invalid> - 2013-05-08 12:43 -0400
Re: How to convert image into Hex 2 Dimensional Array? lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-05-08 18:45 +0100
Re: How to convert image into Hex 2 Dimensional Array? Jeff Higgins <jeff@invalid.invalid> - 2013-05-08 11:18 -0400
Re: How to convert image into Hex 2 Dimensional Array? Joshua Cranmer 🐧 <Pidgeot18@verizon.invalid> - 2013-05-08 11:52 -0500
Re: How to convert image into Hex 2 Dimensional Array? lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-05-08 18:40 +0100
Re: How to convert image into Hex 2 Dimensional Array? Joshua Cranmer 🐧 <Pidgeot18@verizon.invalid> - 2013-05-08 13:54 -0500
Re: How to convert image into Hex 2 Dimensional Array? lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-05-08 20:43 +0100
Re: How to convert image into Hex 2 Dimensional Array? lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-05-11 09:28 +0100
Re: How to convert image into Hex 2 Dimensional Array? Arne Vajhøj <arne@vajhoej.dk> - 2013-05-11 08:50 -0400
Re: How to convert image into Hex 2 Dimensional Array? lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-05-11 15:00 +0100
Re: How to convert image into Hex 2 Dimensional Array? Arne Vajhøj <arne@vajhoej.dk> - 2013-05-12 21:45 -0400
Re: How to convert image into Hex 2 Dimensional Array? Manuel Dahmen <manuel.dahmen@gmail.com> - 2013-05-08 15:38 -0700
Re: How to convert image into Hex 2 Dimensional Array? Roedy Green <see_website@mindprod.com.invalid> - 2013-05-11 13:33 -0700
Re: How to convert image into Hex 2 Dimensional Array? Arne Vajhøj <arne@vajhoej.dk> - 2013-05-12 21:48 -0400
Re: How to convert image into Hex 2 Dimensional Array? markspace <markspace@nospam.nospam> - 2013-05-12 20:49 -0700
Re: How to convert image into Hex 2 Dimensional Array? Arne Vajhøj <arne@vajhoej.dk> - 2013-05-13 19:08 -0400
Re: How to convert image into Hex 2 Dimensional Array? Roedy Green <see_website@mindprod.com.invalid> - 2013-05-15 03:45 -0700
Re: How to convert image into Hex 2 Dimensional Array? Roedy Green <see_website@mindprod.com.invalid> - 2013-05-15 03:50 -0700
Page 1 of 3 [1] 2 3 Next page →
| From | sout saret <saretmis097@gmail.com> |
|---|---|
| Date | 2013-05-07 23:30 -0700 |
| Subject | How to convert image into Hex 2 Dimensional Array? |
| Message-ID | <41718873-b1a6-4b97-bbbb-8002c48d4e29@googlegroups.com> |
Dear Community!
May you help me how to write code in java to convert image to Hex 2 dimensional array. I want to show format as below:
{
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1B,0xFB,0x12,0x0A,0x1B,0x0B,0x09,0x09,0x19,0x09,0x19,0x29,0x19,0xE9,0x00,0x20,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6D,0xFD,0x48,0x05,0x6D,0xF5,0x25,0x14,0x25,0x15,0x25,0x15,0xFD,0x15,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,},
{0x00,0xC0,0x01,0x00,0x01,0xC0,0x00,0x00,0xBC,0x78,0x24,0x48,0xA4,0x48,0xA4,0x48,0xB4,0x48,0xB5,0x48,0xB6,0xC8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,},
};
Best Regard!
Saret Sout
[toc] | [next] | [standalone]
| From | lipska the kat <"nospam at neversurrender dot co dot uk"> |
|---|---|
| Date | 2013-05-08 09:06 +0100 |
| Message-ID | <GKCdnX3n1aHvmhfMnZ2dnUVZ8s6dnZ2d@bt.com> |
| In reply to | #23918 |
On 08/05/13 07:30, sout saret wrote:
> Dear Community!
>
> May you help me how to write code in java to convert image to Hex 2 dimensional array. I want to show format as below:
[snip]
hmm, sounds like homework.
1. get hold of the javadoc for your chosen Java version
Then ...
To get you started.
import javax.swing.ImageIcon;
public class ImageToHex {
public static void main(String[] args) {
ImageIcon ii = new ImageIcon("/path/to/image.ext");
Integer width = ii.getIconWidth();
Integer height = ii.getIconHeight();
Byte[][] bytes = new Byte[width][height];
//you now have 2 dimensional array into which
//you can read your image bytes
//the rest is up to you I guess
}
}
I'm sure there are other/better ways of doing it
lipska
--
Lipska the Kat©: Troll hunter, sandbox destroyer
and farscape dreamer of Aeryn Sun
[toc] | [prev] | [next] | [standalone]
| From | Joerg Meier <joergmmeier@arcor.de> |
|---|---|
| Date | 2013-05-08 12:29 +0200 |
| Message-ID | <e3113x8fg4ip$.1c07xorvh5oei$.dlg@40tude.net> |
| In reply to | #23919 |
On Wed, 08 May 2013 09:06:09 +0100, lipska the kat wrote: > On 08/05/13 07:30, sout saret wrote: >> May you help me how to write code in java to convert image to Hex 2 dimensional array. I want to show format as below: > [snip] > hmm, sounds like homework. It sounded more like he wanted to hardcode an image into his class files, which is a fantastically terrible idea that's usually attempted by people who decided that loading resources in jar files is too complicated to figure out, which is why I stayed away ;) Liebe Gruesse, Joerg -- Ich lese meine Emails nicht, replies to Email bleiben also leider ungelesen.
[toc] | [prev] | [next] | [standalone]
| From | lipska the kat <"nospam at neversurrender dot co dot uk"> |
|---|---|
| Date | 2013-05-08 13:28 +0100 |
| Message-ID | <vNidncfyRa1m2RfMnZ2dnUVZ8hYAAAAA@bt.com> |
| In reply to | #23920 |
On 08/05/13 11:29, Joerg Meier wrote: > On Wed, 08 May 2013 09:06:09 +0100, lipska the kat wrote: > >> On 08/05/13 07:30, sout saret wrote: >>> May you help me how to write code in java to convert image to Hex 2 dimensional array. I want to show format as below: >> [snip] > >> hmm, sounds like homework. > > It sounded more like he wanted to hardcode an image into his class files, > which is a fantastically terrible idea that's usually attempted by people > who decided that loading resources in jar files is too complicated to > figure out, which is why I stayed away ;) Eek, surely not lipska -- Lipska the Kat©: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun
[toc] | [prev] | [next] | [standalone]
| From | Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> |
|---|---|
| Date | 2013-05-08 15:19 +0200 |
| Message-ID | <kmdj5i$sk9$1@dont-email.me> |
| In reply to | #23919 |
On 08/05/2013 10:06, lipska the kat allegedly wrote: > Byte[][] bytes = new Byte[width][height]; Lipska, mind the difference between Byte and byte. That code above is extremely bad advice. -- DF.
[toc] | [prev] | [next] | [standalone]
| From | lipska the kat <"nospam at neversurrender dot co dot uk"> |
|---|---|
| Date | 2013-05-08 14:57 +0100 |
| Message-ID | <iqudnf7mvqsqxBfMnZ2dnUVZ7tSdnZ2d@bt.com> |
| In reply to | #23922 |
On 08/05/13 14:19, Daniele Futtorovic wrote: > On 08/05/2013 10:06, lipska the kat allegedly wrote: >> Byte[][] bytes = new Byte[width][height]; > > Lipska, mind the difference between Byte and byte. That code above is > extremely bad advice. Why? it's common practice these days to eschew primitives and use (autoboxing) classes, it's more consistent in OO code and, as I understand things, post autoboxing, the following two lines are logically equivalent. 1. Byte[][] bytes = new Byte[width][height]; 2. byte[][] bytes = new byte[width][length] The following is perfectly legal given either of the above byte b = 127; bytes[0][0] = b; Byte c = 126; bytes[0][1] = c; Byte d = bytes[0][0]; byte e = bytes[0][1]; I would of course be interested to know what your objection is. Also, I seem to remember being 'told off' for using primitives a while back ... ho hum. lipska -- Lipska the Kat©: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun
[toc] | [prev] | [next] | [standalone]
| From | Daniel Pitts <newsgroup.nospam@virtualinfinity.net> |
|---|---|
| Date | 2013-05-08 08:22 -0700 |
| Message-ID | <_4uit.18441$MS1.11557@newsfe05.iad> |
| In reply to | #23924 |
On 5/8/13 6:57 AM, lipska the kat wrote: > On 08/05/13 14:19, Daniele Futtorovic wrote: >> On 08/05/2013 10:06, lipska the kat allegedly wrote: >>> Byte[][] bytes = new Byte[width][height]; >> >> Lipska, mind the difference between Byte and byte. That code above is >> extremely bad advice. > > Why? it's common practice these days to eschew primitives and use > (autoboxing) classes Common practice where? Cite a credible source or I'll be forced to think that you are just making up facts to support your mistake. My 4 year old daughter does that; you want to be more credible than my 4 year old, don't you? > it's more consistent in OO code and, as I > understand things, post autoboxing, the following two lines are > logically equivalent. > > 1. Byte[][] bytes = new Byte[width][height]; > 2. byte[][] bytes = new byte[width][length] Even ignoring the typos, those are nothing alike. Auto-boxing is a convenience, but does not make those two things the same, even by a long shot. byte cannot contain a NULL reference. It contains no reference whatsoever. Byte on the other hand *can* contain a reference. byte[] is *not* assignable to Byte[], and Byte[] is *not* assignable to byte[]. You also cannot use arrayCopy to copy between the two. Boxing and Unboxing (whether manual or automatic) *does* have a cost. It may be minimal, and shouldn't be the only consideration. It should however be noted and considered as part of the choice. Personally my decision on whether to use Byte vs byte would hinge solely on the question "do I want to store nulls in this?" Also, I would likely wrap that primitive value in a semantic class. I still lament that Java doesn't have "value types" other than the predefined primitives, but I have learned to be "okay" with that.
[toc] | [prev] | [next] | [standalone]
| From | lipska the kat <"nospam at neversurrender dot co dot uk"> |
|---|---|
| Date | 2013-05-08 17:03 +0100 |
| Message-ID | <fYCdnaJ3OIvI6hfMnZ2dnUVZ8sudnZ2d@bt.com> |
| In reply to | #23926 |
On 08/05/13 16:22, Daniel Pitts wrote: > On 5/8/13 6:57 AM, lipska the kat wrote: >> On 08/05/13 14:19, Daniele Futtorovic wrote: >>> On 08/05/2013 10:06, lipska the kat allegedly wrote: >>>> Byte[][] bytes = new Byte[width][height]; >>> >>> Lipska, mind the difference between Byte and byte. That code above is >>> extremely bad advice. >> >> Why? it's common practice these days to eschew primitives and use >> (autoboxing) classes > Common practice where? Cite a credible source or I'll be forced to think > that you are just making up facts to support your mistake. My 4 year > old daughter does that; you want to be more credible than my 4 year old, > don't you? Think what you like, your opinion of my credibility is of no importance to me. In the context of the OPs question, why is it bad advice to suggest Byte[][] as opposed to byte[][] [snip] > Personally my decision on whether to use Byte vs byte would hinge solely > on the question "do I want to store nulls in this? > Also, I would likely wrap that primitive value in a semantic class. What primitive value? a byte? There is already a wrapper class, it's called Byte ??? lipska -- Lipska the Kat©: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun
[toc] | [prev] | [next] | [standalone]
| From | Daniel Pitts <newsgroup.nospam@virtualinfinity.net> |
|---|---|
| Date | 2013-05-08 13:44 -0700 |
| Message-ID | <%Oyit.1706$mC6.559@newsfe15.iad> |
| In reply to | #23928 |
On 5/8/13 9:03 AM, lipska the kat wrote: > On 08/05/13 16:22, Daniel Pitts wrote: >> On 5/8/13 6:57 AM, lipska the kat wrote: >>> On 08/05/13 14:19, Daniele Futtorovic wrote: >>>> On 08/05/2013 10:06, lipska the kat allegedly wrote: >>>>> Byte[][] bytes = new Byte[width][height]; >>>> >>>> Lipska, mind the difference between Byte and byte. That code above is >>>> extremely bad advice. >>> >>> Why? it's common practice these days to eschew primitives and use >>> (autoboxing) classes >> Common practice where? Cite a credible source or I'll be forced to think >> that you are just making up facts to support your mistake. My 4 year >> old daughter does that; you want to be more credible than my 4 year old, >> don't you? > > Think what you like, your opinion of my credibility is of no importance > to me. > > In the context of the OPs question, why is it bad advice to suggest > Byte[][] as opposed to byte[][] > > [snip] Given in the part you snipped. Try again. > >> Personally my decision on whether to use Byte vs byte would hinge solely >> on the question "do I want to store nulls in this? >> Also, I would likely wrap that primitive value in a semantic class. > > What primitive value? a byte? > There is already a wrapper class, it's called Byte ??? The "Byte" class is a primitive wrapper. I would wrap it with a semantic class which determines what that byte represents. Although, I wouldn't be likely to write that for a byte, but other primitives I would.
[toc] | [prev] | [next] | [standalone]
| From | lipska the kat <"nospam at neversurrender dot co dot uk"> |
|---|---|
| Date | 2013-05-08 17:48 +0100 |
| Message-ID | <I7CdnWDuaKNwHBfMnZ2dnUVZ8tCdnZ2d@bt.com> |
| In reply to | #23926 |
On 08/05/13 16:22, Daniel Pitts wrote: > On 5/8/13 6:57 AM, lipska the kat wrote: >> On 08/05/13 14:19, Daniele Futtorovic wrote: >>> On 08/05/2013 10:06, lipska the kat allegedly wrote: >>>> Byte[][] bytes = new Byte[width][height]; >>> >>> Lipska, mind the difference between Byte and byte. That code above is >>> extremely bad advice. >> >> Why? it's common practice these days to eschew primitives and use >> (autoboxing) classes > Common practice where? Cite a credible source or I'll be forced to think > that you are just making up facts to support your mistake. My 4 year > old daughter does that; you want to be more credible than my 4 year old, > don't you? Hmm http://docs.oracle.com/javase/1.5.0/docs/guide/language/autoboxing.html <cite> So when should you use autoboxing and unboxing? Use them only when there is an “impedance mismatch” between reference types and primitives, for example, when you have to put numerical values into a collection. It is not appropriate to use autoboxing and unboxing for scientific computing, or other performance-sensitive numerical code. An Integer is not a substitute for an int; autoboxing and unboxing blur the distinction between primitive types and reference types, but they do not eliminate it. </cite> So, I'll agree that my assertion of logical equivalence is bollocks However I'm still not convinced that mixing primitives and reference types is a 'good idea' in OO code. But given the above I'll concede that suggesting Byte[][] was possibly poor advice, byte[][] might be better. [snip] -- Lipska the Kat©: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2013-05-08 21:10 -0400 |
| Message-ID | <518af786$0$32105$14726298@news.sunsite.dk> |
| In reply to | #23936 |
On 5/8/2013 12:48 PM, lipska the kat wrote: > On 08/05/13 16:22, Daniel Pitts wrote: >> On 5/8/13 6:57 AM, lipska the kat wrote: >>> On 08/05/13 14:19, Daniele Futtorovic wrote: >>>> On 08/05/2013 10:06, lipska the kat allegedly wrote: >>>>> Byte[][] bytes = new Byte[width][height]; >>>> >>>> Lipska, mind the difference between Byte and byte. That code above is >>>> extremely bad advice. >>> >>> Why? it's common practice these days to eschew primitives and use >>> (autoboxing) classes >> Common practice where? Cite a credible source or I'll be forced to think >> that you are just making up facts to support your mistake. My 4 year >> old daughter does that; you want to be more credible than my 4 year old, >> don't you? > > Hmm > > http://docs.oracle.com/javase/1.5.0/docs/guide/language/autoboxing.html > > <cite> > So when should you use autoboxing and unboxing? Use them only when there > is an “impedance mismatch” between reference types and primitives, for > example, when you have to put numerical values into a collection. It is > not appropriate to use autoboxing and unboxing for scientific computing, > or other performance-sensitive numerical code. An Integer is not a > substitute for an int; autoboxing and unboxing blur the distinction > between primitive types and reference types, but they do not eliminate it. > </cite> > > So, I'll agree that my assertion of logical equivalence is bollocks Good. > However I'm still not convinced that mixing primitives and reference > types is a 'good idea' in OO code. I would expect almost any Java program to use both ref types and value types. And the equivalent in C#. Lots of generic collection code and ORM code even mixes primitives with their ref type wrappers, because that is necessary in the context (Java implementation of generics and databases NULL values). Arne
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2013-05-08 12:52 -0400 |
| Message-ID | <kmdvmk$9ib$1@dont-email.me> |
| In reply to | #23926 |
On 5/8/2013 11:22 AM, Daniel Pitts wrote:
> On 5/8/13 6:57 AM, lipska the kat wrote:
>> On 08/05/13 14:19, Daniele Futtorovic wrote:
>>> On 08/05/2013 10:06, lipska the kat allegedly wrote:
>>>> Byte[][] bytes = new Byte[width][height];
>>>
>>> Lipska, mind the difference between Byte and byte. That code above is
>>> extremely bad advice.
>>
>> Why? it's common practice these days to eschew primitives and use
>> (autoboxing) classes
> Common practice where? Cite a credible source or I'll be forced to think
> that you are just making up facts to support your mistake. My 4 year
> old daughter does that; you want to be more credible than my 4 year old,
> don't you?
>
>> it's more consistent in OO code and, as I
>> understand things, post autoboxing, the following two lines are
>> logically equivalent.
>>
>> 1. Byte[][] bytes = new Byte[width][height];
>> 2. byte[][] bytes = new byte[width][length]
>
> Even ignoring the typos, those are nothing alike.
>
> Auto-boxing is a convenience, but does not make those two things the
> same, even by a long shot.
For example, consider what happens when `int x = bytes[0][0];'
immediately follows either of the above. In case 2, it sets x
to zero. In case 1, the JVM throws NullPointerException. That's
not "logically equivalent" in my book!
>[...]
> Personally my decision on whether to use Byte vs byte would hinge solely
> on the question "do I want to store nulls in this?"
Or on "Do I want to put it in a Collection?"
There's also the matter of the memory footprint, even if
"efficiency" is a dirty word in some circles. Version 1 will
use four times (32-bit JVM) or eight times (64-bit) as much
memory as version 2. Image sizes vary, but even a fairly modest
640x480 has 300K pixels -- so using Byte[][] instead of byte[][]
would cost an extra 0.9MB or 2.1MB. Even if I had the desire to
store nulls, a bloat of such proportions would probably prompt
me to use byte[][] and seek another way to represent whatever
I wanted the nulls to stand for.
--
Eric Sosman
esosman@comcast-dot-net.invalid
[toc] | [prev] | [next] | [standalone]
| From | Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> |
|---|---|
| Date | 2013-05-08 17:32 +0200 |
| Message-ID | <kmdquo$dj7$1@dont-email.me> |
| In reply to | #23924 |
On 08/05/2013 15:57, lipska the kat allegedly wrote: > On 08/05/13 14:19, Daniele Futtorovic wrote: >> On 08/05/2013 10:06, lipska the kat allegedly wrote: >>> Byte[][] bytes = new Byte[width][height]; >> >> Lipska, mind the difference between Byte and byte. That code above is >> extremely bad advice. > > Why? it's common practice these days to eschew primitives and use > (autoboxing) classes, it's more consistent in OO code and, as I > understand things, post autoboxing, the following two lines are > logically equivalent. > > 1. Byte[][] bytes = new Byte[width][height]; > 2. byte[][] bytes = new byte[width][length] > > The following is perfectly legal given either of the above > > byte b = 127; > bytes[0][0] = b; > Byte c = 126; > bytes[0][1] = c; > Byte d = bytes[0][0]; > byte e = bytes[0][1]; > > I would of course be interested to know what your objection is. Simple: "byte[]" is not a primitive type. "byte" is a primitive type. "byte[]" is a reference type. Along the same lines, you'll be hard pressed to find a Java I/O library that uses Byte[]'s rather than byte[]'s. > Also, I seem to remember being 'told off' for using primitives a while > back ... ho hum. I don't know about that. -- DF.
[toc] | [prev] | [next] | [standalone]
| From | lipska the kat <"nospam at neversurrender dot co dot uk"> |
|---|---|
| Date | 2013-05-08 17:17 +0100 |
| Message-ID | <y4KdnaD92O8L5xfMnZ2dnUVZ8qmdnZ2d@bt.com> |
| In reply to | #23927 |
On 08/05/13 16:32, Daniele Futtorovic wrote: > On 08/05/2013 15:57, lipska the kat allegedly wrote: >> On 08/05/13 14:19, Daniele Futtorovic wrote: >>> On 08/05/2013 10:06, lipska the kat allegedly wrote: >>>> Byte[][] bytes = new Byte[width][height]; >>> >>> Lipska, mind the difference between Byte and byte. That code above is >>> extremely bad advice. >> >> Why? it's common practice these days to eschew primitives and use >> (autoboxing) classes, it's more consistent in OO code and, as I >> understand things, post autoboxing, the following two lines are >> logically equivalent. >> >> 1. Byte[][] bytes = new Byte[width][height]; >> 2. byte[][] bytes = new byte[width][length] typo notwithstanding oops :-( >> The following is perfectly legal given either of the above >> >> byte b = 127; >> bytes[0][0] = b; >> Byte c = 126; >> bytes[0][1] = c; >> Byte d = bytes[0][0]; >> byte e = bytes[0][1]; >> >> I would of course be interested to know what your objection is. > > Simple: "byte[]" is not a primitive type. I wasn't aware that I said it was > "byte" is a primitive type. > "byte[]" is a reference type. no argument there but what is your *objection* to Byte[][] bytes = new Byte[width][height]; in the context of the OPs question? lipska -- Lipska the Kat©: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun
[toc] | [prev] | [next] | [standalone]
| From | Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> |
|---|---|
| Date | 2013-05-08 18:46 +0200 |
| Message-ID | <kmdvai$765$1@dont-email.me> |
| In reply to | #23930 |
On 08/05/2013 18:17, lipska the kat allegedly wrote: > On 08/05/13 16:32, Daniele Futtorovic wrote: >> On 08/05/2013 15:57, lipska the kat allegedly wrote: >>> On 08/05/13 14:19, Daniele Futtorovic wrote: >>>> On 08/05/2013 10:06, lipska the kat allegedly wrote: >>>>> Byte[][] bytes = new Byte[width][height]; >>>> >>>> Lipska, mind the difference between Byte and byte. That code above is >>>> extremely bad advice. >>> >>> Why? it's common practice these days to eschew primitives and use >>> (autoboxing) classes, it's more consistent in OO code and, as I >>> understand things, post autoboxing, the following two lines are >>> logically equivalent. >>> >>> 1. Byte[][] bytes = new Byte[width][height]; >>> 2. byte[][] bytes = new byte[width][length] > > typo notwithstanding oops :-( > >>> The following is perfectly legal given either of the above >>> >>> byte b = 127; >>> bytes[0][0] = b; >>> Byte c = 126; >>> bytes[0][1] = c; >>> Byte d = bytes[0][0]; >>> byte e = bytes[0][1]; >>> >>> I would of course be interested to know what your objection is. >> >> Simple: "byte[]" is not a primitive type. > > I wasn't aware that I said it was When I called out your using a Byte[] rather than byte[] in your example code, you defended it on the grounds of an alleged "common practice" to use (boxed) reference types instead of primitive types. Thereby, you have implied that byte[] was a primitive type; otherwise your whole argument would have been a non sequitur. But byte[] is not a primitive type, and hence your argument, irrespectively of its merits (see below), does not apply. >> "byte" is a primitive type. >> "byte[]" is a reference type. > > no argument there but what is your *objection* to > > Byte[][] bytes = new Byte[width][height]; > > in the context of the OPs question? Objection? It's bullcrap. Firstly, no I/O library uses Byte[]. Secondly, as Daniel has indicated, the only reason to use Byte[] over byte[] would be to store null references. Which the OP doesn't need, as they have actual data. And lastly, it's dangerous because it furthers the very thing that, I reckon, lead you to use it in the first place: the confusion induced by autoboxing. General OO matters set aside, in the context of Java, autoboxing is a poison. The meagre convenience it provides is largely offset by the confusion, or lack of clarity, it causes in the minds of Java programmers, especially aspirant Java programmers. I've witnessed its nefarious effects countless times in my colleagues' code. A for/each loop is exactly the same thing as a normal for loop with an iterator. But, for better or for worse, in Java, a boxed reference type and a primitive type are two completely different things. Autoboxing induces the thought that they're not. That's why it's poison. -- DF.
[toc] | [prev] | [next] | [standalone]
| From | lipska the kat <"nospam at neversurrender dot co dot uk"> |
|---|---|
| Date | 2013-05-08 18:25 +0100 |
| Message-ID | <gNSdnYxsa-QCFxfMnZ2dnUVZ8l2dnZ2d@bt.com> |
| In reply to | #23935 |
On 08/05/13 17:46, Daniele Futtorovic wrote: > On 08/05/2013 18:17, lipska the kat allegedly wrote: >> On 08/05/13 16:32, Daniele Futtorovic wrote: >>> On 08/05/2013 15:57, lipska the kat allegedly wrote: >>>> On 08/05/13 14:19, Daniele Futtorovic wrote: >>>>> On 08/05/2013 10:06, lipska the kat allegedly wrote: >>>>>> Byte[][] bytes = new Byte[width][height]; >>>>> >>>>> Lipska, mind the difference between Byte and byte. That code above is >>>>> extremely bad advice. >>>> >>>> Why? it's common practice these days to eschew primitives and use >>>> (autoboxing) classes, it's more consistent in OO code and, as I >>>> understand things, post autoboxing, the following two lines are >>>> logically equivalent. >>>> >>>> 1. Byte[][] bytes = new Byte[width][height]; >>>> 2. byte[][] bytes = new byte[width][length] >> >> typo notwithstanding oops :-( >> >>>> The following is perfectly legal given either of the above >>>> >>>> byte b = 127; >>>> bytes[0][0] = b; >>>> Byte c = 126; >>>> bytes[0][1] = c; >>>> Byte d = bytes[0][0]; >>>> byte e = bytes[0][1]; >>>> >>>> I would of course be interested to know what your objection is. >>> >>> Simple: "byte[]" is not a primitive type. >> >> I wasn't aware that I said it was > > When I called out your using a Byte[] rather than byte[] in your example > code, you defended it on the grounds of an alleged "common practice" to > use (boxed) reference types instead of primitive types. Thereby, you > have implied that byte[] was a primitive type; There was no such implication, you are mistaken. I have admitted elsewhere that it was 'less than optimal' to suggest Byte[][]. I did it for purely 'OO' reasons. Interesting reactions though. lipska -- Lipska the Kat©: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun
[toc] | [prev] | [next] | [standalone]
| From | Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> |
|---|---|
| Date | 2013-05-08 23:24 +0200 |
| Message-ID | <kmefjn$bfq$1@dont-email.me> |
| In reply to | #23939 |
On 08/05/2013 19:25, lipska the kat allegedly wrote: > On 08/05/13 17:46, Daniele Futtorovic wrote: >> On 08/05/2013 18:17, lipska the kat allegedly wrote: >>> On 08/05/13 16:32, Daniele Futtorovic wrote: >>>> On 08/05/2013 15:57, lipska the kat allegedly wrote: >>>>> On 08/05/13 14:19, Daniele Futtorovic wrote: >>>>>> On 08/05/2013 10:06, lipska the kat allegedly wrote: >>>>>>> Byte[][] bytes = new Byte[width][height]; >>>>>> >>>>>> Lipska, mind the difference between Byte and byte. That code above is >>>>>> extremely bad advice. >>>>> >>>>> Why? it's common practice these days to eschew primitives and use >>>>> (autoboxing) classes, it's more consistent in OO code and, as I >>>>> understand things, post autoboxing, the following two lines are >>>>> logically equivalent. >>>>> >>>>> 1. Byte[][] bytes = new Byte[width][height]; >>>>> 2. byte[][] bytes = new byte[width][length] >>> >>> typo notwithstanding oops :-( >>> >>>>> The following is perfectly legal given either of the above >>>>> >>>>> byte b = 127; >>>>> bytes[0][0] = b; >>>>> Byte c = 126; >>>>> bytes[0][1] = c; >>>>> Byte d = bytes[0][0]; >>>>> byte e = bytes[0][1]; >>>>> >>>>> I would of course be interested to know what your objection is. >>>> >>>> Simple: "byte[]" is not a primitive type. >>> >>> I wasn't aware that I said it was >> >> When I called out your using a Byte[] rather than byte[] in your example >> code, you defended it on the grounds of an alleged "common practice" to >> use (boxed) reference types instead of primitive types. Thereby, you >> have implied that byte[] was a primitive type; > > There was no such implication, you are mistaken. Okay, whatever. -- DF.
[toc] | [prev] | [next] | [standalone]
| From | Joshua Cranmer 🐧 <Pidgeot18@verizon.invalid> |
|---|---|
| Date | 2013-05-08 11:46 -0500 |
| Message-ID | <kmdv9r$57n$1@dont-email.me> |
| In reply to | #23924 |
On 5/8/2013 8:57 AM, lipska the kat wrote: > Why? it's common practice these days to eschew primitives and use > (autoboxing) classes, it's more consistent in OO code and, as I > understand things, post autoboxing, the following two lines are > logically equivalent. > > 1. Byte[][] bytes = new Byte[width][height]; This creates an array with every entry prefilled to NULL. > 2. byte[][] bytes = new byte[width][length] This creates an array with every entry prefilled to 0. Ergo, not logically equivalent, even if I assume that your height/length was a typo. -- Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2013-05-08 21:04 -0400 |
| Message-ID | <518af634$0$32105$14726298@news.sunsite.dk> |
| In reply to | #23924 |
On 5/8/2013 9:57 AM, lipska the kat wrote: > On 08/05/13 14:19, Daniele Futtorovic wrote: >> On 08/05/2013 10:06, lipska the kat allegedly wrote: >>> Byte[][] bytes = new Byte[width][height]; >> >> Lipska, mind the difference between Byte and byte. That code above is >> extremely bad advice. > > Why? it's common practice these days to eschew primitives and use > (autoboxing) classes, No - it is not. And especially not when it comes to arrays. > it's more consistent in OO code and, as I > understand things, post autoboxing, the following two lines are > logically equivalent. > > 1. Byte[][] bytes = new Byte[width][height]; > 2. byte[][] bytes = new byte[width][length] Not at all. You will eventually end up with 1+width*height and 1 objects respectively. > The following is perfectly legal given either of the above > > byte b = 127; > bytes[0][0] = b; > Byte c = 126; > bytes[0][1] = c; > Byte d = bytes[0][0]; > byte e = bytes[0][1]; Yes. But the fact that you can make those assignments does not make the two declarations equivalent. > I would of course be interested to know what your objection is. Typically you want value semantics for a case like this. And all those objects will come with significant overhead (which may be important in some contexts). > Also, I seem to remember being 'told off' for using primitives a while > back ... ho hum. If someone said that for a case like this, then you have been listening to the wrong person. Arne
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2013-05-08 21:45 -0400 |
| Message-ID | <kmeusn$kb9$1@dont-email.me> |
| In reply to | #23951 |
On 5/8/2013 9:04 PM, Arne Vajhøj wrote:
> On 5/8/2013 9:57 AM, lipska the kat wrote:
>> [...] the following two lines are
>> logically equivalent.
>>
>> 1. Byte[][] bytes = new Byte[width][height];
>> 2. byte[][] bytes = new byte[width][length]
>
> Not at all.
>
> You will eventually end up with 1+width*height and 1 objects respectively.
No; both will generate 1+width objects:
- One array containing `width' references to other arrays,
- `width' arrays containing `height' bytes or Byte
references.
A *really* stupid coder might use Byte[][] *and* populate
the arrays with `new Byte(value)' repeated `width*height' times;
that would produce `1 + width + width*height' objects in all.
Autoboxers would be unlikely to enter that particular trap --
but even so, a four- to eight-fold memory bloat is not to be
sneezed at.
--
Eric Sosman
esosman@comcast-dot-net.invalid
[toc] | [prev] | [next] | [standalone]
Page 1 of 3 [1] 2 3 Next page →
Back to top | Article view | comp.lang.java.programmer
csiph-web