UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2013-12-04 09:00 PM

RipRage
Member
From: England
Registered: 2010-01-06
Posts: 146

Possible fault with textbook

Hey Guys,

Apologises for another random thread, just wanted to ask you both for your opinion on something, the textbook supplied for our module: Object-orientated Java program (written by lectures from the university) seems to have a fault, I wanted your opinions before I challenge it.

There's no easy way I can show you the exact pages unless I scan them or hunt around for a PDF version but ill do my best to express my point.

Page 92 simple states that the following integer types are

byte 8 bits, short 16 bits, int 32 bits, long 64 bits, float 32 bits, and finally double 64 bits. So far so good, however, through out the text they constantly refer a double as being 32 bits and an int as 16 bits, quote "a double occupies 32 bits while an int occupies 16 bits"

Ive seen this on many occasions now and its wrong! a short int is 16 bits and a float is 32 bits, a double is 64 bits!!!! Yeah I know that a standard int can be either 32 bits or 16 bits depending on machine architecture(not sure if this is the case with java and the JVM), however, it still should be stated, they clearly explain that references (similar to if not the same as pointers) are 32 bits or 64 bits depending on machine architecture....

What are your views on this ?

Many thanks!

Last edited by RipRage (2013-12-04 10:00 PM)

Offline

#2 2013-12-05 09:42 AM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,231

Re: Possible fault with textbook

Java types are machine independent, and even if it's C they can't say stuff like that,
exactly because it's machine dependent. So tell them they made some mistakes and
ask them to fix it. Or ask them to explain the text, which gives them a chance to
"discover" the mistakes themselves and also makes it clear why they should fix it.

To me such a mistake is a sign that no one really cares about the textbook and that its
quality is questionable. The only good excuse would be that it's very old and adapted
to Java, 32-bit and 64-bit later, but they forgot to update all sentences.

Offline

#3 2013-12-05 01:23 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,829
Website

Re: Possible fault with textbook

and even if it's C they can't say stuff like that, exactly because it's machine dependent

Well, despite the ISO/ANSI not wanting to get specific, in practice at least "char" is effectively always 8 bits on any modern system I'm aware of, and I suspect lots of code would break horribly if that didn't hold true...  I believe POSIX or SUS or someone like that requires it be true...  (Though, one thing that does vary is whether it's signed or unsigned by default!)  And, usually "float" and "double" are going to be the standard IEEE single (32-bit) and double (64-bit) precision floating point, but I suppose there are still weird machines out there that don't support that...  However "long double" does vary between various modern systems...  And, of course, the basic int types just give minimum sizes they must at least be, and their relative sizes with respect to each other, so you can't really count on much there...  (Though, I've never heard of a system where "short" wasn't 16-bit...  "int" changes, "long" changes, but "short" never changes that I've seen...  And, while I can imagine "long long" one day becoming 128-bit, I've yet to see it happen so far...)

I'm so thankful for C99's introduction of the fixed-sized int types, which make life a whole lot easier in many situations where you really need to keep sizes exact and interoperable between different systems...

Offline

#4 2013-12-05 01:50 PM

RipRage
Member
From: England
Registered: 2010-01-06
Posts: 146

Re: Possible fault with textbook

Robseace wrote:

at least "char" is effectively always 8 bits on any modern system I'm aware of

Interestingly the textbook states that in java a char is 16 bits, UNICODE (presuming it defaults to wchar_t) no mention of ASCII/ANCI....

Offline

#5 2013-12-05 10:07 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,829
Website

Re: Possible fault with textbook

Interestingly the textbook states that in java a char is 16 bits, UNICODE (presuming it defaults to wchar_t) no mention of ASCII/ANCI....

Yeah, the Java equivalent of C's "char" is "byte"...  They foolishly went with UTF-16/UCS-2 for the native character/string type...  When everyone these days is now going UTF-8, which has a ton of benefits, most importantly complete 7-bit ASCII backwards compatability with no increase in storage space...  Plus, it has the flexability to be extended to handle codepoints above U+FFFF (or U+10FFFF for UTF-16), while they're screwed when it comes to supporting those higher Unicode characters ever...

Offline

Board footer

Powered by FluxBB