About Question enthuware.ocajp.i.v8.2.1415 :
Moderator: admin
-
- Posts: 4
- Joined: Sat Aug 06, 2016 11:07 am
- Contact:
About Question enthuware.ocajp.i.v8.2.1415 :
Hello Paul,
Sorry if my question is silly but I wanna know whether in real exam the difficulty level be specified or not?
Like easy,real brainer Just wanted to know
Sorry if my question is silly but I wanna know whether in real exam the difficulty level be specified or not?
Like easy,real brainer Just wanted to know
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1415 :
No, the real exam does not specify the difficulty level and the exam objective. Our simulator lets you hide both.
HTH,
Paul.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 3
- Joined: Thu Aug 04, 2016 10:40 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1415 :
I'm still a bit confused about Boolean.TRUE. Does this return a wrapper object or a primitive?
This is where my confusion stems:
This returns "false" which implies that both sides of the expression represent Boolean objects in which case no unboxing would occur.
However, the following returns "true":
This would seem to imply that unboxing is occurring. If Boolean.valueOf("true") returns a wrapper object and Boolean.TRUE returns a wrapper object, how is it that their equality comparisons return true?
This is where my confusion stems:
Code: Select all
new Boolean("true") == Boolean.TRUE
However, the following returns "true":
Code: Select all
Boolean.valueOf("true") == Boolean.TRUE
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1415 :
Boolean.TRUE is a Boolean object. Please see this: https://docs.oracle.com/javase/8/docs/a ... .html#TRUE
Boolean.valueOf also returns a Boolean object.
So there is no reason for unboxing.
HTH,
Paul.
Boolean.valueOf also returns a Boolean object.
So there is no reason for unboxing.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 14
- Joined: Sat Dec 17, 2016 10:17 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1415 :
Hello, I was wondering if the case of Boolean.valueOf(Boolean boolean) creates a different object type from new Boolean(boolean) is unique to the Boolean class. For instance, does Integer.valueOf(Integer integer) create a different object type from new Integer(Integer integer) or are the two Integer methods substitutable? I did some research online but can't seem to find the answer. Thank you.
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1415 :
There is no valueOf method in Boolean that takes a Boolean. There is one that takes a boolean, though. The Javadoc API description clearly says that it returns Boolean.TRUE or Boolean.FALSE object.
Now, regarding the Integer objects. Check out the JavaDoc. It clearly says the following:
You should try creating one Integer object using new and one using valueOf and compare them using ==. That will validate your understanding.
Paul.
Now, regarding the Integer objects. Check out the JavaDoc. It clearly says the following:
The new operator always creates a new object. So that means in both the cases above, the object created using new and the one received using valueOf are different objects.This method will always cache values in the range -128 to 127, inclusive, and may cache other values outside of this range.
You should try creating one Integer object using new and one using valueOf and compare them using ==. That will validate your understanding.
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 39
- Joined: Sat Jul 29, 2017 1:04 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1415 :
Why does new Boolean(null); return false? I thought it should be compile time error. Why null in this case considered like string?
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1415 :
So if you have some constructor or a method that takes a String (or any other class ) as an argument, can't you pass null to it? Yes, right?Sergey wrote:Why does new Boolean(null); return false? I thought it should be compile time error. Why null in this case considered like string?
It is the same thing.
If you like our products and services, please help us by posting your review here.
-
- Posts: 1
- Joined: Thu Apr 05, 2018 8:49 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1415 :
The reason this expression is true is that both sides of the expression point to static final Boolean.TRUE. That is because Boolean.valueOf(param) returns either Boolean.TRUE or Boolean.FALSEHowever, the following returns "true":
This would seem to imply that unboxing is occurring. If Boolean.valueOf("true") returns a wrapper object and Boolean.TRUE returns a wrapper object, how is it that their equality comparisons return true?Code: Select all
Boolean.valueOf("true") == Boolean.TRUE
-
- Posts: 85
- Joined: Mon Dec 24, 2018 6:24 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1415 :
new Boolean("no") == false;
Does left side of "==" unbox to boolean before the comparison? thanks
Does left side of "==" unbox to boolean before the comparison? thanks
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1415 :
Yes, as per 15.21.2 of JLS, if one operand of == is a Boolean wrapper and another is a boolean primitive, then the wrapper is unboxed.
You can test this easily by printing out the value of your expression new Boolean("no") == false;
You can test this easily by printing out the value of your expression new Boolean("no") == false;
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 60 guests