salvin francis

Bartender
+ Follow
since Jan 12, 2009
salvin likes ...
Google Web Toolkit Eclipse IDE Java
Forum Moderator
salvin francis currently moderates these forums:
Mumbai
Cows and Likes
Cows
Total received
130
In last 30 days
0
Total given
155
Likes
Total received
402
Received in last 30 days
13
Total given
204
Given in last 30 days
3
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt Green check

Recent posts by salvin francis

Hi George, welcome to coderanch. We wish you the best in your quest to learn java

Where did you get this program from ? Please QuoteYourSources <-- It's a link
Next, what happens when you run this program ?
I see a variable called smallest in line #9 and another one at line 16, which one are you confused about ?

If you haven't done it already, I suggest having a look at oracle's tutorial for java. Specifically about methods: https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html
and this: https://docs.oracle.com/javase/tutorial/java/javaOO/returnvalue.html

Do let us know if you still have any doubts about the code above, we would love to discuss further !
9 hours ago
I wanted to share.. this would have been my submission:
4 days ago

Monica Shiralkar wrote:...He was talking something about O(n)/ O(1)/O(2) something.


Isn't it a homework for you to figure out what that is ? Also can you share your final program after all the discussions we've had so far ? Maybe we can discuss about what you think the Big-O notation for your program would be and why.
1 week ago
Also looking at the code OP posted :
I suggest removing code that calls the same method repeatedly as in the case of charAt above. If a method always returns the same value (for the given 'i'), let's just call it once reducing that code to something like this :

As Campbell pointed out, the 'i' is not even needed above if we can use the enhanced for-each loop instead.
1 week ago

Monica Shiralkar wrote:

salvin francis wrote:...

I will correct it. By 'modifies' do you mean the delete line ?

I do mean any kind of modification. If a method says print, it should ... print !! But of all the modification sins the method can commit, deletion ranks the highest

As an analogy in real life, if you handed over a few paper sheets to an employee to read out loud to the team, you wouldn't expect him/her to scribble something on it and return it back. (that's modification).
Now, taking this a step ahead, you wouldn't expect him/her to to promptly shred any random pages once he is done reading. (that's deletion).
1 week ago
Adding to what campbell said...

I would be very angry to see a method called "printMap" that modifies the map I pass to it. Even angrier if it deletes something from my map.
1 week ago

Monica Shiralkar wrote:But in Java 8, default methods were introduced and that difference seem to have gone as now interfaces too aren't completely abstract.


Technical stuff aside, I think there's a difference in intent as well. While an Interface is a contract, it lacked the functionality of adding new methods to it without breaking existing code. This is why default methods were added. I would treat them as an exceptional case e.g. where an API is live and is used by other developers.
1 week ago

Itsumo Snow wrote:... Thank you so much for explaining this, I know it's a very stupid question, I just started learning java and my questions are silly.


Glad to help  
1 week ago
First of all ... Welcome to coderanch !! We hope you have an amazing time here in your quest to learn coding !!

I think your program can explain itself. I have added a few print statements to your method setFavoriteArticle :
I suggest running this and letting us know if the output makes sense ;)
1 week ago
There are still a few more cases to consider that's not discussed in this thread. e.g. a third party library having a memory leak after some odd set of transactions, etc...
One can keep adding more cases to this hypothetical situation. There is no single rule on what to do in this situation.

As with any production issue, the more you dig into the logs and metrics of the system, the more clues you get to solve the particular issue.

As an interviewer, If I ask this question, my aim would be to get a conversation about two items:
1. If the candidate has faced this issue in the past, how has he solved it
2. How will he use this experience to solve this issue in the future.

1 week ago

Zachary Griggs wrote:...Append that character onto a new String...


Wouldn't it be simpler to run a simple loop and prepend instead ?
2 weeks ago