Zaheer Ahmed

Greenhorn
+ Follow
since Feb 06, 2007
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 Zaheer Ahmed

Hi Guys!

I passed SCJP 5.0 with 84%. I prepared from the KnB book once and only once page by page. In the last week took the JQPlus and was able to only do the first 5 exams and the final exam. On the final exam I scored 72%.

For those studying for the exam, I recommend the KnB book and the JQPlus. Paul Anil was very kind enough to help when I was having some issues with setting up the JQPlus.

Thanks to KnB for such a great book. Thumbs up to Enthuware team and specially to Paul Anil. And last but not the least the ranchers here. It was very helpful and motivational in getting the certification.

Now SCWCD 5 is going down. Plan to follow the same path for it. KnB and Enthuware!
11 years ago
Hi Dev!

This has actually to do with the new features implemented as part of Java 1.5.

Var-args and auto-boxing are both new features introduced in Java 5.

As you are passing ints to the methods, they get confused to which method to call because both of these new features have the same priority.

If you had removed the method with long var-args and just had two longs in the method, and then called the method passing two ints, then int would be up-casted to long instead of being auto-boxed to Integer objects. This keeps Java backward compatible because if you have 1.4 and it ran fine and then you introduced auto-boxing or var-args methods, it will still keep running fine.

This is really creepy explanation, but try hard to understand. If you have KnB book that explains the concept in detail.
It compiles and runs fine for me but with a warning.

I am using JDK version 1.5 Update 14.
Hi Sidhar!

I tried this example and it ran fine but with this warning:



First thing is that you get this warning because compiler actually finds an equivalent of go(int[] d) in the parent class, but its not exactly the same that is taking an array as argument. But the compiler knows that the superclass's go method can handle the arrays if it gets so it compiles fine.

At runtime the methods that are actually executed are based upon the underlying object of the reference variable.

a.go runs the A class's go() method because a refers to an object which is of type A.
b.go runs the B class's go() method because b refers to an object which is of type B. Same is the case for c.

Hope this helps.


Secondly, explicit casting is required if you need to assign a bigger variable into smaller variable



Let me clarify this more... Casting is not required only when you are assigning a variable of 8 bits to another one that is 16 bits, but its also required when there is an expected loss of data.

When assigning a float to an int we have possible loss of precision due to the fact float sets aside memory for representing decimal places but int does not.

Hope this helps...
Hi Sarwan!

The only kind of variables that you can define within an interface are "public static final" by default if you even specify it or not.

The answer to your question is in interface we can only define constants but no instance variables. The constants make sense in the interface as long as you those constant do specify something about the interface itself.
But we can never have any instance variables or non-final and non-static and non-public variables in an interface declaration.

Hope this helps...


In the above example the trailing data after the point is truncated. That is:



The above code prints 100 in the output truncating any data after the decimal place. So you lost 0.001 in the integer variable that got truncated.


Secondly, explicit casting is required if you need to assign a bigger variable into smaller variable such in the example above, you need to do an explicit cast. Thats kind of assuring the compiler that I know what I am doing (Bert)...

Hope this helped!
[ June 20, 2008: Message edited by: Zaheer Ahmed ]
That I was guessing... Thanks Ernest for clarifying it up...
11 years ago
Hi All!

How can I declare the usigned primitive integers in Java???

I tried the following code:
<code>
public class TestUnsigned {
public static void main(String[] args) {
unsigned int a = 10;
System.out.println(a);
}
}
</code>

But the above code does not compile. It gives "Not a statement" error.

I remember doing something like this... I am not sure whether it was Java or C++. I know that Java is not C++ (Bert) and actually repeated that a couple of times but I am confused here...
11 years ago
Ubunutu is great. Ubuntu is the only linux distro on 1 CD per my experience and it is much more than its size.

I had installad v6.10 earlier. The only problem that I came up was with the ISA Server. My internet guy was using ISA server and the clients needed the ISA server to be able to browse the internet. But, there is no ISA Client for other OS than MS Windows.

Additionally, do check your hardware support with whatever version of linux you want to install.

To be honest, currently i am using my copies of Vista home edition that came shipped with my laptop and it works just great. Except that the fact it does not have RDC . Unless you do not have a money problem, I would suggest go with Windows, whatever the people say its still the easiest windows.

Cheers,
Zaheer
11 years ago
It would be great if any of the guys (Bert, Jesper, Ben, or marc) can verify this???

// Zaheer
Ragha, I thought you were having problems compiling it. But no problem.

Thanks Meena for clarifying it up for Ragha.

// Zaheer
For me it works fine.

Try the following code:

class Test {
static boolean doStuff() {
for (int x = 0; x < 3; x++) {
System.out.println("in for loop");
return true;
}
return true;
}
}

I think you are not including the code in a class.
You are right. C1 and C3 are the ones that have been assigned null values and ready for GC.

And if you look closely at the answers you will see that option C says 2. I guess the explanation is wrong and there is a typo in there.

Please have a look a look at the following link for a list of K&B errata.

https://coderanch.com/t/257589/java-programmer-SCJP/certification/SCJP-Errata-Updated

// Zaheer
Yes this is right. Take for instance, Integer and Long. These classes have different inheritance structure that is both inherit from Number class and Number class inherits from the Object class. So they are not in the same inheritace tree.

As far as the Number class is concerned, yes, Long, Integer etc can be automatically unboxed or widened to Number class because its the parent class of both Integer and Long classes.

So the following code works fine:
<code>
public class Ranch {

public static void main(String [] args)
{
Integer intNumber = new Integer(10);
Number numNumber = intNumber;
System.out.println(numNumber);
}
}</code>