Siddhant Agarwal

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

Recent posts by Siddhant Agarwal

I am just beginning to work on a  JAVA based project under which I have an option to use either a JDBC based transaction or the Java Transaction API? Now, I am not much aware of both of them, but I went through few posts online. However, I couldn't really understand when to use which one? How do we differentiate what would suit our need under which scenario?
ohh. So, it has to be a difference in the list or type of parameters for overloading to be valid. For a change in modifier, access specifier, return type or anything else in the method signature won't make a difference.
Thanks for the clarification!

Sorry for the late reply.
2 years ago
I declared two functions in a class like this:


Case 1:
Only Type A and Type B are defined in my class
a. It compile successfully.

b. When I call function like this: or It calls the Type B implementation.

c. When I call function like this: It shows me a compile time error.

Case 2:
All three types are defined in my class -> I get a compile time error saying that func2 is already defined.

Firstly, why is this difference in behavior observed between Case 1 and Case 2? When we had two functions(Type A and Type B) where the only difference was the return type, it compiled. However, when we added Type 3, again with a different return type, it didn't compile?

Secondly, between Case1.b and Case1.c, on what basis does Java decide when to call which implementation of the function (between Type A and Type B)
2 years ago
Thanks for the explanation. I did try it out before posting the last reply and it does increase the capacity to 20, when we pass "abcd" to the constructor while creating an instance of StringBuilder. However, if I do an append, it does not increase the capacity unless and until it is required.
2 years ago
Sorry for the incorrect information in the post. As Zachary said, it happens when I create an instance of StringBuilder and pass a value in the constructor. That is when it prints the capacity as 20. It doesn't do the same when we do an append. As seen in the source code for StringBuilder it passes the string's length + 16 to the base, causing the capacity to be 20. I agree with Zachary, that we need not worry about the capacity at all in most of the scenarios. However, I was wondering is there any reason behind setting the capacity to size of string + 16, in the constructor of this class?
2 years ago
I was wondering, when we create an instance of StringBuilder, by default the capacity is taken as 16. However, after I execute sb.append("abcd"), the capacity value changes to 20? Why is that so? What is stored in the initially allocated memory space?
2 years ago
I was wondering, when we create an instance of StringBuilder, by default the capacity is taken as 16. However, after I sb.append("abcd"), when I check the capacity value again prints 20? Why is that so? What is stored in the initially allocated memory space?
2 years ago
I think I understand now. I went through various posts on stack overflow as well discussing the same thing and then tried with a sample code where the object of Chick class was created in some other class. So as long as the object uses the private member within the class, it works. If I create the Chick object in some other class, and try to access the private member of Chick, it shows me an error.
Thanks!
2 years ago


Why I am able to access a private member of a class using an instance of the same class? Doesn't that beat the purpose of data hiding?
I came across this example while reading through book "OCA Study Guide by Jeanne Boyarsky and Scott Selikoff". This example is given under Chapter 1 - Java Building Blocks, topic "Order of Initialization".
2 years ago