Narayana Bojja

Ranch Hand
+ Follow
since Jun 30, 2016
Narayana likes ...
Hibernate Spring Java
Merit badge: grant badges
For More
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 Narayana Bojja

Thanks again Salvin. I agree . Based string class hashcode method implementation, s1, s2, s3, s4 hashcodes can be same. == operator checks hash code values, right ?. Why s1==s3 is false and s1.hashCode() == s3.hashCode() is true in below code .


true false false

Thanks for the reply Salvin. I already mentioned reply method of chars type behaviour in the question. I want answer for why s1, s3, s4 hashcodes are same and When I compare with == operator , it is returning false. Why ?
Hello Coderanch team,

It' output

true false false

As per the replace method of char type version implementation, replace method returns same object if both the parameters are same. So, s1, s2 will refer same object. s1==s2 is true as expected.
Replace method of string type, replaceAll methods must return new string object always. When I compare s1, s3 and s1, s4 with == operator , there are returning false. If I print their hashcodes , all hashcodes are same.
I tested with both Java 8 as well Java 11.
Could you please help me with this ?

Charles O'Leary wrote:
while the super class's Animal eat method states that it throws a checked Exception that must be either handled or declared per definition of checked exception (if/when an exception does not extend Runtime Exception).

I hope that helps.

So, I am correct.

Charles O'Leary wrote:Let's try your "understanding", please see output:

Dog eatsDog eats

I hope that helps.

No. I know that if we handle or declare that checked exception , code runs and gives output " Dog eatsDog eats ".  But my question is different. I am asking about explain to the error. I have wrote my understanding about the error . Is it correct ? or Am I missing anything ?

When we compile above code , it gives below error.

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Unhandled exception type Exception

at com.Dog.main(

My interpretation for above error is as follows.

Animal a = new Dog();;

Here, "a" type is Animal. So, java compiler checks eat() method in Animal class. It is throwing checked exception. We didn't either declared or handled that checked exception in Dog class main method. So, We get compiler error.

Is my understanding correct ?
If wrong , Could some one  explain what is internal process for this error, please ?
Hi Tim Moores,

Thanks for your reply. I understand. I need answer for another question . For OCPJP examination point of view ,  we need to follow JDBC documentation only right ? Please share your suggestions ?
Hi Every one,

I have question  which is similar to this question which asked almost 10 years back. ResultSet. But there is no expected answer.  If ResultSet  type is forward only , you can read data in only forward direction. we can't apply absolute method on that ResultSet as per JDBC API specification . I tried sample example using Mysql databese . It allows reading ResultSet (forward only) in both forward and backward. I am able to apply absolute method .  The same question is asked in Mysql forum Mysql forum .  
So , I what want to know is What are the  JDBC drivers which allowes both  forward and backward readind data from ResultSet (forward only) ?. If a question asked in OCPJP exam of this type, Which standard we need to follow ? I mean Do we need to follow according to JDBC documentation ( or API ) ? or Do we need to follow according to  specific driver implementation ?

The same kind of question has been asked . I given my suggestions OCA_study_Tipes. If you are preparing for OCA7, I would recommend you OCA7 by Mala Guptha. It is like spoon feeding.
Hi Harshal,

3 Errors :can not find the symbol DateTimeFormatter  

Error is clearly saying you didn't import the package where DateTimeFormatter   is available in your program.

You imported only java.time package. But DateTimeFormatter  is not available in java.time package. It is in java.time.format package . Just add the below line in your import section

. It works fine.

I want to add one more point. If you import like java.time.*; ,  Java imports only classes, interfaces,etc in java.time package only. Java doesn't import classes, interfaces,etc in sub packages of  java.time package.

Hope this helpful !
Hi Yogesh,

Here is the explanation about execution of your program.

Initially b value is false and i value is 1. Next do while loop . do while executes for the first time without condition checking.

Please observe the above do while loop condition. first you are negating b value and  you are assigning that value  to b again.
Iteration 1:
Control enters do while loop. i will becomes 2. next condition checking . while(b=!false) =>while(b=true) =>while(true). condition is true . so loop execution continues.
Iteration 2:
i will becomes 3. next condition checking. Now b value is true because of previous loop iteration. while(b=!true) =>while(b=false) =>while(false). condition is false. so loop execution terminates.
Now i value is 3. So the output is 3. Please correct me if anything is wrong.

Hope this helpful

As Henry already explained , I also want to give my opinion. Here you probably expected NullPointerException or ClassCastException. But that doesn't occur. NullPointerException occurs when you call a method/variable on reference variable which is  null. So here  you are not calling anything on references , so no chance of  NullPointerException. ClassCastException occurs when you type cast super class reference to sub class reference type if super class reference variable is pointing to super class object. Here super class reference variable is not  pointing to any object. So no chance of ClassCastException. Overall you don't get any exceptions here.
Please go through this thread OCP7_Certificate . There is scanned copy of OCPJP7 . OCA8 certificate also looks same and contains same information.