Computer Sciences Department logo

CS 368-1 (2010 Summer) — Day 9 Code Sample

These are the code samples that we built in class.

Java: Hello, World!

public class HelloJava {

    public static void main(String args[]) {
        String name = (args.length == 0) ? "World" : args[0];
        System.out.println("Hello, " + name + "!");
    }

}

Simple Workflow: Build and Run HelloWorld.java

#!/usr/bin/perl

use strict;
use warnings;

# try to compile HelloJava.java
print "compiling... \n";
system('javac HelloJava.java');

# check exit code for errors
if ($? != 0) {
    print "FAILED! $? : $!\n";
}

# everything is ok, run code
print "running... \n";
my $java_output = `java HelloJava`;

# print output
print "the command exited " . ($? >> 8) . "\n";
print "and the output was '$java_output'\n";