Pallavi Sadit

Ranch Hand
+ Follow
since Jul 24, 2014
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Pallavi Sadit

A. (a,b) -> (a-b)
B. (a,b) -> 5
C. (a,b) -> i++
D. None of the above are appropriate.

The answer in the book is B, because it satisfies the two requirements - being associative and stateless. I totally agree with this answer if the reduce had just two arguments - identity and accumulator.
I am confused here , because there is a combiner also present in the reduce method which is s1+s2. Now, combiner has the contract that should return u, which is satisfied here as identity is 0. There is one more requirement : should be equivalent to
Suppose u and t both here are 5 as accumulator returns 5 for any two values in stream. so, combiner.apply(5, 5) is 10 whereas accumulator.apply(5,5) would return 5.  So, as a whole , to me the answer D looks closer.
Please clarify if my understanding is not right.
Question 28:

The answer says " The method compiles and returns a Path value that is always equivalent to the input argument." which is not correct. When the path is absolute, it returns the same path back, but if it is not null and relative, it returns absolute path , which may be from the current working directory and would not be equivalent to input argument.


The absolute path is equivalent to input path but the relative one is not.
Chapter 7 , Q 14 has actually two correct answers B ) HH:mm and D) hh:mm

This also prints 02:33. The difference only is that h represents a 12-hour day and H represents a 24-hour day. Since , the time 02:33 can be there for both 12-hour and 24-hour clock when am/pm is not specified, both the options should be valid.
Until now, even though the API were marked as deprecated, they were never removed. So, developers were relaxed and comfortable to let things run the way they are and not go to the trouble of replacing them. But now , things have changed in Java as well with Java 9. See this JEP . Now, the deprecated API which are marked with forRemoval = true, will be removed in the next major release. So, the developers will be forced to be attentive and replace them.
4 years ago

Viktor Logwin wrote:Your book doesn't need a promotion. It's like a new iPhone coming out  
I don't gonna take part in the promotion, because I already have the book, but I would like to thank you, Jeanne and Scott, for your work and your engagement in helping people to prepare themselves for certification and to learn Java.
You're great!  

Please, don't stop, keep creating new books about further topics like Spring/Java EE/Design Patterns...  

I too wholeheartedly agree with this comment, I used your OCA book for preparation of the exam and am using the OCP book now. And I am sure I will be using this one as well before I finally appear in OCP exam.
Thanks for sharing this.
6 years ago
Thank you Ankit. I understood now, the IOException and Suppressed exception are caught by the catch block , and finally a RuntimeException is thrown which is uncaught. So that is the one that is thrown at the end of the code and hence the answer.
Need help with the following question, can someone elaborate on the answer provided in the book.
The question is as follows:
10. Given:

Which exceptions will the code throw?
A. IOException with suppressed RuntimeException a
B. IOException with suppressed RuntimeException c
C. RuntimeException a with no suppressed exception
D. RuntimeException c with no suppressed exception
E. RuntimeException a with suppressed RuntimeException c
F. RuntimeException c with suppressed RuntimeException a
G. Compilation fails

According to me the answer should have been F, but the answer is D, I am not clear with the explanation to the answer. I tried modifying the code to the following to verify if there is any suppressed exception, and I could see that there is indeed one.

Suppressedjava.lang.RuntimeException: a
Exception in thread "main" java.lang.RuntimeException: c
at com.explore.pallavi.Animals.main(
When we give the curly braces, this means the method has a body. Even if there is no implementation code inside the body, it will be considered as valid implemented method. You can let the method do something by putting some code inside the body, leaving it just means method is not doing anything right now, may be in future you may add something.
Hi Sam,
I am at a point in my career where I am thinking of a job change. Your book comes handy at this time . I want to know how many years of Java/JEE experience has this book been written for? Is it only for developers who have around 4-7 years of experience or it covers stuff for technical architects (11-12+ years) or Senior Lead developers (8-10) also ?
6 years ago
I too guessed output to be Hello world, and then to check my answer, tried to copy the code and run. Unfortunately, I copied only the code part (without comment), so it worked perfectly for me :P . I had to look up the answer in the book to find out what am I missing.
6 years ago
I live in India. In my apartment, we follow 2 bin 1 bag method. One green bin which can be lined only with paper (no plastic bags lining allowed) -this is used for all such wastes that can be decomposed , like the kitchen wastes (fruit and vegetable peeling, spoiled cooked food etc.). The other red bin is used for all the sanitary wastes, floor dust and other wet waste - this bin can also be only lined with a paper and no plastics to be thrown in any of these two bins. The bag, which is a reusable jute bag has to be used for dry waste - like wrappers, waste plastic bags , milk packets , grocery plastic bags etc.
We place the two bins and bag outside our door while leaving for office. The house keeping staff is paid to collect it door to door and dump appropriately in 3 large bins. Finally the waste in the large bins is collected by a local NGO/ Municipal Corporation.The reason for the segregation is to reduce the amount of waste going to the landfills , generate compost from the degradable waste and recycle the ones in dry waste.
6 years ago

Nikhilesh Puranik wrote:Thanks for the reply. I do know the basic functions (definitions) of the loops. What I meant in my question was that I need to know how the loops in this program work depending on the input we give during program execution.

Hi Nikhilesh,
You can try adding some logging (System.out.println) inside the loops and check how the loops are working, what algorithm is it using to sort the numbers.
6 years ago
Just wondering how useful will it be to learn a new language unless you are going to work on it, won't we forget it if not put into practice?

Deviating slightly from the topic of the thread, can't stop myself from expressing it.Apart from the help on my queries that I get on CodeRanch, I visit it regularly for the motivation I get,seeing enthusiasm of the fellow ranchers, bartenders etc. here to keep learning and updating oneself. This thread is one such example.
Also,even though I am not reading this book right now, I am able to get a glimpse of the book through the threads here, which again adds to the benefits I am getting from this community .
Thank you for the great work JavaRanch family !!!
7 years ago