|
Summary: If our introductions to Rexx have whet your appitite any, you may now be interested in moving up to another easy-to-learn language: Java. I doubt anyone has missed the Java wave, but maybe you are still wondering about what Java could do for you. If you'd like to find out, this new regular column will guide you into object oriented developing, try some useful algorithms and show how easy it could be to build graphical interfaces. Java makes all of the above easy, since most of the hard stuff has already been done and either comes with Java or is easy to obtain. In other words, Java gives you what you want, without the headache. Soon we'll know more about Java inner parts, opportunities and user interaction, as well as basic modeling and design. I won't assume you have any knowledge about any particular programming technique, but I will assume you have some basic coding coding experience, no matter which language. In the future I'll be dividing future columns into a theory lesson and some practical lab work. But today we start with a little of Java's history. The history lessonOnce upon a time, while working for Sun Microcomputers, a computer scientist named James Gosling gave birth to a new object oriented language that he named Oak. That was eight years back in 1991 when people were still using OS/2 version 1.30 and cheered when Rexx made it into the Standard Edition. Oh, those were the days ... Oak was primarily developed for use in embedded electronic equipment, such as VCRs, telephones and cable TV boxes. That never surfaced at the time, but it was important to the language because it set the basic characteristic of what we have today in Java. Two of those important qualities are size and reliability. Embedded systems aren't equipped with huge amounts of memory, therefore the size is important. But even more important is the reliability. Imagine an automatic telephone switchboard running out of memory, or taking a sudden power-failure. You'd quickly learn to appreciate reliability if you lived in that area. Fortunately, while consumer electronics were still far off, the World Wide Web gave Java a new purpose, since Java really met the needs of the client/server systems inherent to the Internet. The pro's were: the small size suited limited bandwidths, it was an interpreted language with the potential of being supported by any operating system, and it had a security manager. These made Java the perfect tool for applets and soon it was giving many web pages everything from animation to online shopping carts. What IBM saw in Java is still a mystery, since they already had Smalltalk, a language still widely used in the community of computer science and which still has a number of features Java doesn't have. In spite of that, March 1996 saw IBM gave us a prerelease of Java for OS/2, and six months later we received Warp 4 with Java 1.02. Today, we consider 1.02 useless, but back then it gave us a Java enabled Netscape and a token presence on the Java landscape. However, since then Java has matured from good to better to best on OS/2. If you've forgotten, why not look at Infoworld's review of Java Virtual Machines again and see how OS/2 ranks compared to the others. Today Java seems to be one of the hottest languages ever, broadly hyped-up by computer media and everyone except Microsoft. Nevertheless, learning Java could never be wrong, it gives you a deep insight in Object Oriented developing and you could always switch to C++ later on (given that the two languages are remarkably similar). Java basicsAs with REXX, Java is an interpreted language. This means that each instruction is translated into native machine code as it runs and your computer will need a Java interpreter to understand how to read each instruction. But you ask, "Don't you compile the Java code?" Yes, you do, but you're not compiling to machine code as you would with a traditional compiled language. A computer understands machine code as you understand your native tongue, fast, fluently and faultless. Machine code speaks right to the computers heart, it's CPU. Only the operating system lays in between to control the actions, supporting the app with memory, creating windows on demand, and other basic tasks. But Java is compiled to a device-independent, operating system-independent, bytecode. Bytecode (so-called because it is mostly made up by combinations of instructions of one or two bytes long) is kind of a pseudo-machine-language, understood by an interpreter, a Java Virtual Machine. The JVM reads the Java bytecode and executes it, byte by byte. The JVM is, on the contrary, 100% dependent upon the actual operating system. Compared to C this takes time and so Java has been belittled as sluggish. Alas, if you're planning to write yourself a new database managing the telephone numbers of New York city, you'd better pick another language. But, you could easily use Java to build your user-interface to this huge database as well as every module around it. Further, Java can either be used to create a stand-alone application, or browser-dependent applets. The main difference is that you have to embed an applet in a HTML web page and run it in another framework, like your Netscape browser, or the OS/2 appletviewer. An application has no need of a framework, except the Java Virtual Machine that's installed on your computer. There are differences between apps and applets, but we'll not bother with these for the moment. Your Java developing environmentIf you haven't already set up an environment for developing Java, there's only a few short steps you need to create one. First. See to it you have at least one HPFS partition. When Java was developed, the designers thought it was about time to finally give up the old 8.3 filename limit, meaning that it's almost impossible to do any Java development on FAT formatted drives.
Second. Make yourself a new folder to use for your work (Figure 1). We'll use several examples and a lot of the stuff will be reused, as it should in object oriented developing. Although there are a number of visual developing tools available, you are in no need of them now. They serve their purpose, but I want you to get the basic feeling of Java inner parts. Frankly, you got the first tool already, E.EXE, which comes with OS/2. Or you could use EPM, or any tool you find yourself comfortable with. The advantages with developing tools are, you'll get colored key words, automatic indentation and other nifty features. Third. Go get the software needed. To install Java you are in need of a few items. Follow these steps:
Say Hello World
We will conclude this first part of our column with the most oft written application ever: "Hello World." Open up an OS/2 window alongside your text or programming editor of choice (in our case, MED), then follow me. Our "Hello World" example is shown here in this screenshot, (Figure 2) that's deliberately replacing normal text so you can't cheat by using cut and paste ;-) Remember that Java is sensitive to the type of parentheses or bracket you use, with there being three kinds: { } [ ] ( ). They are always in pairs. Be sure you save the file with exactly this name in your HelloWorld folder that you made before: HelloWorld.java. Java is very sensitive with upper and lower case names, including file names. After you've written the code and saved it, you're off to execute the built in Java compiler. And after that we will test the OS/2 JVM (Figure 3). The first command line javac HelloWorld.java starts the Java compiler. The result will be a new file called HelloWorld.class.
The second command line java HelloWorld is actually starting the OS/2 JVM, executing the file HelloWorld.class. The extension 'class' is always omitted. Now you could go tell your friends you've spent this time making a Java application ;-) Did I hear someone mention "useful"? Ahem, could we save some of the goodies to the future? So you will be back. See you next month! |
Copyright © 1999 - Falcon Networking | ISSN 1203-5696 | April 1, 1999 |