About Question enthuware.ocajp.i.v8.2.1350 :
Moderator: admin
-
- Posts: 21
- Joined: Mon Oct 24, 2016 6:55 am
- Contact:
About Question enthuware.ocajp.i.v8.2.1350 :
How does it parse directly double value?
Float.valueOf("12.3");
Float.valueOf("12.3");
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1350 :
Not sure I understand your question. "12.3" is not a double. It is a String.
Paul.
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 3
- Joined: Sun Jan 29, 2017 1:54 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1350 :
i have the same question as nikitos.admin wrote:Not sure I understand your question. "12.3" is not a double. It is a String.
Paul.
because you cannot do like
Code: Select all
Float f = 12.5
found this:
Float (Java Platform SE 7 ) wrote:The numerical value of the input string is converted directly to the target floating-point type. In general, the two-step sequence of conversions, string to double followed by double to float, is not equivalent to converting a string directly to float. For example, if first converted to an intermediate double and then to float, the string
"1.00000017881393421514957253748434595763683319091796875001d"
results in the float value 1.0000002f; if the string is converted directly to float, 1.0000001f results.
-
- Posts: 1
- Joined: Fri Sep 22, 2017 6:21 am
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1350 :
Need some help with the same concept.
How does compiler catch this :- Integer intObj = 123.3;
But not this :-
Float f = null;
f = Float.valueOf("12.3");
String s = f.toString(); int i = Integer.parseInt(s); // One reason i can think of is, output of toString() is not decided till runtime ?
How does compiler catch this :- Integer intObj = 123.3;
But not this :-
Float f = null;
f = Float.valueOf("12.3");
String s = f.toString(); int i = Integer.parseInt(s); // One reason i can think of is, output of toString() is not decided till runtime ?
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1350 :
Yes, compiler doesn't know the value of s because the compiler can't execute any code. That is why the compiler does not know that s points to a String that cannot be parsed into an int.
If you like our products and services, please help us by posting your review here.
-
- Posts: 2
- Joined: Thu Dec 28, 2017 10:02 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1350 :
Gentlemen,
I'll dare to ask this question again since there were no answer provided yet.
Yes, we understand that "12.3" is not a double. It is a String.
But the value it represents - 12.3 - is double, not float.
How come that during the convertion from string 12.3 it becomes a float?
Thank you.
I'll dare to ask this question again since there were no answer provided yet.
Yes, we understand that "12.3" is not a double. It is a String.
But the value it represents - 12.3 - is double, not float.
How come that during the convertion from string 12.3 it becomes a float?
Thank you.
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1350 :
Because the method that parses the String argument and converts it to float is coded to accept a String that doesn't end with f. Here is what the JavaDoc API description of Float.valueOf (which is what Float.parseFloat invokes internally) says:
Note that trailing format specifiers, specifiers that determine the type of a floating-point literal (1.0f is a float value; 1.0d is a double value), do not influence the results of this method. In other words, the numerical value of the input string is converted directly to the target floating-point type.
If you like our products and services, please help us by posting your review here.
-
- Posts: 2
- Joined: Thu Dec 28, 2017 10:02 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1350 :
Okay, now it's more clear.
Thank you.
Thank you.
-
- Posts: 12
- Joined: Tue Mar 06, 2018 9:54 am
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1350 :
This is another question where the answers help find the solution;
The first two answers are:
12
13
But the code says:
So those answers are never correct. I think they should be:
i = 12
i = 13
The first two answers are:
12
13
But the code says:
Code: Select all
System.out.println("i = "+i);
i = 12
i = 13
-
- Posts: 29
- Joined: Sun Feb 11, 2018 3:13 am
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1350 :
Will the value of f not be unreachable from the catch block? (There were qs in other tests in which we try to print a variable declared in the try block in the catch block and it doesn't compile in these cases.) So I marked trouble: null!
Am I missing something?
Am I missing something?
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1350 :
Why do you think it is unreachable?
An unreachable statement causes compilation error. So even if you think it is unreachable, why do you think it will print trouble: null?
An unreachable statement causes compilation error. So even if you think it is unreachable, why do you think it will print trouble: null?
If you like our products and services, please help us by posting your review here.
-
- Posts: 29
- Joined: Sun Feb 11, 2018 3:13 am
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1350 :
Yes YesAn unreachable statement causes compilation error.
1. I thought it would print trouble:null because f is initialized to null outside the try block (and so is an instance field).
2. There were questions similar to this in the previous tests.. I don remember the q number, though; where the answer was "compile time error" I guess when we try to access a value from the catch block which was in try. The scenario might have been slightly different.
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1350 :
If there is a compilation error, how will the program run to produce any output?
You really need to go through a good book before attempting mock questions.
You really need to go through a good book before attempting mock questions.
If you like our products and services, please help us by posting your review here.
-
- Posts: 29
- Joined: Sun Feb 11, 2018 3:13 am
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1350 :
I actually got your point. Thank you..!
And I have read Kathy Sierra's complete OCA syllabus!
And I have read Kathy Sierra's complete OCA syllabus!
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1350 :
You might want to try the one by Jeanne Boyarsky or Mala Gupta.
If you like our products and services, please help us by posting your review here.
-
- Posts: 29
- Joined: Sun Feb 11, 2018 3:13 am
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1350 :
Yupp yup. Thank you!
-
- Posts: 1
- Joined: Tue Nov 26, 2019 12:29 am
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1350 :
It is a compile-time error if a statement cannot be executed because it is unreachable. This means that the control flow of your program can't get to that statement, but you assume that they would be. The compiler analyzes the flow, and reports these statements to you as error messages. It is a reliable indicators of logical error in your program.
When the compiler reports an unreachable statement, it typically points you to the statement. When that happens, you can follow the flow of control from top to bottom to discover why the statement can never be reached. There are quite strict rules when statements are reachable in java. These rules are design to be easily evaluated and not to be 100% accurate. It should prevent basic programming errors.
When the compiler reports an unreachable statement, it typically points you to the statement. When that happens, you can follow the flow of control from top to bottom to discover why the statement can never be reached. There are quite strict rules when statements are reachable in java. These rules are design to be easily evaluated and not to be 100% accurate. It should prevent basic programming errors.
Who is online
Users browsing this forum: Bing [Bot] and 32 guests