k duffy

Greenhorn
+ Follow
since Aug 29, 2004
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 k duffy

Hello:

I am working with the Bridge2Java API from the IBM AlphaWorks.
Bridge2Java allows java to communicate with ActiveX objects under Windows.
I need to work with the Bloomberg ActiveX object. The object allows you to extact data from the Bloomberg market data service.

Refering to the code below. Is there a smarter way to determine if the object returned from the call to blpData.get_BLPSubscribe is an object and what are its dimensions?

Many thanks for your help

KD



import blpdata.*;

public class QuickblpData {


public static void main(java.lang.String[] args) {

blpdata.BlpData blpData;

String bbTicker;
String[] aFields;
String reqField, tmpString ;
Object overrideFields;
Object overrides;
String[] aResults;
Object monitor;
Class objType;
Object[] aObj, aObjd2 ;

try {
//System.loadLibrary("bridge2java");
com.ibm.bridge2java.OleEnvironment.Initialize();
System.out.println("hello");

blpData = new blpdata.BlpData();

bbTicker = "RHAT.US Equity";
int cookie = 1;
aFields = new String[] {"Name", "Company_Tel_Number"};
reqField = "Name";
overrideFields = null;
overrides = null;
aResults = new String[] { " Name " } ; //new Object();
//monitor = new Object();
blpData.set_SubscriptionMode( _FIRE_EVENT_TYPES.ByRequest );
//blpData.Subscribe( bbTicker, cookie , reqField, overrideFields, overrides, aResults );
Object objResults = blpData.get_BLPSubscribe( bbTicker, reqField );
System.out.println( objResults );

objType = objResults.getClass();
System.out.println( objType.getName() );

if ( objResults instanceof Object ) {
if ( objResults instanceof Object[] ) {
System.out.println( "it is Object[]" );
aObj = (Object[]) objResults ;
System.out.println( aObj.length );
if (aObj[0] instanceof Object[] ) {
System.out.println( "aObh[0] is Object[]" );
aObjd2 = (Object[]) aObj[0] ;
System.out.println( aObjd2.length );
tmpString = (String) aObjd2[0];
System.out.println( tmpString );

}

}

}



} //try
catch (com.ibm.bridge2java.ComException e)
{
System.out.println( "COM Exception:" );
System.out.println( Long.toHexString((e.getHResult())) );
System.out.println( e.getMessage() );
}
catch (Exception e)
{
System.err.println( e );
System.out.println("message: " + e.getMessage());
}

}
}
19 years ago
Greeting Guys and Gals:

Passed SCJP(310-035)today with an 83%.
Used the Sierra and Bates book as well as the Java Programming Language book. I found the combination perfect.

Three Step process.

1) Read the books
2) Do the samples and understand the samples
3) Do practice exams (Marcus Green & The Java Ranch)

Got me where I wanted to be.

Thanks

Java Ranch
19 years ago
D is wrong.

In "The Java Programming Language Third Edition" pg 44 it says "Constructors are invoked after the instance variable of a newly created object of the class have been assigned their default values and after their explicit initializers are executed"..
Could you suggest how to improve the code?

Please kd
I accept the assertion that when it comes to threads very little is guaranteed.

But I believe that an assumption is being made in the following code.
From Sierra amd Bates pg 529.

This code assumes that ThreadA will get a lock on Thread "b" before "b" can start its loop. Is this a safe way of doing things? Yes I know it is only an example in a book.

Because if the loop in "b" got started before ThreadA got the lock then the following would happen:
ThreadA would be blocked at synchronized(b)
the wait in ThreadA would never receive the notify

Am I getting this right?

Regards

kd



public class ThreadA {
public static void main(String [] args ){
ThreadB b = new ThreadB();
b.start();
synchronized(b) {
System.out.println("ThreadA has the lock");
try {
System.out.println("Waiting for b to complete...");
b.wait();
}
catch (InterruptedException iEx) {}
}
System.out.println("Total is: " + b.total );

}

}


class ThreadB extends Thread {
int total;

public void run() {
synchronized(this) {
System.out.println("ThreadB has the lock");
for(int i = 0; i<100; i++) {
total += i;
}
notify();
}
}

}
Tom, thanks for your kind reply.

I think Java Programming Language 3rd edition pg. 76 answers the question.

"a reference to a field always refers to the field declared in the class in which the method is declared, or else an inherited field if there is no declaration in that class"

Keep that in mind and ALL the code behaves as expected.

Another point of confusion, for me, is that there are two variables named zero2Sixty. The one in BMW is hiding the one in Car. I will try using a constructor in BMW and I bet things will work smother.

thanks again.

kd
This to me is becoming more confusing.
I hope that someone will chime in with an authoritative explanation.

The object I have created in the code is of type BMW.

BMW extends Car therefore it "has" the methods setOnPetal() and getZero2Sixty().

The call bmer.stepOnPetal() proves that BMW has inherited the stepOnPetal() method because it executes the overridden goFast() method and zero2Sixty equals 8.

The call bmer.goFast()executes the overridden goFast() method, works as expected.


aCar.stepOnPetal() should execute the inherited stepOnPetal on BMW and it does. Because the actual class of the object rather than the reference variable type determines the method executed.

aCar.goFast() works as I expect.

bmer.zero2Sixty() return the instance variable BMW.zero2Sixty.

The next to calls aCar.getZero2Sixty returns 12. Why? The class of the object is of type BMW. I would it to exected the inherited method on BMW and return 8. Same is true for bmer.getZero2Sixty(). Why does it return 12?

Thank you for your attention to this matter.

best regards.

kd
I have my doubts about that.
The subclass inherits the method otherwise how would the call to
bmer.stepOn() Petal work?

As per Sierra & Bates's book (pg 70) "if a subclass inherits a member, it's exactly as if the subclass actually declared the member itself. In other words, if a subclass inherits a member, the subclass has the member."

Still confused.

kd
Greetings Java Ranch:

I wrote up a couple of very simple classes to test my understanding of Accessing Inherited Members. In the "Java Programming Language 3rd Edition" page 75 it says "When you invoke a method through an object reference, the actual class of the object governs which implementation is used. When you access a field the declared type of the reference is used."

This is what I my trying to test and I managed to confuse myself and a co-worker very well. Please find my classes below and my questions futher below.


BMW goes fast. Zero to Sixty in: 8
BMW goes fast. Zero to Sixty in: 8
BMW goes fast. Zero to Sixty in: 8
BMW goes fast. Zero to Sixty in: 8

bmer.zero2Sixty:8
aCar.zero2Sixty:12
bmer.zero2Sixty:12


I do not understand why the last two methods return 12
What is the difference between the call to stepOnPetal and getZero2Sixty()?

Thanks in Advance.

Regards

kd

([c0de][/c0de] tags added)
[ September 03, 2004: Message edited by: Barry Gaunt ]
ok yes, now I understand.
The mention of interfaces in the question threw me off.
I wonder why that was tossed in there.

Thanks for your kind feedback.

kd
Sun Objective 1.2

the following question is from Sun Certified Programmer & Developer for Java 2
by Sierra & Bates

Which of the following are legal declarations for nonnested classes and interfaces? (Choose two)
a. final abstract class Test{}
b. public static interface Test{}
c. final public class Test{}
d. protected abstract class Test{}
e. protected interface Test{}
f. abstract public class Test{}


lets see
a. final and abstract are opposites so wrong
b. interface can not be declared static
c. OK
d. protected can only be used on members
e. protected can only be used on members
f. OK

Book says C & F
but look at C the question said for interfaces, an
interface can not be final.

confused.

thanks in advance for your help.

kd