Manoj Macwan

Greenhorn
+ Follow
since Aug 03, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Manoj Macwan

I got this now. In K&B book they have emphasised on hashCode() method (page 563) for HashSet but missed to specify that object should also override equals() method if you want to explicitly check for duplicates. I need to override equals() method as well in my code and then HashSet will not add new Dog object if dogName is same as previously added object.
Hi,

I have written below sample code to understand HashSet uniqueness. I have overridden hashCode() method for one custom class Dog and then tried to create HashSet of "Dog" objects. As per characteristics of HashSet duplicates shouldn’t be allowed that is being checked based on hashCode() value of the object.
In overridden hashCode() method, I have assigned hashCode() to object as one of the string variable hashCode().
The expected result of below program should be 4 Dog objects in HashSet but there are 5 objects and size of HashSet is shown as 5.

Any reason why this behavior? Is there any error in implementation?

Hi All,

I have one small query regarding Abstract and Static.

Why both abstract and static class is not possible?

I know the reason for final and static, why the can't go hand in hand.

but,don't know such reason for static and abstract.

The same query I have for abstract and static methods also.

Please help me in resolving this query.
Thanks in Advance.

Manoj
The answer of this question is 8 2.

As said in the earlier post - If a for isn't followed by braces, it loops the statement that follows the for.
In this case "If" is the looped statement.

Here we are looping 5 times and each time values of X and Y are:
x y
0 - 1 1
1 - 2 2
2 - 4 2 (As the first expr is evaluated as TRUE, second expr won't executed)
3 - 6 2 (As the first expr is evaluated as TRUE, second expr won't executed)
4 - 8 2 (As the first expr is evaluated as TRUE, second expr won't executed)
Hi All,
I have some doubts regarding the below mentioned question.



The answer of above question is given as, it will print:
Parent's method2()
Parent's method1()
In the explanation, given that if we change the access modifier for method1() in Parent class as Public, it will print:
Parent's method2()
Child's method1()

I have tested the code with both mentioned scenario, and it is giving desire output.

Please help me in understanding both above mentioned scenario.
Hi Ranjan,

Sun has one section called certManager for certification related queries.

You can enter your query over there.

The link is: https://i7lp.integral7.com/durango/do/login?ownername=sun&channel=sun&basechannel=prometric

But for, this also you require the Prometric Testing ID number.
Congratulations Prafulla!!!
17 years ago
Hi All,

I have cleared the SCJP 5.0 exam with 83%.

It was good experience, but looks scary when I had given the Master exams from K&B Book.

Thanks to Java Ranch Forum, I have cleared my doubts, and done well in the exam.

Thanks for support of Java Rancher.
17 years ago

Originally posted by madhu v pe:
Hi

there is a question on generics in javabeat
Code given as below


Answer is a,b,c & f
how come b is valid? can anyone provide some source to clarify this

Thanks

Hi,

I had given the K&B Master exam and score poorly in that exam.

I got only 43 questions right out of 72 questions.

What should I do for the better preparation?

I am planning to give SCJP exam soon. Please provide me some inputs.

At What level the Master exam of K&B is comparing to the Actual Exam?

Please provide me some help.
Hi sukhavasi,

Which compiler are you using for this java code?

In the JDK 1.5, they have introduce the new feature called AutoBoxing and UnBoxing.
According to this feature, whenever require any primitive will be converted to Wrapper object or vice versa.

So, in your case also b3 will be converted to primitive value.

If you are preparing for SCJP 1.4 then, you don't require to know about this feature, otherwise you must know.
Hi Lucky,

It seems that Stats is the user defined class only.

The Java SE API don't have any Stats class.

and, it also look like the example is not complete, as the average() method is missing in the Stats class.

Please provide some more information for this example.
Thanks Raghavan,
Still new to this forum, and learning a lot from this forum.
I have read in the K&B book that:

bytes, shorts, ints, booleans & chars exhibit immutability upto this range :
Boolean
Byte
Character from \u0000 to \u007f (7f is 127 in decimal)
Short and Integer from -128 to 127

I have some doubt regarding same:
Integer i1 = 10;
Integer i2 = 10;
Integer i3 = new Integer(10);
Integer i4 = new Integer(10);

System.out.println("i1 == i2: " + (i1== i2) + " i3 == i4: " + (i3== i4));

It gives the o/p as: i1 == i2: true i3 == i4: false

Is it like that while creating the new Object using new keyword, the above mentioned rule is not applies.

Please help me to understand this issue.

Thanks in Advance.
Here the rule is that before doing anything in the constructor, the constructor of super class will be called. The other rule is that after all the constructor call over, the instance variable initialization happens.
Here I am giving you the sequence.

1.First new B(), this calls the B class constructor, this calls the super(2) first.
2.This super(2) assign the variable val as 2. This is A class val variable.
3.Now the instance variable of B class assignment happens, this assign the val variable of B class with 1
4.At this point, the B class has two val variable access, one with class A value(2) and other with class B value(1).
5.After this on the B class object we are calling the nested class C class object.
6.In the constructor of C class we are calling first super(4), as the super class is A, the val variable for A is again assigned to value 4.The B class val is still 1 and B class�s A class val value is still 2 and still accessible.
7.Finally we assign the val variable in C class as 3
8.So first we are printing the B class variable 1
9.Then C class local variable 3
10.Then we have used the super which is A class variable for C, that is 4.
11.Add one other statement
a.System.out.println(B.super.val);

It will give that hidden 2 value for B class�s A class val variable.