Andy James

Ranch Hand
+ Follow
since Aug 22, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Andy James

Hi Joanne,

Thanks very much for your reply. I digged into 'the Java Language Specification' and 'The Java Virtual Machine Specification' and found the following interesting information:

Java Language Machine Specification

2.4 Reference Types and Values

A reference value may also be the special null reference, a reference to no object, which will be denoted here by null. The null reference initially has no run-time type, but may be cast to any type. The default value of a reference type is null.

The Java Virtual Machine specification does not mandate a concrete value
encoding null.

Similarly, while null might appear to be a keyword, it is technically the null
literal (§3.10.7).

A literal is the source code representation of a value of a primitive type (§4.2), the String type (§4.3.3), or the null type (§4.1).

3.10.7 The Null Literal
The null type has one value, the null reference, represented by the null literal null, which is formed from ASCII characters.
NullLiteral:
null
A null literal is always of the null type (§4.1).


4.1
In practice, the programmer can ignore the null type and just pretend that null is merely a special literal that can be of any reference type.



4.7.4 The StackMapTable Attribute
• The Null_variable_info type indicates that location contains the verification type null.
Null_variable_info {
u1 tag = ITEM_Null; /* 5 */
}



So it seems that its upto a particular JVM implementation to decide what value to use to denote a null literal. Thanks again!

Andy
Okay. So, I get that null is a value.

What happens when multiple object references are assigned null? Does null has an address? Cause we know that reference variables store addresses of the objects that they refer to.



Thanks.

Andy
Thanks for your reply, Matthew. I understand what you have written. What I fail to understand is - how does it affect the java compiler. Isn't assigning null as good as not assigning a value. How does it make a difference to the compiler? The compiler doesn't get a value for any of the variables - s1 and s2.
Why does the Java compiler and Runtime environment treat the local variables s1 and s2 differently? None of s1 and s2 is assigned a String object.



Andy
Thanks for all the replies. It is getting interesting. A quick question:

Does the HAS-A relationship also applies to the base classes? For example, if class A extends Base and B HAS-A A, does it also imply that class B HAS-A Base?


cheers,
Andy
Thanks, Kevin.

So can I infer that if class B is accessible in class A, the following is the only way to implement relationship "B HAS-A A"?



Class B can't define variable of class A as method parameter, local variable or static variable to implement relation "B HAS-A A". RIght?

Cheers,
Andy
If class A shares HAS-A relationship with class B, is definition of instance variables the only way that these classes can share HAS-A relationship:



or can class B define variables of class A as local variable to implement HAS-A relationship?



Cheers,
Andy
Congratulations to you!

Did you get any questions on CLASSPATH?

Cheers,
Andy
12 years ago
Hi all,

Why the following code doesn't compile?



whereas the following compiles successfully?



In both the cases, code int a = 10; will never execute, that is, is unreachable. Then why compilation is unsuccessful only for the while statement?

cheers
A
Hi all,

Can classes and interfaces share HAS-A relationship? For the following code, is it correct to say that MyClass HAS-A MyInterface and MyInterface HAS-A MyClass?



cheers
A
I am preparing for the OCP Java7 certification. Can someone please explain what is the following exam objective referring to?

"Apply object composition principles"

cheers
A
Can anyone please answer to this query?

Andy
I am preparing for the OCP Java7 certification. I am unable to understand the following exam objective:

"Apply object composition principles"

Can anyone please help explain this objective. Are there multiple composition principles or just one - define a variable of type A in type B, if you want to use the functionality of A in B, rather than maling type B inherit type A?

cheers
Andy
Hi!

The OCP Java & exam objective states - "Design and create objects using a factory, and use factories from the API".

Does this pattern only include the "Factory Method" or "Simple Factory" pattern which includes creation of a factory method that return the exact subclass object based on the arguments passed to the method? Example -

Or it also includes Abstract Factory Pattern?

Cheers,
Andy