Rohan Deshmkh

Ranch Hand
+ Follow
since Aug 31, 2012
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
(keep public parts private until JForum day)
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by Rohan Deshmkh

In java the if condition must have a expression that results into a boolean value.But the closest i got to print hello world was using the foll code:

5 years ago

Kaydell Leavitt wrote:
I read that it isn't good to use nextInt() anyway because it doesn't validate. I believe that you can get stuck on nextInt() when it's in a loop and the next character is not a digit and it never will be.

I haven't came across this, maybe you could give some example, then we can find it out.

Kaydell Leavitt wrote:
Would you say that you should always use nextLine() or next() and always input String objects and then do validation in your own Java code?

I don't think that we should always ignore nextInt() , it's there for a purpose.
5 years ago
Here is why you should use Scanner.nextLine() :

scanner.nextInt() will only take integer value entered and not the \n(When we hit enter after entering the integer). So this \n is still in the buffer, so when we use scanner.nextLine() after sacn.nextInt() it takes or stores \n.That's why nextLine() was returning empty line.
5 years ago
Use scanner.nextLine(); after line 12.
It has got nothing to do with mac or windows.
When you use the same scanner object to take inputs int and then string then always use scannerobject.nextLine().
5 years ago
I forgot to mention my problem.
I am getting output correctly, but from the above problem what i have achieved is:

Robert checks for balance,see's it's enough
Robert completes withdraw
Kristen checks for enough balance, it's not enough,so she gets a message " cannot withdraw due to Low balance"

I think that although i am getting the output correctly, this is not the correct approach to show the use of synchronized method.I think both should have checked if there's enough balance , for for both it should have told "yes there's enough balance".And then one of them should go for sleep,the other completes the withdrawal and when the second one when withdrawing should get the message "there's not enough balance"
5 years ago
I am trying to understand the synchronized keyword practically.So,Here's the problem:

Initial balance is 1000.It's a joint account of Robert and Kristen.
Both want to withdraw 1000 from that account at same time from different locations.
Now , here is the flow of program that i want to achieve:

Robert checks balance,see's it's enough
Robert sleeps
Krsiten checks balance, see it's enough
Krsiten withdraws
Now, when Robert wants to withdraw he see's that there no enough balance, so he get's a message "not enough balance"

Kristen and RObert names can be interchanged as we are not sure which one will be picked by jvm to execute first.

Here is my code:

5 years ago
Yes seems like a bug, is getting generated in version 11 properly.Looks like version 11 does not have xml gui builder, waiting for version 12 which will be releasing in December.
5 years ago

Ulf Dittmer wrote:IntelliJ 12 hasn't been released yet; maybe a bug in the beta version?

OK thanks i am downloading version 11 now, i will install it and report back if it works or not.
5 years ago

Maneesh Godbole wrote:I don't use IntelliJ but sounds like you have an IDE refresh issue. Maybe you can try refreshing the file/workspace?

I tried android with eclipse first , but i didn't liked it, it was very slow on my pc.But then i tried intelliJ12 and i loved it.It's very fast as compared to eclipse.So, the point is i am also new to Intellij, i tried the option "Force regenerate" but still nothing happens.I will now figure out how to refresh file or workspace in Intellij as it's not visible when you right click the project .
5 years ago
I am using intelliJ 12 and i am experiencing weird problems regarding in gen folder.
I just started with android programming and have made 2-3 very very simple apps, all of them runs correctly.But all of them have one common problem:
My file inside gen folder is not getting generated automatically, so it does not contain the code that should be present there.But still my apps runs fully.Is there a way to fix this?
5 years ago
Thanks Jeff for explaining it with the example, i understood what you said.
5 years ago
Hey thanks Jeff , i got some of the things you mentioned but I didn't understand the following quote:

Jeff Verdegan wrote:. Is there some reasonable common/default behavior that could be provided for at least some implementations? Then use abstract class. Are we defining a pure abstract type? Then use interface. And in many cases we use both.

I understood about when to use abstract class but i am not able to understand this line:

Are we defining a pure abstract type? Then use interface.

Can you give an example about pure abstract type?

5 years ago

Campbell Ritchie wrote:Thank you for quoting the book.
I don’t know whether our FAQ would help you. I did not think that passage from the book is very clear; it might be clearer in the context of the whole paragraph, however.

I don’t know whether this sort of example helps, but let’s try:-

I could not understand how your above code is advantageous in code reuse.Here is the full context from that book:

Q. When to use an abstract class?:
In case where you want to use implementation inheritancethen it is
usually provided by an abstract base class. Abstract classes are excellent candidates inside of application
frameworks. Abstract classes let you define some default behavior and force subclasses to provide any specific
behavior. Care should be taken not to overuse implementation inheritance as discussed in Q10in Java section.

Q. When to use an interface?:
For polymorphic interface inheritance, where the client wants to only deal with a
type and does not care about the actual implementation use interfaces. If you need to change your design
frequently, you should prefer using interface to abstract. COCoding to an interfacereduces coupling and
interface inheritance can achieve code reusewith the help of object composition. For example:The Spring
framework’s dependency injection promotes code to an interface principle. Another justification for using interfaces
is that they solve the ‘diamond problem’ of traditional multiple inheritance as shown in the figure. Java does not
support multiple inheritance. Java only supports multiple interface inheritance. Interface will solve all the
ambiguities caused by this ‘diamond problem

5 years ago

Campbell Ritchie wrote:I am not sure you have understood it. You can provide getXXX methods for those instance fields which are used by other classes, and setXXX methods for fields which are set from other classes. Obviously you don’t always need both setXXX and getXXX methods for a particular field.

Thanks i completely understood what you meant, thanks for putting it in a nice and understandable manner .
5 years ago

Paul Witten wrote:
What they mean is "if you are forced to redesign your class often then that indicates that a polymorphic interface(s) would be preferable."

Yes i understood that, but i wanted to know why polymorphic interface would be preferable?And also what advantages does interface have over abstract class when redesigning is the issue?
5 years ago