Warning: Undefined array key "birthday_search" in phar:///home/duptmor/public_html/prod.mcpressonline.com/forum/core/vb/vb.phar/api/user.php on line 173

Warning: Undefined array key "joindate" in phar:///home/duptmor/public_html/prod.mcpressonline.com/forum/core/vb/vb.phar/api/user.php on line 190

Warning: Undefined array key "posts" in phar:///home/duptmor/public_html/prod.mcpressonline.com/forum/core/vb/vb.phar/api/user.php on line 191

Warning: Undefined array key "posts" in phar:///home/duptmor/public_html/prod.mcpressonline.com/forum/core/vb/vb.phar/api/user.php on line 197

Warning: Undefined array key "userid" in phar:///home/duptmor/public_html/prod.mcpressonline.com/forum/core/vb/vb.phar/api/user.php on line 6509

Warning: Undefined array key "userid" in phar:///home/duptmor/public_html/prod.mcpressonline.com/forum/core/vb/vb.phar/api/user.php on line 212

Warning: Undefined array key "privacy_options" in phar:///home/duptmor/public_html/prod.mcpressonline.com/forum/core/vb/vb.phar/api/user.php on line 251

Warning: Undefined array key "userid" in phar:///home/duptmor/public_html/prod.mcpressonline.com/forum/core/vb/vb.phar/library/user.php on line 4998

Warning: Undefined array key "userid" in phar:///home/duptmor/public_html/prod.mcpressonline.com/forum/core/vb/vb.phar/library/user.php on line 1585

Warning: Undefined array key "lastactivity" in phar:///home/duptmor/public_html/prod.mcpressonline.com/forum/core/vb/vb.phar/library/user.php on line 1601

Warning: Trying to access array offset on value of type bool in /home/duptmor/public_html/prod.mcpressonline.com/forum/core/vb5/route/profile.php on line 74
Using assignment operator with java objects - MC Press Online Forums

Unconfigured Ad Widget

Collapse

Announcement

Collapse
No announcement yet.

