Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!

blossom belle

Ranch Hand
+ Follow
since Jun 17, 2017
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
5
Received in last 30 days
0
Total given
18
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by blossom belle

thanks campbelle ritchie 
9 months ago
i tried 2 online compilers !
9 months ago




I would like to know what is the reasoning behind the c++ code's behavior ? 
How can a value be assigned to a value instead of being assigned to an address ?
9 months ago
It's not that. I'm not meaning books or sources.
I do understand the concepts and what's happening in the code. But unlike my ease with arrays or lists, where I can start solving a problem instantly, with trees, even though I know how it works, it is hard to create a new algorithm for some prob on trees, or just find a solution for any tree based question.
So is it just by practice that it'll get better ? It's just confusing.
10 months ago
I'm talking about things like trees , binary tree, a morris traversal such as a morris inorder or preorder traversal, etc.
Many such operations .
10 months ago
As we all know, non linear data structures are more difficult to implement than linear data structures.

what is the way to master programming and cracking problems on non linear data structures ? it seems very confusing .
10 months ago
thanks,  will check again.
Is the OCA badge and certificate the same ?

if no, I would like to know how long does it take to get an e-copy of the certificate ? and do we get a hardcopy of the certificate and hoe long does that take if yes ?

i have received the badge alone through  link in mail.


I would like to add this !

instead of 'if' , while statement will not show the error and does not require return 0; outside the while loop too !
Arco ,

1. If a method is declared to have a return type, then a compile-time error occurs if the body of the method can complete normally (§14.1).

2. A break, continue, return, or throw statement cannot complete normally.

I feel these two statements from the JLS would help in having a better idea about the other possibilities .
thanks for all responses and the cow stephan ! 

Stephan van Hulst wrote:If you have lots of these questions, it may be worth your time to learn how to navigate the JLS. Even though it's technical, it is well written and has many links between related paragraphs.



The JLS is indeed such a vast ocean of many unpredictable facts !   

Stephan van Hulst wrote:https://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.4.7

If a method is declared to have a return type, then a compile-time error occurs if the body of the method can complete normally (§14.1).



so despite the 'if' being true always, the compiler looks at the path in the method outside the 'if' and doesn't find an abrupt completion ..... and hence , the error 
I can't see the rules for normal completion. what are those rules about normal completion especially the return statement. I don't seem to find them

shambhavi sham wrote:In addition , I have a doubt regarding the behaviour of the following code snippets too :

CODE A : 
Here, since 'if' is always true and determined at compile time itself, we know for sure that c and d will be initialized before its use . so it compiles fine. but when if is false i.e. if(false) will give an error since c and d will be used without initialization .






CODE B :

Similarly, over here at compile time, we know that if is true and so surely the return statement will get executed,similar to the above example. but yet, it shows an error and expects a return statement outside the if block too. 




why are both the codes contradicting ?



Ok. but I don't think that answers my question in this post quoted. My doubt is : in code A, since 'if' is true is already known,  we know for sure that c and d will be initialized before its use. hence, initialization of c and d is not required after the 'if' block too. so it compiles fine. but when if is false i.e. if(false) will give an error since c and d will be used without initialization .

But a similar explanation for code B doesn't hold true, because even though in code B, 'if' is known to be true always and hence will surely execute the return, it expects a return outside the 'if' too . why ?