About Question enthuware.ocajp.i.v7.2.1159 :

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

Moderator: admin

Post Reply
ETS User

About Question enthuware.ocajp.i.v7.2.1159 :

Post by ETS User »

How is the test taker to know that a = Integer.MIN_VALUE = 10000000 00000000 00000000 00000000
:shock: :(

dtchky
Posts: 19
Joined: Wed Aug 01, 2012 3:11 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1159 :

Post by dtchky »

The test taker hopefully doesn't know that good sir or ma'am : )

Detailed info on primitive data types (and their associated wrapper classes) is available quite readily on the net and via any intro to Java book. It's definitely advisable to know the min / max values because you'll almost always need to consider variable types at this level in just about every Java application you write.

MIN_INTEGER would be -2147483648

Guest

Re: About Question enthuware.ocajp.i.v7.2.1159 :

Post by Guest »

Thank-you for the kind and informative response. I am not used to seeing the values in binary though. I have a basic idea of the MIN and MAX values for the primitive types but not their binary representations. Although, it may be that the MIN values are just 1 followed by zeros, number of zeros determined by number of bits of primitive type, since 1 means negative in binary.

dtchky
Posts: 19
Joined: Wed Aug 01, 2012 3:11 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1159 :

Post by dtchky »

You're welcome : ) This is in reference to question enthuware.ocajp.i.v7.2.1159?

Within the OCAJP exam I never had any questions about binary representation, I suspect you don't really need to know Java at that level for the OCAJP fortunately. The exam does cover primitive ranges but it uses base 10 values - mostly the questions are about type casting or widening conversions.

This particular question is asking not so much what the values are for Integer.MIN_VALUE, but rather what the sign would be.

Within the OCAJP probably the most complex question you might come across of this nature would be similar to this actual Enthuware question, or something like:

Consider the following:

Code: Select all

public class Test {
        public static void main(String[] args) {
                Integer x = 0;
                System.out.println(x.MIN_VALUE);
                System.out.println(x.MAX_VALUE);
        }
}
What would be the output when running this code?

(Multiple choice answers)

In this case the output will be:
-2147483648
2147483647

Having said all this, if you wanted to see the binary values you could add the following code to the program above:

Code: Select all

                System.out.println(Integer.toBinaryString(x.MIN_VALUE));
                System.out.println(Integer.toBinaryString(x.MAX_VALUE));
Output:
10000000000000000000000000000000
1111111111111111111111111111111

Guest

Re: About Question enthuware.ocajp.i.v7.2.1159 :

Post by Guest »

yes, still asking a question about enthuware.ocajp.i.v7.2.1159. Thank-you for your reply. I hope I won't have to do any twos complement on the exam! That is time intensive.

It has been interesting to learn about though. Thank-you for your help.

:geek:

dtchky
Posts: 19
Joined: Wed Aug 01, 2012 3:11 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1159 :

Post by dtchky »

I can say there will definitely not be any two's compliment on the OCAJP exam : ) The Enthuware application I found to be quite a bit more difficult than the actual Oracle certification so if you're scoring highly in Enthuware you'll easily pass the OCAJP test.

Good luck.

Javanaut

Re: About Question enthuware.ocajp.i.v7.2.1159 :

Post by Javanaut »

I am almost passing the first time through... I keep getting low 60s :/ My friend said to wait until I can make 80s on practice tests. I am not sure where I will find more practice tests though! :/

Plus Oracle recently raised the passing score for the OCAJP to 77% but gives 10 more minutes.

dtchky
Posts: 19
Joined: Wed Aug 01, 2012 3:11 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1159 :

Post by dtchky »

You don't really need to find more practice tests, Enthuware mixes things up a bit even if you take the same test multiple times. I had access to a few intro to java books along with some more advanced reference guides, the approach I used (aside from reading all the books cover to cover a couple of times each) was to study only the questions I got wrong in Enthuware - by study I don't mean memorize the correct answer, I hit the books again to understand the underlying concepts and language constructs. I found my scores jumped very quickly after this. I made sure I passed every Enthuware test 3 times in a row before I sat the OCAJP.

75%, 77%, this is just a couple of questions, aim for 100% and you don't need to worry about 'just passing' : )

javanaut

Re: About Question enthuware.ocajp.i.v7.2.1159 :

Post by javanaut »

Hi dtchky,

Thank-you for the advice. I have read Head-First Java one and a half times, and SCJP once. I use SCJP as a reference though for questions I miss to understand concepts I haven't grasped like you described. Plus, I read another Java book that focused on OCA preperation.

I wish I was as fast a learner as you. When I take the test again, I receive the same questions, and I score like 96 or something. lol ...but I still get 60s when taking the tests the first time! :/

Thanx for the feedback. I appreciate it.

Respectfully,

javanaut

The_Nick

Re: About Question enthuware.ocajp.i.v7.2.1159 :

Post by The_Nick »

Hi everybody,
Is it a peculiar thing related to the minimum value of a variable? Or this kind of tricks that -a still remains negative even though one would expect to convert it into positive?

For example:
int i = -45;
System.out.println(-i);// it gives out 45 not -45;


Could somebody make the 2's complement example for

Code: Select all

