Ashish Hareet

Ranch Hand
+ Follow
since Jul 14, 2001
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 Ashish Hareet

Does anyone know, how I can record sounds in the au format for Java applets ? I've got Garage Band, can I use it to record in au format ? Any freeware utilities I can use.

Or do applets support any other format besides au ?

Thanks
Ashish H
15 years ago
N Pats,

Consider this from your code

long long_int_var = orig_int_var >> 33;

orig_init_var is of type int & it's value is 1, so it's binary representation is as follows

00000000 00000000 00000000 00000010

Shift this right by 33 you end up with zero. Do note that the resut of the shift expression is a int cause orig_int_var is an int, no long was involved in the shift operation.

Explanation for your third question is same as above.

Try orig_int_var >> 2 for kicks.

Try binary shift operations - Binary Shift Applet
Article - Binary Shift Operations

HTH
Ashish Hareet

Edit per Punit's comments, Ooops!!
Vipin,

Unfortunately, I do not have any mock exam questions for SCWCD at this time. Let me check with a couple of folks I know, if they'd be willing to help set up mock exams for SCWCD. Will update this thread, if I manage to get some.

Thanks
Ashish Hareet
15 years ago

Originally posted by Lakuma Yalamanchili:

So I was right when I thought the following is wrong??

[ October 03, 2008: Message edited by: Lakuma Yalamanchili ]



I'll disagree, my statement was given in the context of what can be added to the list & not the type of the list in which case it is correct(except that Number should also be included). Denis' statement was from Sun's website & refer's to the type of the list itself, not the type of objects that can be added to the list. Note the distinction in the context of the statements.

Here's some code to see what can/cannot be added to generic lists & how the types of the list themselves affect their usage.



Commented lines cause compile-time errors, refer to Sun's link previously provided to understand why.

HTH
Ashish Hareet
[ October 03, 2008: Message edited by: Ashish Hareet ]
I answered a similar question on one of our forums, see if it helps

Generics & super

Also check out Sun's resource on generics - http://java.sun.com/docs/books/tutorial/java/generics/index.html

HTH
Ashish Hareet
Preetha,

Lets see how "x.method();" will be evaluated. At compile time we'll first need to determine what class or interface to search for "method()".

Per JLS 15.12.1 - If the form is Primary.NonWildTypeArgumentsopt Identifier, then the name of the method is the Identifier. Let T be the type of the Primary expression; then the class or interface to be searched is T.

Per this, the type of "x" is "ax" & we conclude that we can call "method()" from ax & "x.method()" gets compiled.

Now at runtime, we may think that since Java uses late-binding we'll have to resolve "method()" to use it's runtime type. But that is not the case. Per JLS 15.12.4.1 - If the invocation mode is static, then there is no target reference. The expression Primary is evaluated, but the result is then discarded.

What this means in our case of "x.method()" is that x is evaluated but the result of that evaluation is not used, instead we use the type of "x"

Now lets see how "x1.i" will be evaluated. At compile-time, per JLS 15.12.1(see above), we can only search "ax" for i. Compile fails right away since ax does not have a member i.


Further lets consider what happens if "method()" is an instance method(not static). With "x.method()", again per JLS 15.12.1, we conclude that the class to be searched is "ax".

And now at runtime, something different happens since "method()" is an instance method. Per JLS 15.12.4.1 - the expression Primary is evaluated and the result is used as the target reference.

What that means is we evaluate x which results in a target reference of type "ax" & the method from "ax is called". On the other hand, when we evaluate x1, it results in a target reference of type "bx" & that is why we end up with the method from bx being called.


For reference pleas read the following -
* JLS 15.12.1
* JLS 15.12.4
[ October 03, 2008: Message edited by: Ashish Hareet ]
Thanks Ankit, it should've been 4, I'll edit my post
Hi Preetha,

First, static methods are invoked without reference to any particular object. What matters is the class type being used. In fact if "x" had been inititlazed to null i.e. "ax x = null", you would still get the output as mentioned.

Now, for "x1.i", i is a member of bx & the type of x1 is ax, although under the hood it is bx. ax has no knowledge of what members are available in the subclasses & hence simply putting x1.i will yield a compile-time error. You will have to explicitly cast x1 to bx i.e. "((bx)x1).i".

HTH
Ashish Hareet
Guys,

I got the impression from atleast one post in here that the increment from a++ never gets writtent back to a, so I'm adding my comments.

Take note of the following two points from the JLS & Java's operator precedence
* 15.7.1 Evaluate Left-Hand Operand First - The left-hand operand of a binary operator appears to be fully evaluated before any part of the right-hand operand is evaluated.
* 15.14.2 Postfix Increment Operator ++ - The value of the postfix increment expression is the value of the variable before the new value is stored
* Operator precedence - http://www.irixtech.com/java/tutorials/java-operator-precedence

So, for the example, from the original post "a = a--", a-- puts 5 as the value in the expression & makes the final value of a as 4 per JLS 15.14.2. And now, since assignment will always happen in the end the final value of a ends up being 5 although a was 4 after a--.

Another example to consider is "a = a++ + a". In this case, per JLS 15.7.1 left-hand operands need to be fully evaluated before any part of the right-hand can be evaluated. So we evaluate a++, we get 5 in the expression & a has the value 6. Now we evaluate the right-hand operand which is simply substituting the value of a i.e. 6. Finally, the assignment is performed & a ends up being 11.

Take a minute to have a look at the said JLS articles, the JLS may seem geeky at times but all the answers are there.
JLS 15.7.1
JLS 15.14.2


HTH
Ashish Hareet
[ October 03, 2008: Message edited by: Ashish Hareet ]
Arijit,

Originally posted by Arijit Daripa:
You have taken a great step forward to helping the aspirants of SCJP and you have provided a lot of very good questions. That's why I am always going admire you. People like you can help, a lot, the SCJP and Other certification aspirants. Keep it up.


Appreciate the motivating thoughts.



Originally posted by Arijit Daripa:
But errors can harm the thoughts of the aspirants. So be carefull.


My thoughts exactly. Thats the reason end user feedback is really important & I always appreciate your directed posts over here. It may seem that you've been outspoken in the past, but if my site doesn't give good content then the user has all rights to be get back to me in the manner they see fit. I take it as an opportunity to make my site better.

Originally posted by Arijit Daripa:
How shall I send you private messeges?


Couple of options -
* You can use the private message feature here on javaranch. You'll find the message icon with little men in the posts. Click the one associated with my post.
* You can use the contact feature on irixtech - http://www.irixtech.com/contact
* You can also email me directly with a relevant subject line - gnashes30 at yahoo dot com

As always, thanks for your valuable thoughts & feedback.

Ashish Hareet
15 years ago
Yes Arijit, I'm running this site all by myself. I simply put up the questions I've received cause I don't have enough time to go through them all. I depend upon user's like yourself to provide me feedback. If anything, later users can benefit from the errors you've detected.

With my site I'm trying to make a self-sustainable free medium for the community & with everything free, only the community can help make this a truly free & valuable resource

Thanks for asking
Ashish Hareet
15 years ago
Arijit,

Thanks for pointing this out. I'll rephrase the question to be more specific, maybe add a code sample to it.

Let me know if you find more items like these.

Ashish Hareet
15 years ago