ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

How to start with java

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

  • How to start with java

    Hello,

    I have a java source but i couldn't get info in web, where to paste the code and how to compile.. All i could get is CRTJVAPGM which says something to create an object from jar or class file. but i need to create jar file from a source. Please advise.

  • #2
    Re: How to start with java

    You need to save the Java code to a stream file in the IFS. The filename should end in .java. So if your program is named 'HelloWorld", you would call the IFS file "HelloWorld.java"

    Once you've done that, you should compile your program from QShell. The command would look like this:
    Code:
    javac HelloWorld.java
    IMHO, you should never use the CRTJVAPGM command. That's an old IBM tool that was used to do optimization on an existing Java class (these days you should use standard JIT optimization, it optimizes better...) and to add IBM-only features to Java, such as adopted authority. Frankly, if you're going to use IBM i only features, you're much better off NOT using Java. The only real advantage of coding in Java (which is, IMHO, a clumsy and poor performing environment) is that it's cross-platform. Once you start adding OS-specific features, there's really no reason to use Java.

    So don't use CRTJVAPGM -- it's only for progams that are already compiled.

    Use "javac" in QShell to compile. Then, you can use the "java" command in QShell to run your program, or the RUNJVA command if you wish to run it from the CL command environment. (But, QShell is a more natural environment for Java programs that use the console.)

    Almost everyone who codes Java programs for IBM i is working with web interfaces, though... so for a "helloworld" using a tool like RUNJVA is fine, but most likely, if you get serious about it, you'll be using WebSphere.

    Comment


    • #3
      Re: How to start with java

      Originally posted by Scott Klement View Post
      You need to save the Java code to a stream file in the IFS. The filename should end in .java. So if your program is named 'HelloWorld", you would call the IFS file "HelloWorld.java"

      Once you've done that, you should compile your program from QShell. The command would look like this:
      Code:
      javac HelloWorld.java
      IMHO, you should never use the CRTJVAPGM command. That's an old IBM tool that was used to do optimization on an existing Java class (these days you should use standard JIT optimization, it optimizes better...) and to add IBM-only features to Java, such as adopted authority. Frankly, if you're going to use IBM i only features, you're much better off NOT using Java. The only real advantage of coding in Java (which is, IMHO, a clumsy and poor performing environment) is that it's cross-platform. Once you start adding OS-specific features, there's really no reason to use Java.

      So don't use CRTJVAPGM -- it's only for progams that are already compiled.

      Use "javac" in QShell to compile. Then, you can use the "java" command in QShell to run your program, or the RUNJVA command if you wish to run it from the CL command environment. (But, QShell is a more natural environment for Java programs that use the console.)

      Almost everyone who codes Java programs for IBM i is working with web interfaces, though... so for a "helloworld" using a tool like RUNJVA is fine, but most likely, if you get serious about it, you'll be using WebSphere.

      Thank you Scott. Compiled it successfully. But while running Runjva command
      Code:
      Runjva Class(sample) PARM('/quim/data/file') classpath(*ENVVAR)
      Although the file is at the location, the program is showing 'File not found exception' while running. is there anything more to be done?

      Comment


      • #4
        Re: How to start with java

        Are you referring to the '/quim/data/file' file? Or are you referring to the Java class?

        Have you verified that it exists with WRKLNK?

        Have you tried running the Java program with QShell instead of RUNJVA? (I don't know why that would matter, but it's easy to try.)

        Comment

        Working...
        X