Juva Yuva

Greenhorn
+ Follow
since Dec 18, 2008
Merit badge: grant badges
For More
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
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Juva Yuva

Originally posted by Siddharth Bhargava:




During Compile time, compiler believes the code and casting that was done. But during runtime , it actually checks the type of the object while casting.

the first line(Manager manager = (Manager)staff[0]; ) works , because staff[0] is actually an object of Manager .

the second assignment will fail , because the staff[1] contains Employee object which cannot be cast to it subclass (Manager)

Always remember the rule , that Manager is a Employee , but all employees cannot be Manager. Try working out is-a relationship and cast it.
So ,
[ December 27, 2008: Message edited by: Juva Yuva ]
15 years ago

Originally posted by Juva Yuva:


Thats because you declared the method (factorial) as Class method. And since main is static , methods can be called directly . Otherwise It can be accessed in non-static way , by creating instance of the class.

1) Try creating an instance of the class in the main method , call the factorial method with the instance.
2)And remove the static modifiers from the methods

15 years ago

Originally posted by Rob Prime:
To be even more precise:

No need for the else here. I even set up my Eclipse to warn me if I use unnecessary else blocks.




Yeah . But If the code inside the if statement is not "return" statement then if , else if makes difference
15 years ago

Originally posted by seetharaman venkatasamy:


1.two different browser-----------> then two different session id

2.two different window from same browser-----------> then only one session id

Hope this helps



And thats why session attributes are not thread-safe
15 years ago

Originally posted by Steve Fahlbusch:
The code inside the method can be reduced to:



To be more precise



15 years ago
Did it thrown any error ? can you elaborate the output of javac as seen when executed
15 years ago

Originally posted by Juva Yuva:
What are the basic steps to create Immutable classes ?

1) Declaring the class as final so as to avoid subclassing and overriding
2) Declaring the accessor methods for the instance variables
3) Making the instance variables private.

Is that all.Anything i missed ?

[ December 25, 2008: Message edited by: Juva Yuva ]



Thanks Harvinder.
Correcting my steps ( for other beginners to read)

1) Making all the instance variables final and private.
2) Declaring and implementing public accessor methods for the instance variables.
3) In the accessor method (get) , sending the copy of the instance variables by creating clone , so to avoid the reference being used outside to change the state of it.
4) Declaring the class as final so as to avoid subclassing and overriding (optional, so as to provide Mutable functionality by subclassing )
[ December 26, 2008: Message edited by: Juva Yuva ]
15 years ago

Originally posted by Suresh Rajadurai:
Hi Folks,

Is there any method to get the type of the variable (primitive)? Something like this:



I m afraid , we cannot call any methods on the primitive type ( as it does not have behaviours) and hence the answer should be NO.
15 years ago
Thanks Christophe. But What i need is to consolidate the important differences/enhancements between 1.4 and 1.6, rather than finding between 1.4 to 1.5 and then to 1.6. I m wondering if anybody has already done that consolidation and posted in any link?
15 years ago
Hi,

Can anyone post some good links where i can get the exact differences between 1.4.2 and 1.6 ? I searched and could not find anything useful.thanks.
15 years ago
What are the basic steps to create Immutable classes ?

1) Declaring the class as final so as to avoid subclassing and overriding
2) Declaring the accessor methods for the instance variables
3) Making the instance variables private.

Is that all.Anything i missed ?
[ December 25, 2008: Message edited by: Juva Yuva ]
15 years ago

Originally posted by Dikesh Stha:

without formation of objects of super classes sub class objects can not be created and cannot be able to access class variable..Is this right or not??

dikesh



Its possible to create an subclass object and use the variables and methods (state and behaviours ) of the super class without any reference to Super Class. If you dig in to the subject , you could realise how abstract classes and inheritance are used as super classes/interfaces without ever creating objects of them .

During inheritance , all the variables and methods ( including static , final) are inherited to the subclass except the constructors and private ones. And subclass behaves as if the inherited methods are their own methods and thats wat OOP is all about.

Juva
[ December 22, 2008: Message edited by: Juva Yuva ]
15 years ago
I think as long as the compiler is concerned , it checks for the overriding rules at first (neither cares its defined as static or non static ) , which causes the exception as faced -lesser accesser specifier for the overriden method in subclass.

Actually when it matters was, when the method was actually called.Where it uses shadowing (hiding) to call the method as explained in another thread.

https://coderanch.com/t/410462/java/java/Static-Methods-Interface
[ December 20, 2008: Message edited by: Juva Yuva ]


With a subclass, you can access all protected variables of the super class -- not only for the "this" instance, but for any instance passed into it as well. However, the instance that is passed to it, must be at least of the type of the subclass.



Thanks Henry. but need more explanation on the visiblity of the protected variables ?
[ December 19, 2008: Message edited by: Juva Yuva ]
15 years ago