int i =-45, System.out.println(-i);

in comparison to the Integer.MIN_VALUE thing?

Thanks in advance.

The_Nick.

The_Nick

Re: About Question enthuware.ocajp.i.v7.2.1159 :

Post by The_Nick »

I would like to add this post from stackoverflow.com
It helps to clarify the point of this question in my view.
http://stackoverflow.com/questions/1253 ... en-compare

DesRenthuware
Posts: 32
Joined: Wed Aug 28, 2013 6:12 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1159 :

Post by DesRenthuware »

Very interesting question - assumed that the answer would be an overflow (so got it wrong/right?). Remembered the min and max vals would be one out, but expected mathematical rules to take precedence (i.e. -(-x) = +x) and so would overflow.

javanaut
Posts: 22
Joined: Wed Aug 21, 2013 12:29 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1159 :

Post by javanaut »

Please let me know if I am wrong, but I think the explanation for this question is a little misleading when describing two's complement.

The second step is to add 1 but it shows adding 32 1's to the complemented number, which is not correct if I am not mistaken. In other words it is like the explanation is saying to add the MAX_VALUE in binary of the number to the complemented (everything switched to the opposite) binary value. :shock:

Regards,

Javanaut

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

Re: About Question enthuware.ocajp.i.v7.2.1159 :

Post by admin »

I don't see it adding 32 1's. It shows the number that you get after adding 1 to step 1.
Step 1 (complement the bits of 1): ///11111111 11111111 11111111 11111110///
Step 2 (add 1 to step 1): ///11111111 11111111 11111111 11111111///.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.

javanaut
Posts: 22
Joined: Wed Aug 21, 2013 12:29 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1159 :

Post by javanaut »

Oh yeah, I just added it on paper in binary and adding one to the complemented bits in step one does produce 32 1's. I see what the explanation is saying now.

Thanks Paul. :D

Regards,

Javanaut

javanaut
Posts: 22
Joined: Wed Aug 21, 2013 12:29 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1159 :

Post by javanaut »

Code: Select all

// java program by javanaut :D

public class Foo {

        static public void main(String[] args) {

                Integer x = 0b11111111_11111111_11111111_11111111;
                System.out.println(x);

                Integer x1 = Integer.MAX_VALUE;
                System.out.println(x1);

                System.out.println(Integer.toBinaryString(x));
                System.out.println(Integer.toBinaryString(x1));

        }



}
 

This is the output on my machine:

Code: Select all

-1
2147483647
11111111111111111111111111111111
1111111111111111111111111111111
Hey all,

I made this program to try and experiment with some of this - binary numbers, two's complement, etc. I noticed that the first toBinaryString() method in my program prints out one more 1 that the second call to this method. Can someone please explain?

The arguments to the toBinaryString() method are -1 in x and MAX_VALUE found in x1.

Regards,

Javanaut

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

Re: About Question enthuware.ocajp.i.v7.2.1159 :

Post by admin »

That is because there is one more 1 in the binary representation of -1 than in MAX_VALUE. Please read how -1 is represented in a 32 bit int.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

javanaut
Posts: 22
Joined: Wed Aug 21, 2013 12:29 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1159 :

Post by javanaut »

Paul,

Thank-you for the reply. How odd that MAX_VALUE has only 31 bits when it is an int that is a 32 bit data-type. :o

This part of Java is not really on the OCAJP7 exam though?

Thank-you again for helping me understand what I was missing with the output of my program.

Regards,

Javanaut

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

Re: About Question enthuware.ocajp.i.v7.2.1159 :

Post by admin »

I didn't say MAX_VALUE has only 31 bits. I said it has 31 1s. The MSB is 0 and is probably not printed because of the way toBinaryString method is coded.

No, this is not required for the exam.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.

javanaut
Posts: 22
Joined: Wed Aug 21, 2013 12:29 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1159 :

Post by javanaut »

Intense.

I had to look up MSB https://en.wikipedia.org/wiki/Most_significant_bit

I can see guess the MSB is dropped since it is a zero or something sort of like how octals are printed by Java if I am not mistaken.

Yes, I am glad this is not on the exam. :mrgreen:

thupten
Posts: 4
Joined: Thu Jan 09, 2014 3:21 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1159 :

Post by thupten »

Has this question ever appeared on the test?
I think most would choose the Overflow exception as the answer. This is totally unexpected behavior. There probably are many programs out there with bug related to this. :(

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

Re: About Question enthuware.ocajp.i.v7.2.1159 :

Post by admin »

As mentioned in previous posts, this much detail about 1s and 2s complement is not required for the exam.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

Sergey
Posts: 39
Joined: Sat Jul 29, 2017 1:04 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1159 :

Post by Sergey »

I did not understand the explanation in programm, but i find this in the web:

Code: Select all

Basically, because Integer.MAX_VALUE is actually only 2147483647, so -Integer.MIN_VALUE, which would be +2147483648, actually overflows the capacity of the internal binary representation of integers. Thus, the result "loops around" back to Integer.MIN_VALUE, or -2147483648.
is it correct?

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

Re: About Question enthuware.ocajp.i.v7.2.1159 :

Post by admin »

Yes, the explanation explains the reason why "loop around" happens.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests