Guild Companies, Inc.  
 
Midrange Programmer - How-To Advice & Free Code
OS/400 Edition
Volume 1, Number 8 - April 25, 2002

Learning Java by Example

by Shannon O'Donnell

[The code for this article is available for download.]

Sometimes all you want is for someone to simply show you how to do something because you don't have the time to research it on your own. Sometimes we all feel that way, because we have way too much to do. So what the heck? Let's take one article and forget about the how's and the why's and instead concentrate only on the how-to. In this article, I'm going to show you how to use Java to accomplish some useful and unique tasks.


Executing Commands on a PC Using Java


Here's one way to execute PC commands from Java. Compile the sample Java application on your PC and run it by typing the following:







java ExecuteCommands <Path_Command>

Where "Path" is the path (i.e., C:\winnt), and "Command" is the executable file you want to run (i.e., NOTEPAD.EXE).

ExecuteCommands.txt

Displaying AS/400 Spool Files from a PC

Want to display spool files from the AS/400 on your user's PC, from within a Java application? Let the iSeries Toolbox for Java VACESS classes named AS400DetailsPane and VprinterOutput do all the hard work for you. Here's how.

Compile the Java code and execute it by typing the following:

java AS400SpooledFilesDemo

You'll be prompted to log on to your iSeries, and the spool files for the user who logged on will be displayed in an AS400DetailsPane.

AS400SpooledFilesDemo.txt

Creating a New Image Based on an Existing Image

If you've ever had occasion to duplicate JPEG image files, you know that you can do so in a variety of ways. You could, for example, use Windows Explorer to copy one image to another, or you could use a photo editor such as Paint Shop Pro. But what if you need to programmatically duplicate an image? Once again, Java comes to the rescue!

This Java application will accept the name of an existing image file (JPEG, GIF), and the name of the new JPEG file to be created from the old image; it then creates the new JPEG based on the existing image file.

Compile the source code and run the Java application:

java createNewImageFromOldImage  pathOldImage   pathNewImage

Where "path" is the qualified path to the image file (i.e., C:\), "OldImage" is the name of an existing image file (i.e., Drawing.JPG), and "NewImage" is the name of the new image file you want to create (i.e, DuplicateJPG).

createNewImageFromOldImages.txt

Just the Beginning

It's amazing what you can do with Java. These three short examples are merely the tip of the iceberg. Use these examples as a beginning for building your own cool Java applications. And if you come up with something really unique, send it to me at sodonnell@itjungle.com and we might even publish it!

Editor's Note: This article has been edited since its original publication. The article incorrectly stated that the command java DisplayAS400SpooledFiles should be used to display spool files from the AS/400 on a user's PC, from within a Java application. The command is, in fact, java AS400SpooledFilesDemo. Guild Companies regrets the errors. [Corrections made 4/25/02]

Sponsored By
WORKSRIGHT

On June 30, 2002,
$$$$$$$$    Postal Rates will go UP!    $$$$$$$$

On Monday, July 1st,
$$$$$    your postage bill can go down.    $$$$$

How can this happen? By CASS certifying your mailing names and addresses and presorting your outgoing mail. Our CASS certification software ensures that your address files have valid ZIP Code and address information. Our presort software ensures that you can properly prepare you mail for delivery to your Post Office.

WorksRight Software, Inc. is the number-one source for iSeries and AS/400 CASS, presort, ZIP Code, and area code software and data. Visit our Web site - www.worksright.com - to learn more about our CASS and presorting software, or contact WorksRight Software, Inc., phone 601-856-8337, e-mail software@worksright. com.

THIS ISSUE
SPONSORED BY:
ASNA
BCD Int'l
Tramenco
Aldon Computer Group
Profound Logic Software
WorksRight Software
BACK ISSUES
TABLE OF CONTENTS
Empower Users with Embedded SQL
Fun with VARPG Radio Buttons
Simplify JSP Applications with JavaBeans, Part 2
Stream I/O in Qshell
The iSeries Toolbox for Java Does Service Programs
Learning Java by Example
  Newsletters | Subscribe | Advertise | About Us | Contact | Search | Home  
  Last Updated: 4/24/02
Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.