Win a copy of Head First Android this week in the Android forum!

Vaibhav Sagar

Ranch Hand
+ Follow
since Jan 07, 2016
Cows and Likes
Cows
Total received
2
In last 30 days
0
Total given
0
Likes
Total received
6
Received in last 30 days
0
Total given
3
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Vaibhav Sagar

I was hoping someone knew an interesting back story for why his handle is habuma  
5 years ago
I am reading Spring In Action by Craig Walls. I am wondering what does "habuma" mean.

Thanks.
5 years ago
I can think of two alternatives if the constraint is only about using the dog's instance created at line 11-



5 years ago
Hi, I need to store and retrieve Word files and display them as clickable urls in a web page. I am currently using Java to retrieve files directly from the file system(Java generates the file system path of the file and presents it as a url). Should I be using a NoSQL alternative like MongoDb for an increase in performance (I read that they are useful for storing and retrieving files)? If yes, then which database solutions(for e.g. MongoDB) would be good according to my requirements?

Thanks.
5 years ago
Hi Elim, if you run your code with few additional System.out.println() then you'll realize the issue with your code. For e.g.-



What is happening is that you are incrementing your counter "i" twice, once inside your System.out.println(i++); and once in the end of the for loop for (int i = 0; i < 8; i++) {
i++ basically means i = i + 1 in your code and you are doing this twice.
5 years ago
Hi, could you tell what value are you getting for "txtAddRooms.getText()"-

5 years ago

This is what I've though about, but it does not work either...



Why? You got a different error? If yes then what is it, if no then what did you change?
5 years ago
Hi Claire,

How about creating a class which contains these three as attributes?
For e.g. you could create a simple Person class with three fields- id, name and gender. Then each row in the text file(except the first one) can be mapped to a Person object. You could then add methods in this class to retrieve a person's details based on your requirements.
You could even create a List of these Person objects to map all the rows in the file if you need it.

Edit- I think I misunderstood your question(I now think that you meant that the sequence of the columns is random), Dave's comment below has the more appropriate answer.
5 years ago
Call to super will be placed in the Animal(String name) constructor. This is because we can't have a call to both super and this in the same constructor.
For e.g. what do you think would happen if the following was allowed?-


So your first example will be like this in terms of super/this calls-



This is called constructor chaining and eventually a constructor will need to call super(implicitly or explicitly), otherwise you'll get a exception like the one you got in your other example(because in other words that means the constructors are calling each other in a circular way).
5 years ago
Hi Liutauras,

Could you please elaborate why not to use the File object? I tried looking for it on Google but didn't find anything related to this.

Thanks.
5 years ago
Thanks guys for clearing this up. I was confused with the grammar and the wordings and I thought there is some concept that I am not aware of regarding 'this' . With Java one needs to be sure cause there are so many little gotchas here and there (IMHO).
5 years ago
I thought that 'this' inside a method refers to the object that called(invoked) the method. But while discussing it another thread I was told that its not the correct way to put it and "Rather, this refers to the current object on which the method was invoked. It's entirely possible that a different object could have called/invoked the method. ". My confusion is that how can a object call/invoke the method of an entirely different object?
For e.g. even if the object of class A wants to call the method of class B, then doesn't it need to first have an object of class B to call its method(and therefore the 'this' in the called method would refer to B because B is the object that called(invoked) the method)? I think I am overlooking some concept...



I created a separate thread as I did not want to hijack the OP's. Thanks.
5 years ago

Rather, this refers to the current object on which the method was invoked. It's entirely possible that a different object could have called/invoked the method.



Could you please give an example for this scenario?

Thanks.
5 years ago
Hi Bill,

Even though 'this' is an implied parameter, it still points to an object(the object that called the method). So for accessing the instance fields of that particular object you will need to 'objectReference.instanceField'. It doesn't matter whether the object reference was implicit (this.balance) or explicit(BankAccount ba = new BankAccount(); ba.balance = 100;).
Example-
5 years ago
Thanks guys. I also found that JLS says that this is correct behavior, https://docs.oracle.com/javase/specs/jls/se7/html/jls-12.html#d5e14527
I found it kinda counter intuitive at first but it does make sense and is the right thing to do by the compiler.

Ordering in case of instance intialisers would be from superclass to subclass.
5 years ago