About Question com.enthuware.ets.scjp.v6.2.401 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
kannattaa
Posts: 4
Joined: Thu Jul 03, 2014 5:11 am
Contact:

About Question com.enthuware.ets.scjp.v6.2.401 :

Post by kannattaa »

The following code snippet will print 'true'.

Code: Select all

        float f = Integer.MIN_VALUE;
        int i = (int) f;
        System.out.println( i == Integer.MIN_VALUE);
seems to be a better question.

The fact of the matter is that Integer.MIN_VALUE = (-1) * 2 ^ 31.
So it can be converted to binary, normalized and loss-free represented in IEEE-754 binary32 format as 11001111000000000000000000000000

The problem of Integer.MAX_VALUE is that it requires not obvious loosly convertion and normalization to (1)*2^31 = (Integer.MAX_VALUE + 1) and vice versa.

Is the original question(with Integer.MAX_VALUE) really captured from exam and focused on the details of loosly conversion?
(f.e. the trick won't come out with Integer.MAX_VALUE / 2)

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.401 :

Post by admin »

Well, the objective of the question is to sensitize the reader about the implications of using a float. You may not get the exact question on the exam but you may get question that depends on you knowing that float doesn't store precise integers.

HTH,
Paul.

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests