*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Integral types -- MG Exam 3 Q 25 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Integral types -- MG Exam 3 Q 25" Watch "Integral types -- MG Exam 3 Q 25" New topic
Author

Integral types -- MG Exam 3 Q 25

shree vijay
Ranch Hand

Joined: Sep 18, 2000
Posts: 208
Question 25)
Which of the following statements are true?
1) The following statement will produce a result of 1. System.out.println( -1 >>>2);
2) Performing an unsigned left shift (<<<) on a negative number will always produce a negative number result <br /> 3) The following statement will produce a result of zero, System.out.println(1 >>1); <br /> 4) All the integer primitives in java are signed numbers <br /> <br /> Answer to Question 25) <br /> Objective 5.1)<br /> 3) The following statement will produce a result of zero, System.out.println(1 >>1);
Although you might not know the exact result of the operation -1 >>> 2 a knowledge of the way the bits will be shifted will tell you that the result is not plus 1. (The result is more like 1073741823 ) There is no such Java operator as the unsigned left shift. Although it is normally used for storing characters rather than numbers the char Java primitive is actually an unsigned integer type.

now , should i include char in integral types? I remember studying that numeric types are divided into integral types and char -- integral are(byte,short,int,long)

------------------
Regards,
Shree


Regards,<BR>Shree
James Baud
Ranch Hand

Joined: Jan 06, 2001
Posts: 60
shree vijay,
I think what was meant here is that the bit-representation of char is that of an unsigned integer whose range falls between 0x0 to 0xffff, or 0 to 2**16. The key here is the whole 16 bits. For signed integers (byte, short, int, char) the bit spectrum for the integer value has to give up one bit to denote the sign. Primitive type short, for example, can only have a postive max value of 2**15 - 1.
Hope this helped.
------------------
~James Baud
Talk, does not cook rice. - Chinese Proverb


<B>~James Baud</B><P>He who asks, is a fool for five minutes;<BR>but, he who does not ask, remains a fool forever. (Chinese proverb)
Rajpal Kandhari
Ranch Hand

Joined: Aug 26, 2000
Posts: 126
Hello James,
Just to add one point.

The char type is integral but unsigned.
All the numerical primitive types(thatis, all except boolean and char) are signed.
James,
The range of a variable of type char is from 0 to 2power16-1.
Regards
Raj.

Regards,<P>Raj.<BR>-------------------------<BR>Afforts should be Appriciated.<BR>-------------------------
James Baud
Ranch Hand

Joined: Jan 06, 2001
Posts: 60
Rajpal Kandhari:

The char type is integral but unsigned.

Yes, the type is integral, but at the bit-level you can think of char as an unsigned integer with a width of 16 bits.

The range of a variable of type char is from 0 to 2power16-1.

The char datatype encompasses all the 65536(2power16) characters of the Unicode character set as 16-bit values. - Khalid A. Mughal, A Programmer's Guide to Java Certification Sec 2.5, p. 31
------------------
~James Baud
Talk, does not cook rice. - Chinese Proverb
Rajpal Kandhari
Ranch Hand

Joined: Aug 26, 2000
Posts: 126
Hello James,
RHE book says on page-9 "The range of a variable of type char is from 0 through 2(power)16-1."
Now which author is correct.
What do experts have to say about this.
------------------
Regards,
Raj.
-------------------------
Afforts should be Appriciated.
-------------------------
James Baud
Ranch Hand

Joined: Jan 06, 2001
Posts: 60
Hi Raj,
Both authors are correct. If we analyze the wordings carefully, all 65536(2power16)[KAM] actually means that, w/ zero offset, the min_value = 0 and max_value = 65535(2power16-1)[RHE].
0xffff equals 65535(2power16-1) not 2**16 as I previously announced. My apologies.
------------------
~James Baud
Talk, does not cook rice. - Chinese Proverb
 
wood burning stoves
 
subject: Integral types -- MG Exam 3 Q 25
 
Similar Threads
Q from examulator.com
Marcus Green - What is Java Integral Type
Doubt in Marcus mock exam 3
From marcus green
true/false