Compiling Java


To compile a Java source file into a Java class, use the command:

      JAVAC vehicle.java 

Within WDSc, simply right-click the Java source file and select javac to compile the Java class. Assuming that the source file contained no errors, the compiler will create a file with the same name as the source file, but with an extension of .class. In this case, it would create a file named Vehicle.class.

The vehicle class is not an executable class. Other Java classes can call it, but it cannot be the initial class. Applications are special classes that can be the initial class called. These applications are similar to the sample class shown in Figure 26.3, but the example in Figure 26.4 shows the code for a sample application named Buycar. Rather than having a constructor method, it has a main method. In WDSc, right-click the Vehicle.java file and select Copy, then Paste the copy into the i5Primer folder, renaming it Buycar.java.

image from book
Figure 26.4: Source code for Buycar Java application.

The main method public static void main(String[] args) { accepts an array of strings as arguments. Strings[] defines the data type of the argument as an array of strings; args is the name of array.

As before, system.out.println(); prints a line of text.

The first close brace (}) ends the main method, and the second close brace ends the application.



IBM i5/iSeries Primer(c) Concepts and Techniques for Programmers, Administrators, and Sys[... ]ators
IBM i5/iSeries Primer(c) Concepts and Techniques for Programmers, Administrators, and Sys[... ]ators
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 245

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net