sai prashanth

Greenhorn
+ Follow
since May 04, 2010
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 sai prashanth

ok, thanks Faisal!
13 years ago
Ok, so if I were to use 1.4 to compile this code that would give a compile error? Also, how would one know what version will be used to compile a code in the exam if not mentioned. can we assume it will be 1.6 if we are taking the 1.6 exam?

And..what about the rule that we cannot add primitives to collections?
13 years ago
This is a question on K and B book.




The answers were:

1. Result is 1 2
2. Result is 1 2 3
3. The code will not compile
4. Runtime exception


I thought the answer is 3 since we CANNOT add primitives to a collection. If it were Java 5 and using generics, we would have autoboxing, right? Since this is a pre-generics code wouldn't this code not even compile.

Well, the answer was 4 which I dont understand.

Anyone can shed some light?
13 years ago

Abimaran Kugathasan wrote:

sai prashanth wrote:
1. Is it true that if a class is serialized then its child classes is also subjected to serialization, unless there is a class which satisfies a -HAS-A- principle and that class is not serializable?



Have a look on this

sai prashanth wrote:
2. What happens if the first parents class is something other than Object and that parent class does not have a no-org constructor, say someone has defined a constructor with args ( which then would not allow for the default no arg constructor to exist unless you define it) ?



Why don't you try it?



The thread is incomplete and like you I too was not able to get to the bottom of it. Did you ever find out what he meant?
13 years ago

Karuppiah Subramaniyam wrote:

Abimaran Kugathasan wrote:

Karuppiah Subramaniyam wrote:here the incremented value of k (2) only should get printed right?


Welcome to JavaRanch! Don't you go through the thread? printed value 1, as in the 1st code.



Ya I have gone through the thread. And I am also getting the same answer.But logically speaking after the multiplication , the value of k will get incremented by 1.Where that value will be?



Your assumption is right but what you have to notice here is..



if it were just:



even this

13 years ago

Rob Prime wrote:

Abimaran Kugathasan wrote:If a Sub class is serialized, it doesn't mean that its super class is also serialized. When a subclass is de - serialized, the no-argument Constructor of the super class will run.


A little more precise, the no-argument constructor of the first non-Serializable parent class will be called. If the super class is also Serializable then its constructor will not be called. In some cases that first parent is java.lang.Object.



Thanks for that clarification. Ok, so..as a follow up..

1. Is it true that if a class is serialized then its child classes is also subjected to serialization, unless there is a class which satisfies a -HAS-A- principle and that class is not serializable?
2. What happens if the first parents class is something other than Object and that parent class does not have a no-org constructor, say someone has defined a constructor with args ( which then would not allow for the default no arg constructor to exist unless you define it) ?
13 years ago

Campbell Ritchie wrote:

sai prashanth wrote: . . . chapter on serialization.. . . .

Please tell us where you got that from; you appear to have misunderstood the chapter, or there was something not clear there.



It was a random website on java, and to think of it I am guessing I had misunderstood the statements there.
13 years ago
Here is what I came to know after going through a chapter on serialization..

1. If a class is serializable then all subclasses can also be serialized.
2. If a class is serializable then its super class can also be serialized BUT there could be complications since the super class constructor will be invoked after the deserialization process.

Now to all those serialization experts if the above two sounds ok, could you tell me why my answer to this question and the one in the answer's section is different.

Question


MY ANSWER
Animal, Dog, Beagle and GSheperd - although Dog is the only class which actually implements serialization, super class Animal can be serialized and all the subclasses too can be serialized - and NOT Living class since it has no relation to the class Dog which implements serializable -- right?

CORRECT ANSWER
Dog and Beagle


I do not get why..any help is appreciated.

Thanks!
13 years ago
Ok, agreed. Thanks again for that clarification. One last thing that still makes me wonder is this, infact I have a separate post on this but I will ask the question again here:



Why is this? The method takes a short, and the '9' that I pass in also is under 32 bits then why should I cast it?
13 years ago
Thanks for the link. So that makes me curious about something else.

Lets say..'7' - which by itself is an int. Now when I do this:



..am I actually assigning the 32 bits to a 16 bit holder? Does it automatically do a chopping of the higher bits and just store the applicable 16 bits?
13 years ago
ok, so am doing this:

Please clarify

Thanks!
13 years ago
I was going through a webpage which has details about basic java primitives and I came across this statement:

Any expression involving an int and/or a primitive lower than int (byte, short) will always result in an int.



Does it mean byte + byte = int like 8 bits + 8 bits = 32 bits(which is not right!) ?

I even tried to a bit operation of ADD but that did not give me 32 bits. Could anyone throw some light in this statement?

Thanks!
13 years ago
Ok, so I have this silly doubt about casting and any clarification is appreciated.

I understand the byte, short , integer, long are 8,16,32,64 bits respectively.

so when I do this:



..the compiler does not complain even though '9' an integer literal of 32 bits is assigned to a 16 bit, is that right?

On the other hand


I dont understand why..

Thanks!
13 years ago
I think when we declare an enum the members should be the first thing that needs to be declared. Anything else might be causing the error.
13 years ago
See if this helps:

1. Instance Variables (A variable defined in a class and could be visible outside the scope of the class too- also called Class variable, can be static, final, private, public transient, volatile)
2. Local variables (When the scope of the variable is limited to a method and is not available outside, only possible access modifier is final)
13 years ago