Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link

Arjun Narsipur

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

Recent posts by Arjun Narsipur

Thanks all. Its clear to me me except for one nagging doubt which I have, i thought about it a lot but still can't figure it out.
Lets say i pass a primitive integer variable named s (holding value 5) to a method. Now the method gets a copy of the variable and and let's say it increments it to 6 (by using s++) . We now have two variables (the original one and one with the method) both named s but one with value 5 and the other with value 6. is this allowed?
8 years ago

manish ghildiyal wrote:Hi Arjun,

What I mean to say is that variable a which you pass as argument (to modify method)
in main method is copied when modfiy method is invoked...so variable which is actually modified inside modify method is not the variable a of main method, its just
a copy of it...so inside modify method you are not incrementing variable a of main method but rather a copy of it which is local to modiy method.
So variable a of main method reamains unincremented.

Manish



I think I got it. Is it now correct to generalise this and say that if i pass a primitive (and not a reference) to any method, the method actually works on a copy (BY VALUE!) of that variable and not on the original?

Regards
Arjun
8 years ago

manish ghildiyal wrote:..additionally

in your first case you are passing a primitive and not a reference...so when copying of
argument happens then you get two different entities which are in no way connected.So
modifying one doesn't impact other in any way.

Manish



So Manish

If I understand correctly are you saying that in the following code






the value of a++ is different from value of a? In which Case we have a value for a and another for a++ stored in two different locations? But doesn't a++ mean increment the value of "a" by 1 and store it in "a"?

Thanks for clarifying.

8 years ago

Maneesh Godbole wrote:

Arjun Narsipur wrote:
How do I know which of the key words ought ot be in caps and which in small?


All java keywords are lower case.
By convention, class names should be capitalized. Check out http://www.oracle.com/technetwork/java/codeconv-138413.html

I believe, modern text editors like JEdit (also) have the ability to colorize these to provide you visual clues. (e.g. the keyword "private" shows up in red color) IDEs such as Eclipse certainly do.




Thanks a lot. I downloaded and using Netbeans and so far the experience is good. Query resolved.
8 years ago

Ivan Jozsef Balazs wrote:Java is case sensitive: public != Public.



Thanks a lot, I had overlooked it. Also I realised I had made the mistake of keeping S in "System.out." in small.

How do I know which of the key words ought ot be in caps and which in small?

8 years ago

Hi All

I tried to compile the following code but i get 2 errors.

Errors:::
C:\java Programs>javac MonsterTestDrive.java
MonsterTestDrive.java:4: error: class, interface, or enum expected
Public class MonsterTestDrive {
^
MonsterTestDrive.java:7: error: <identifier> expected
Public static void main(String [] args) {
^
2 errors




Code:::
Public class MonsterTestDrive {


Public static void main(String [] args) {


Monster[] ma = new Monster[3] ;

ma[0] = new Vampire() ;
ma[1] = new Dragon() ;
ma[2] = new Monster() ;

for (int x = 0; x <3; x++) {

ma[x].frighten(x) ;

}
}

}


class Monster {

boolean frighten (int d) {

system.out.println ("arrrgh");

return true;
}

}


class Vampire extends Monster {

boolean frighten (int x) {

system.out.println ("a bite?!!");

return false;
}

}

class Dragon extends Monster {

boolean frighten (int degree) {

system.out.println ("breathe fire");

return true;
}

}

===================

Can somebody help me understand the issue here please?

Regards

8 years ago