harsh sahay

Greenhorn
+ Follow
since May 13, 2011
harsh likes ...
Mac Eclipse IDE Java
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
15
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by harsh sahay

hi all,

As i am planning to start with scwcd preparation soon, i would like to know which is the latest exam version and which book to refer for my preparation.

thanks..
Hi,

I cleared my ocpjp 6 exam with 95% . Thanks to everyone who helped me with my doubts. javaranch rocks
11 years ago
Hi all,

I have been studying for the ocpjp 6 exam since 1 month now. I tried to evaluate myself recently by giving first two mock tests from enthuware and diagnostic exam from examlab and my results are as follows:-
Enthuware:-

Test1: 70%pass
Test2:70%pass

ExamLab Diagnostic test:- (63% fail) [could have passed since i did some very silly mistakes in 2-3 questions].

I am planning to give real exam in next 15-20 days during which i will be giving a lot of mock exams.
I request the ranchers who have already cleared the certification exam or preparing for it to guide me if my preparation is going ok or not as i am just able to reach the passing marks.

Also need your feedback on whizlabs exams as i am planning to purchase that too.
Thanks..

Java Language Specification wrote:5.2 Assignment Conversion
Assignment conversion occurs when the value of an expression is assigned (§15.26) to a variable: the type of the expression must be converted to the type of the variable. Assignment contexts allow the use of one of the following:

an identity conversion (§5.1.1)
a widening primitive conversion (§5.1.2)
a widening reference conversion (§5.1.5)
a boxing conversion (§5.1.7) optionally followed by a widening reference conversion
an unboxing conversion (§5.1.8) optionally followed by a widening primitive conversion.

If, after the conversions listed above have been applied, the resulting type is a raw type (§4.8), unchecked conversion (§5.1.9) may then be applied. It is a compile time error if the chain of conversions contains two parameterized types that are not not in the subtype relation.

Discussion
An example of such an illegal chain would be:

Integer, Comparable<Integer>, Comparable, Comparable<String>

The first three elements of the chain are related by widening reference conversion, while the last entry is derived from its predecessor by unchecked conversion. However, this dis not a valid assignment conversion, because the chain contains two parameterized types, Comparable<Integer> and Comparable<String>, that are not subtypes.

In addition, if the expression is a constant expression (§15.28) of type byte, short, char or int :

A narrowing primitive conversion may be used if the type of the variable is byte, short, or char, and the value of the constant expression is representable in the type of the variable.
A narrowing primitive conversion followed by a boxing conversion may be used if the type of the variable is :
Byte and the value of the constant expression is representable in the type byte.
Short and the value of the constant expression is representable in the type short.
Character and the value of the constant expression is representable in the type char.

If the type of the expression cannot be converted to the type of the variable by a conversion permitted in an assignment context, then a compile-time error occurs.

If the type of the variable is float or double, then value set conversion is applied to the value v that is the results of the type conversion:

If v is of type float and is an element of the float-extended-exponent value set, then the implementation must map v to the nearest element of the float value set. This conversion may result in overflow or underflow.
If v is of type double and is an element of the double-extended-exponent value set, then the implementation must map v to the nearest element of the double value set. This conversion may result in overflow or underflow.

If the type of an expression can be converted to the type of a variable by assignment conversion, we say the expression (or its value) is assignable to the variable or, equivalently, that the type of the expression is assignment compatible with the type of the variable.

If, after the type conversions above have been applied, the resulting value is an object which is not an instance of a subclass or subinterface of the erasure of the type of the variable, then a ClassCastException is thrown.


Thanks Henry, this was really informative.

Hi all,
My doubt with this code is why auto-boxing with Long d=4 is failing as compared to Byte,Short,and Integer where it is a success? I don't understand why we need to explicitly specify the value as 4L for it to work. Since 4 is an int type shouldn't it be boxed automatically to Long? Please clarify.

Instance blocks can give value to instance variables;
Instance blocks can use instance variables, if they are defined before the instance block in the code.


Thanks for the above code Alex . After executing and debugging the above code and other examples, i think that the instance variables and initialization blocks are always executed before the constructor body runs(and not after executing the constructor as i was thinking it to be). So this doubt is now cleared.

I have also tried to execute the above two quoted notes:-
1.)The first one i tried.
2.)For the second one here is the code snippet:-


My Doubt here is:-

Shouldn't the compilation error occur at line Line 1 also?

I also noticed that the scope of variables defined and initialized in an initialization block is local to that block only(as can be expected from any other normal method).










Pinki Roy wrote:
I don't understand why the out put is
Hello 2
Hello
Hello
hello 1

As per my understanding it should have been
Hello 2
Hello
hello 1

Someone please clarify please.



Hi...as i understand an object is created when its constructor has completely executed along with a copy of its instance variable created. when control returns to InitDemo constructor from class A, only after the complete execution of the constructor will InitDemo object be formed and instance variable ob will be initialized to ob=new A() (if you go like this the output should be Hello2 hello hello1 hello);

Could someone please explain why A ob=new A() statement is getting executed before the completion of the InitDemo constructor??(as the output shows Hello2 hello hello hello1) which in turn means that InitDemo instance variable ob is getting initialized before the actual formation of the InitDemo Object as the constructor would not have completely executed by then??
confused between the last two outputs in bold...

hi...I tried to create a simple MyOuter class which holds an inner class called MyInner. As expected, two .class files where created after compilation as shown below:-

Can Someone please explain me as to why no constructor was created for MyOuter class as the compiler is supposed to insert it by default.
Secondly, what is the meaning of MyOuter paramMyOuter argument in MyOuter$MyInner constructor and how it helps.Please explain me the complete flow.
Thanks>>
12 years ago
hi...I tried to create a simple MyOuter class which holds an inner class called MyInner. As expected, two .class files where created after compilation as shown below:-
public class MyOuter
{
class MyInner
{
MyInner()
{
}
}
}

class MyOuter$MyInner
{
MyOuter$MyInner(MyOuter paramMyOuter)
{
}
}

Can Someone please explain me as to why no constructor was created for MyOuter class as the compiler is supposed to insert it by default.
Secondly, what is the meaning of MyOuter paramMyOuter argument in MyOuter$MyInner constructor and how it helps.Please explain me the complete flow.
Thanks>>
12 years ago