Unconfigured Ad Widget

Collapse

Announcement

Collapse
No announcement yet.

Two Doubts in AIR //

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Guest.Visitor
    replied
    Thank you Tom. Your answers are as awesome as your Book!! :-)

    Leave a comment:


  • Guest's Avatar
    Guest replied
    Hi David,

    I would be glad to help clarify your doubts.

    1) For the getBytes Method of the String class, you will be retrieving the state of the object that is being referenced. So, the value that you are looking for is saved within the object and you are asking to get it out. Let me refer to the hello world example:


    D airString S like(jString)
    D displayBytes S 52A
    /free
    JNIEnv_p = getJNIEnv();
    airString = new_String('Hello World');
    displayBytes = String_getBytes(airString);
    DSPLY displayBytes;
    freeLocalRef(airString);
    *inlr = *ON;
    /end-free


    airString is a reference to the new String object that is created. The call to new_string will create the new String object and it will initialize it's internal value to be what is passed in as the parameter, which in this case is 'Hello World'. So, now you have a "pointer" to a memory location that has the structure of a String class. You don't know all of the internal mechanics of what is inside the String class, but you don't need to care. All you know is that the 'Hello World' String is contained inside, along with some other stuff.

    The String_getBytes prototype has a reference to the 'java.lang.String' class, so it knows all of the internal components of the class and what the interface looks like to the class. the next parameter of the extproc prototype :'getBytes' tells it what method you want to call from the String class. This method 'getBytes' knows that you are looking to get that string of bytes back out. So, all you need to do is pass in the instance of the class that you are working with and it will pull out the bytes that were passed in when the object was created. So, String_getBytes(airString) will call the getBytes method on the instance of the class that is passed in 'airString'

    To put it another way, suppose you have a lot of active users on your system and you know they all have job logs and all of their job logs will look differently. You know that you could call the DSPJOBLOG on each of the jobs, it uses the exact same command; just like getBytes is for String, so each job has it's own instance. All you have to do is specify which job name, user and job number to identify the instance that you are interested in and it will give you back the job log, which is like the state of the instance of the object (Passing the String Object). I hope that wasn't confusing, I'm trying to map over the concepts for you.

    2) Yes, the service program has a main procedure. I do not believe that will supported in the future, which is a recent modification. But, there is a reason why I did that. I try to keep all of my procedures as encapsulated as possible without referencing global variables in the procedures of the service program unless neccessary. So, my intention was to have all of the global variable initialization done within the main method to use it for that specific purpose. It could just as easily be made into a subprocedure that could be called from the main program.

    To call it, I put a prototype in SPAIRJAVA

    D JavaServiceProgram...
    D PR extProc('SVAIRJAVA')

    And in your main program, you could call it like this:

    CallP JavaServiceProgram();

    This would call your main procedure.

    I usually call the main procedure of the service program right at the beginning of the main program that will be using it, so that everything is initialized and ready to go. If you do not explicitly call it from you main program, then it wouldn't be executed.

    So, besides the Java classpath and reusing existing JVMs, when else would I use it? Typically it would be for overriding and opening files. I frequently create main procedures in service programs when I have files defined in the F specs that I would be using throughout the service program. For multi member physical files I may not want to override and open and close the file with each call to a procedure, so I would override and open it once in the call to the main procedure and reuse the file in the procedures. But, you could also just create a subprocedure to do this as well, this is just one technique that I use and could easily be eliminated.

    I hope this answers your questions and that you enjoyed the video tour today.

    Thanks for your questions!
    Tom

    Leave a comment:


  • Guest.Visitor
    started a topic Two Doubts in AIR //

    Two Doubts in AIR //

    Hi Tom,

    Pardon my ignorance; Could you please clarify my below doubts.
    1. The Hello World program uses a getBytes procedure which takes java string object as input and returns an array of
    bytes; however the prototype for getBytes doesnt have any parameter attached to its prototyp in spairjava?? If we are passing a parameter it must be in the prototype right?

    code .....................................
    ==========================
    ..from AIR05_01
    displayBytes = String_getBytes(airString);

    ...from SPAIRJAVA

    D************************************************* *********************
    D String_getBytes...
    D PR 65535A varying
    D extproc(*JAVA:
    D 'java.lang.String':
    D 'getBytes')
    ================================================== =============

    2. SVAIRJAVA has a main procedure ( I thought service programs wont have main procedures but only Subprocedures ) . When and How we are going to use it ? (I mean its clear to me that we are going to set the classpath using it and start the jvm but from where we will call this main procedure)?
    My doubt is the code shown on page 114 is not inside a subprocedure body, then if we put it into a service program its never going to be executed right?
    Could you please clarify...

    Thanks in advance, many congrats for this revolutionary book!!!!!

    Regards,
    David
Working...
X