iSeries compile Java programs - Beginners Tutorial

To compile java program in iSeries you need to have JDK installed. Click here to learn how to check if Java is installed on your iSeries and what is the the Java Version?


Here is a sample Java program that we will try to compile

package com.as400samplecode;

public class SimpleJava {

 public static void main(String[] args) {

  String firstName = args[0].trim();
  String lastName = args[1].trim();
  String age = args[2].trim();

  System.out.println("First Name: " + firstName);
  System.out.println("Last Name: " + lastName);
  System.out.println("Age: " + age);

 }

}

Now you can create a new file called SimpleJava.java in the IFS directory of your choice or use Eclipse to create the program and then FTP it to iSeries.

To compile the Java program we are going to use the command javac in Qshell



To start the Qshell use command QSH and press ENTER.

Once inside the QSH, next to the $ sign type

cd {path_to_your_folder} and press ENTER

for example cd /myName/Java, when your get the $ sign back that means execution is complete.

Now to compile type
javac -d {path_to_your_folder} SimpleJava.java

After the Java program is compiled you will see the $ sign.

Now lets run the program, type
java java com.as400samplecode.SimpleJava "Albert" "Who" "35"

Here is the Output
First Name: Albert
Last Name: Who
Age: 35
$

Lets look at what the compile does it basically creates a sub directory called com underneath the {path_to_your_folder} and then underneath that is the as400samplecode directory and then the java class. This is what happens when you package Java programs using this line of code.

package com.as400samplecode;

Javac Command


javac [ options ] [ sourcefiles ] [ @argfiles ]

Arguments may be in any order.

options
  • Command-line options.
sourcefiles
  • One or more source files to be compiled (such as SimpleJava.java).
@argfiles
  • One or more files that lists options and source files. The -J options are not allowed in these files.

Standard Options

-classpath classpath
Set the user class path, overriding the user class path in the CLASSPATH environment variable. If neither CLASSPATH or -classpath is specified, the user class path consists of the current directory. See Setting the Class Path for more details.

If the -sourcepath option is not specified, the user class path is searched for source files as well as class files.

-d directory
Set the destination directory for class files. The destination directory must already exist; javac will not create the destination directory. If a class is part of a package, javac puts the class file in a subdirectory reflecting the package name, creating directories as needed. For example, if you specify -d c:\myclasses and the class is called com.mypackage.MyClass, then the class file is called c:\myclasses\com\mypackage\MyClass.class.

If -d is not specified, javac puts the class file in the same directory as the source file. Note that the directory specified by -d is not automatically added to your user class path.

-deprecation
Show a description of each use or override of a deprecated member or class. Without -deprecation, javac shows the names of source files that use or override deprecated members or classes.

-encoding encoding
Set the source file encoding name, such as EUCJIS/SJIS. If -encoding is not specified, the platform default converter is used.

-g
Generate all debugging information, including local variables. By default, only line number and source file information is generated.

-g:none
Do not generate any debugging information.

-g:{keyword list}
Generate only some kinds of debugging information, specified by a comma separated list of keywords. Valid keywords are:

source
Source file debugging information
lines
Line number debugging information
vars
Local variable debugging information

-help
Print a synopsis of standard options.

-nowarn
Disable warning messages.

-source release
Enables support for compiling source code containing assertions.

When release is set to 1.4, the compiler accepts code containing assertions. Assertions were introduced in J2SE 1.4. When release is set to 1.3, the compiler does not support assertions. The compiler defaults to the 1.3 behavior if the -source flag is not used.

-sourcepath sourcepath
Specify the source code path to search for class or interface definitions. As with the user class path, source path entries are separated by semicolons (;) and can be directories, JAR archives, or ZIP archives. If packages are used, the local path name within the directory or archive must reflect the package name.

Note that classes found through the classpath are subject to automatic recompilation if their sources are found.

-verbose
Verbose output. This includes information about each class loaded and each source file compiled.

No comments:

Post a Comment

NO JUNK, Please try to keep this clean and related to the topic at hand.
Comments are for users to ask questions, collaborate or improve on existing.