Using assignment operator with java objects

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

  • Using assignment operator with java objects

    When you use an assignment operator with two java objects...what is happening?

    Code:
    D #lcobject1    s                   like(HSSFCellStyle)
    D #lcobject2     s                   like(HSSFCellStyle)
    ..
    /free
    #lcobject2 = #lcobject1;
    /end-free
    Does object1's contents get copied to object 2 or does object2 start taking up the same memory space as object1?

  • #2
    I think it's the latter based on what I just found in the RPGIV Manual....

    A Java object is viewed as an object reference in RPG. This object reference is an integer value, which behaves like a pointer. Normal object references are positive values, assigned in increasing order from 1. Global references, which can be created using JNI function NewGlobalRef , are negative values. These values are assigned in increasing order from the smallest negative number (-2147483647). Normally, these values are not visible within the RPG code.

    So now the question is...how do I copy the contents of one java object to another without destroying and recreating the object each time?
    Last edited by Guest; 11-12-2010, 11:49 AM.

    Comment


    • #3
      each Java class inherits from Object and has a method clone() and a well designed Java class should overwrite clone() with appropriate functionality.
      BTW: I would not recommend to use this embedded Java in RPG stuff, its slow, instable, unreadable and doesn't scale well. RPG and Java should be decoupled by running a prestarted JVM and asynchronous communication between RPG and Java. I have written Open Source AppServer4RPG which is extendable by an EventHandler Concept; the capabilities of AppServer4RPG could be tested by the Open Source Application ArdGate (deployed together with AppServer4RPG). ArdGate enables native SQL access from DB2/400 (STRSQL, embedded SQL, QMQRY) to any JDBC Database including reading and writing to and from CSV, XML and Excel.

      Dieter Bender
      Last edited by Guest.Visitor; 11-14-2010, 03:25 AM.

      Comment


      • #4
        Any issues of using Java with RPG are caused mainly by the way the code is written. If you write the code properly and are aware of how to manage the JVM properly then you will not have any issues. When integrating RPG with Java, you could literally integrate your new capabilities right within your existing RPG code and it would be a simple as calling a procedure with a single line of code.

        I am not familiar with the option mentioned above, but I would be cautious to implement new open source projects that have minimal testing in a production environment with minimal support.

        Comment


        • #5
          ... thats simply not true!!! Calling Java from RPG via the Compiler support:
          - doesn't scale, because you are starting multiple, or even hundreds of JVMs
          - is slow, because startup of every JVM has a big punishment on AS/400 and the context switch is expensive
          - is instable, because a null pointer Exception makes your JVM unusable
          - is hard to maintain, because you can't controll your Java environment
          - is unreadable, because every programmer has to have knowledge in Java and RPG.
          Funny, not to know or even not to have a look at some piece of software, but to know, thats not worth to test. Thats one of the reasons, why the RPG community is standing where it stands. We did it this way every time, we don't wanna do it another way, never heard of this guy...
          BTW: AppServer4RPG is published since more than 2 years and the main components where running more than 2 years in production before.

          D*B
          Originally posted by T.Snyder View Post
          Any issues of using Java with RPG are caused mainly by the way the code is written. If you write the code properly and are aware of how to manage the JVM properly then you will not have any issues. When integrating RPG with Java, you could literally integrate your new capabilities right within your existing RPG code and it would be a simple as calling a procedure with a single line of code.

          I am not familiar with the option mentioned above, but I would be cautious to implement new open source projects that have minimal testing in a production environment with minimal support.
          Last edited by Guest.Visitor; 11-14-2010, 03:26 AM.

          Comment


          • #6
            Let's look at what is true and what is not true:
            - The JVM starts once per job. So, yes there is time to start the JVM, but it only starts once, then you reuse it through the job.
            - I would code to handle exceptions caused by null pointers (You could find this in my Book Advanced Integrated RPG and also in the ILE programmers guide)
            - You can control your Java enviroment (You could find this in my Book Advanced Integrated RPG and also in the ILE programmers guide)
            - You can put your Java code into a service program/procedures then you could share your code with your entire staff and all they need to know is RPG and it works.

            As I've said before, I am not familiar with the software you are talking about, so I do not know what it can or can not do.

            I believe there are different tools for different situations. For the particular situation of modifying an RPG program to change EXCEPT to AirExcel_setCellValueString(airCell:'Output Value'); in your existing RPG program to change all of your spool file output to excel spreadsheets is a minor change to your existing programs that gives you full control over your output. This could be accomplished simply with just RPG and the POI open source project.

            I don't know if your application could do that or not. If it can that's great! If I were looking to do something that would require hundreds of jobs to be creating PDFs, XML, Excel Spreadsheets, JDBC with multiple databases, I might also consider using PHP which has all of these capabilities. But, I couldn't use PHP directly inside RPG to create a single Spreadsheet file, or PDF, like integration with Java does. So, there would be two different situation with two different options.

            I did not say to avoid using any software. I said to be cautious. Which to me would make it "worth to test". I am an open source advocate and think it's great there are open source options out there for RPG.

            But, I would think if you were trying to come into a forum to introduce some software you would like for them to try, I wouldn't say to the RPG programming community
            Originally posted by benderd View Post
            "Its not surprising to me, that the RPG mainstream has his feet deep in the passed century." or "RPG, it has evolved, but its far away from beeing competitive with the modern programming languages." as quoted from your other post "Are RPG Programmers RPG's Worst Enemy?"
            The fact of the matter is that I know you at least wrote code in RPG at one time. And you're frustrated. I know. I've been there. But, there are options available.

            Comment


            • #7
              The only thing you could do with null pointer exceptions, is to check in RPG wether an object reference is valid or not. The problem with this is, that if a null pointer exception in Java occors, it crashs at any other point and you have to use some work arounds to get another JVM to work (BTW: the implementation of the compiler support is rather lousy - the JVM is started in the main Thread, you won't do this in C, for example). Making a mistake at one point, causes your software to crash at other points.
              Every JVM you are starting takes more ressources than 20 interactive Jobs doing RPG work and its good practice in Java software development to share JVMs in a Multithreaded Environment, Java is Server oriented work. 50 Jobs creating PDF documents, or doing other work using Java and doing it the embedded Java in RPG way, will use as much ressources as 1000 interactive users!!!.
              Making JNI calls from RPG, using the built-in compiler support, you would have to make all components, you need available in your systemwide classpath. If some other programm would start a JVM with the "wrong" classpath, other applications will get the problems.
              It doesn't help to much to put the JNI calls to a service programm, if something doesn't work, you are thrown back to embedded Java in RPG. Sorry, it looks to me, that the examples from your book are not running in production as long as AppServer4RPG does.
              Just for your information: I'm writing Java Code and RPG up to now and I'm publishing components in both languages from time to time, the main diffrence between my approach and yours is, that I'm looking to the mainstream of Java, to learn how to work with this language in a proper way and I'm not frustrated, I enjoy a lot to write down some thoughts about RPG and Java in Forums like this...

              D*B

              Originally posted by T.Snyder View Post
              Let's look at what is true and what is not true:
              - The JVM starts once per job. So, yes there is time to start the JVM, but it only starts once, then you reuse it through the job.
              - I would code to handle exceptions caused by null pointers (You could find this in my Book Advanced Integrated RPG and also in the ILE programmers guide)
              - You can control your Java enviroment (You could find this in my Book Advanced Integrated RPG and also in the ILE programmers guide)
              - You can put your Java code into a service program/procedures then you could share your code with your entire staff and all they need to know is RPG and it works.

              As I've said before, I am not familiar with the software you are talking about, so I do not know what it can or can not do.

              I believe there are different tools for different situations. For the particular situation of modifying an RPG program to change EXCEPT to AirExcel_setCellValueString(airCell:'Output Value'); in your existing RPG program to change all of your spool file output to excel spreadsheets is a minor change to your existing programs that gives you full control over your output. This could be accomplished simply with just RPG and the POI open source project.

              I don't know if your application could do that or not. If it can that's great! If I were looking to do something that would require hundreds of jobs to be creating PDFs, XML, Excel Spreadsheets, JDBC with multiple databases, I might also consider using PHP which has all of these capabilities. But, I couldn't use PHP directly inside RPG to create a single Spreadsheet file, or PDF, like integration with Java does. So, there would be two different situation with two different options.

              I did not say to avoid using any software. I said to be cautious. Which to me would make it "worth to test". I am an open source advocate and think it's great there are open source options out there for RPG.

              But, I would think if you were trying to come into a forum to introduce some software you would like for them to try, I wouldn't say to the RPG programming community


              The fact of the matter is that I know you at least wrote code in RPG at one time. And you're frustrated. I know. I've been there. But, there are options available.
              Last edited by Guest.Visitor; 11-14-2010, 09:05 AM.

              Comment


              • #8
                These are good points which, comes back to what I said about the way your code is written. “If you write the code properly and are aware of how to manage the JVM properly then you will not have any issues. When integrating RPG with Java”.

                Null Pointer Exceptions



                To me, null pointer exceptions are bugs. Any place where you could potentially get a null pointer exception, I would be proactive and code to support that. And example would be in some code from my book like this:

                svRow = HSSFSheet_getRow(argSheet: argIndex);
                if svRow = *NULL;
                svRow = HSSFSheet_createRow(argSheet: argIndex);
                else;
                endif;

                This is actual code from my book, Advanced Integrate RPG. You get the expected row, if it doesn’t exist, then you create it. No null pointer exception. If you did get a null pointer exception on createRow, then you most likely have your Java package installed improperly which would be identified much earlier.

                Using JNI



                If you were to dive down into the details of using JNI with RPG, you could recover from exceptions using ExceptionOccurred and ExceptionClear. I sometimes use this in situations where I could have exceptions, such as FileNotFound when attempting to read files on the IFS that do not exist. After handling the exception the program will continue normally without having JVM problems. Both of these methods are documented in my Book and in the RPG Programmer’s guide.

                Managing the JVM



                Also using Java with RPG you can manage the JVM. You can start it, stop it, attached to an existing JVM, reclaim memory, handling exceptions… (which are also documented in my book and in the RPG Programmer’s Guide)

                Class Path



                Again the class path has to do with how you do your coding. There is a global setting that you could use to set your class path, but I do not encourage that because you may have 3rd party software that may need to influence that. And also if you are developing and have multiple versions of a jar file on your system that you are testing with, you would want to change your class path to only be used for your current job to test the different version.

                When using Java with RPG, you only get one JVM to start per job. And once you start it you need to have your class path set for the duration of the job. I accommodate this by initializing the JVM within any program that will be using it, and it will prepare for any projects that may be used during the job. This is where the coding part comes in. Just make sure you properly initialize everything and you’ll be fine. And the JVM is only started when the user needs it. They do have a startup time on the first usage, but every reuse after that is very fast, in my opinion.

                Java Exceptions



                If you did have an exception within the Java portion of the code, then yes you would have to debug the Java code, but this is typically just a wrapper around the call to the Java code, so you would need to look at the way you’re are implementing it. I am not sure how you could avoid this in your situation if you have RPG calling Java using any method?

                Simplicity



                The simplicity of integrating Java with RPG is targeted at RPG programmers that have solid RPG programmers that don’t want to evolve their code to have new capabilities without being deterred from learning a large amount of new concepts. With my book Advanced Integrated RPG, you only need to put the jar file on your IFS. Then I provide prototypes and sample code to get it working. That’s it. No servers to maintain and you’re using RPG and coding it right within RPG and you don’t need to be a Java programmer to start using it. My service programs are just the beginning. I demonstrate how to build the prototypes and procedures so they could implement any project and also to become familiar with the capabilities that are available. And I recommend projects that have been tested by hundreds of thousands of users. So you are working with production worthy code that could literally be a single line of code change within your RPG.

                Performance



                I would say if a job is using more of the CPU, it is doing more. When using Java with RPG, I use it for the intentions of extending the existing code. And you code it directly within the existing code. You merely use the service program and have minimal code changes and you’re creating PDFs, Excel Spreadsheets and sending Emails.

                When using Java for these purposes, it only uses Java for these purposes. Other than that you are running lightning fast RPG. So, if you have 100 users on your system, you most likely only have a handful of users utilizing Java at one time. Your code changes are minimal, and you are providing all of these new features with minimal setup and maintenance.

                Larger Scale



                To consider worst case situations of 50 jobs creating spreadsheets concurrently, I would probably consider using batch and queue them up for minimal impact on the system. Or you could run such batch jobs on off peak times.

                If you did not need the resolution of utilizing Java directly in-line with your RPG code and you were going to do things such as creating PDFs or Excel Spreadsheets, or send email. I may consider using PHP that has all of these capabilities and runs very fast. They just wouldn’t be in-line with the RPG code, which is where I would integrate Java with RPG.

                Exploring your Options



                I am always keeping my eyes open for new options.

                For an RPG programmer that wants to make simple changes to their existing code that will give them the ability to create PDFs, Excel Spreadsheets and Email, the documentation is now there. The components are now available and well tested and adaptable to any operating system and multiple programming languages. And there is also sample code available to plug into your code. So, for an RPG programmer, you could make an easy transition into a new programming area and get great results with minimal requirements. And to top it off, you get introduced to Java, which will be a good starting point for learning more about Java and you get to produce professional results.

                After being introduced and acquiring more Java skills, you could then branch off to consider it for a GUI, or applications on workstations or mobile devices.

                When designing web pages, or performing high speed bulk processing as mentioned above, I may consider using PHP. You could easily install it on the I and the coding syntax has been known for having a minimal learning curve.

                So, my point being that there are different solutions to different problems. With these considerations in mind, I wouldn’t discourage the usage of a technique when you have a specific goal in mind. I would tend to take a more pragmatic approach.

                I wish you good luck with your project

                Comment


                • #9
                  ... I don't have read your book, but I did have a look to the downloadable code mentioned in another Thread. The embedded Java in RPG concept is ending up with having some Serviceprogramms doing eMail, generating Excel, accessing a MySQL database and maybe generating PDF.

                  If one of these has a little problem (programms might have bugs) and a null pointer Exception occurs, the next(!!!) Java function will crash. For instance you loose the connection to MySQL and afterwards sending an eMail will fail. If you try to recover the situation. you would have to reload your JVM and you will loose the complete state of the Java parts of your application in your job.

                  If we have a look who is needing one of the above mentioned applications, nearly everybody needs it and so we will have not only 50 JVMs loaded, it might be hundreds and that won't scale, even for expensive hardware. I know very well abot the concept to solve this by a serving (RPG/CL) Batch Job, generating PDF, or sending eMail, scalability would be better, but limited again: one user creating a very large pdf document might slow down - or even block - other users.

                  I agree completely, that it would be best, that an RPG programmer only needs one SRVPGM with 5 or 10 procedures to do eMail, and another SRVPGM for generating PDF and maybe 2 or 3 more for other work, wich is easier done with available Java components. Doing it this way, the technical complexity is encapsulated. Thats my approach too and the SRVPGMs might look very similar to each other. In my design for the implementation of these SRVPGMs I have a Java part and a RPG part and a mechanism to talk with each other. Put all to the Java part, what is done easier in Java (Exception Handling, object creation of temporary needed Objects, managing application state) and providing methods very similar to the exported procedures in the SRVPGM. I could call these methods by JNI calls, but I don't stay here with my concept and I'm going further. I let the Java part run in a prestarted JVM and RPG talks to this JVM asynchronous. This communication part is encapsulated in AppServer4RPG, providing the ability to call a Java method with a DataStructure as parameter, getting back another DataStructure. Inside from AppServer4RPG these calls are handled multi threaded and Session handling is provided.

                  In deed, there are diffrent solutions to diffrent problems and I feel free to recommend a diffrent solution to the problem of integrating Java components in RPG applications. I'm trying to solve this problem from the Java perspective.


                  Dieter Bender

                  Comment

                  Working...
                  X