TweetFollow Us on Twitter

Java FAQ
Volume Number:12
Issue Number:1
Column Tag:Javatech™

Java Rules

A Java FAQ

By Hillel N. Cooperman and Aparajita Fishman, Cambridge, MA

This is the first in what will be several articles on Java and the Macintosh implementations. Watch this column in the future for a beginner lesson on Java programming and reviews of offerings from Natural Intelligence, Borland, Sun, and others for Macintosh programmers.
- Contrib. Ed, jaw

Considering the amount of hype surrounding Java, it is nearly impossible, without a lengthy and thorough investigation, to really understand what Java is all about, and to know what it can and cannot do for you. As an antidote to all the hype, we are going to try to give some honest answers about Java in this article. We hope it will be helpful as you decide about how to pursue this new technology.

According to Sun’s “The Java Language - A White Paper”, Java is a “portable, interpreted, high-performance, simple, object-oriented” programming language. Buzzword-shy it is not. In the questions below we will look at Sun’s claims and explain what they mean.

1. What is Java?

Java is a programming language. It is really that simple. Much of the confusion on this topic is from people mixing up what Java will enable with what Java actually is. However, for the purposes of this article, Java’s importance is based on what it is currently capable of doing. That’s what we’ll focus on.

First a little bit of history. In April of 1991 the Java development team (or “Green” team, as they then called themselves) started work in a building located off of the Sun campus. Java was originally conceived as a programming language and operating system for consumer electronics devices (i.e. set-top boxes). The team envisioned the technology being licensed in the same way that Dolby Systems licenses its noise reduction technology. While market forces shifted so that the set-top box market slipped away as a potential home for the Java technology, the Web appeared on the horizon as a likely candidate for Java-based interactivity. With this goal in mind, Sun introduced Java in May of 1995. Sun’s current marketing reflects the idea that Java is the “Internet application language.” We will try to delve a little deeper.

Yes, Java is a language but it is also a concept and an approach to deploying applications.

2. What Is a Java Applet?

As we said before, many people confuse Java’s capabilities with what Java actually is. The primary task with which people associate Java is creating interactive content for the Web. By this we mean a level of interactivity beyond the basic forms and buttons provided by a combination of standard HTML and CGI programming. An applet is a program that is called in the process of displaying HTML. Calling an applet from HTML looks like this:

Sample HTML
<HTML>
<HEAD>
<TITLE>Applet Page</TITLE>
</HEAD>
<BODY>
<H4>This is an example of a Java applet:</H4>
<H>R
<APPLET CODE=myApplet.class width=100 height=50>
</APPLET>
<H>R
</BODY>
</HTML>

Sample Applet
import browser.applet;
import awt.graphics;
class myapplet extends Applet  {
        public void paint(Graphics g) {
                g.drawstring("Hello world.", 25, 25);
        }
}

When a Java-enabled web browser (such as HotJava or Netscape) encounters the APPLET tag, it loads the Java class (applet) referenced in the quotation marks. Once loaded, the browser runs the code contained in the applet and performs whatever function is specified by the code.

Having applets run in your web browser wouldn’t be such a great feat if they weren’t small enough to be loadable in a relatively short period of time; interactivity on the web is not very interactive if it takes an hour to load an applet. Just as Macintosh applications are built upon the Macintosh Toolbox, which provides a significant foundation of core functionality, Java applets are built upon Sun’s AWT (Abstract Window Toolkit), a class library which provides applets with their core functionality. And just as the Macintosh Toolbox resides on each user’s machine, so too is AWT a part of each user’s browser, obviating the need to load AWT over the net. The end result is that Java applets tend to be very compact, which translates into faster load times.

3. Is Java Only Good For Creating Applets?

Currently there are two options when using Java. The first is to create AWT-based applets which can only run within a Java-enabled browser or application. The second is any programs which use only console input and output. Although used mainly for applets now, Java is a robust, general purpose language with many possible applications.

4. How Easy Is It To Go From C/C++ To Java?

It is very easy.

One of the Java team’s stated objectives was to keep the language familiar to the majority of programmers. Java’s expression syntax is the same as C’s and it incorporates the key object-oriented features of C++. This was done to give programmers a common reference point when porting their skills to Java. And, from our perspective, Java provides most of the power of C++ with none of the pain. This was achieved by avoiding those “features” of C++ which, while providing tremendous power for those “in the know,” are a source of tremendous complexity and befuddlement for most programmers. In particular there are two potential pitfalls in C++ that Java avoids: raw pointers and multiple inheritance. In place of pointers, Java provides true type-safe arrays and strings, as well as runtime type-checked dynamic casting.

5. Are Java Applets Cross-Platform?

The Java specification actually consists of two parts, the language specification and the Java runtime environment. The language specification, like any other programming language, is independent of the platform on which it is deployed. Java’s runtime environment is a byte code virtual machine (VM) interpreter that allows an applet to run on any given platform. Think of it as a simulated CPU with a platform neutral machine language.

The Java compiler compiles Java source code into Java byte code, and this byte code is executed by the virtual machine. Because the Java environment and virtual machine are platform-independent specifications and have been ported to multiple platforms, compiled Java applets are themselves platform-independent.

There are two browsers that are currently available (or are about to be available) that run Java applets. HotJava is Sun’s Java-capable browser (written in Java) that runs on Solaris and Windows NT. As of this writing, beta versions of a Java-capable Netscape browser are available on Solaris, Windows NT, Windows 95, and of course Macintosh.

6. Will Java Allow Viruses and Destructive Programs
to be Transmitted Via the Net?

As we mentioned before, Java applets are built on AWT. AWT provides two levels of security. On the first level, AWT prevents applets from having free access to your computer’s file system. So, for example, it would be extremely difficult for someone to write a Java applet which did any damage to your computer’s files. The second level of security involves a byte code verifier in the Java virtual machine. The verifier checks to see if any of AWT’s security classes have been overridden or if anything in the applet will make the browser crash. If both conditions are met, it allows the non-offending applets to run in your browser. Otherwise, it rejects them. While a good concept, the verifier can be fooled; be careful.

7. How Fast is Java?

The real question is, “How fast is Java in relation to other programming languages?” The answer is, Java falls somewhere in between the speed of static languages such as C/C++ and dynamic languages such as SmallTalk. Preliminary benchmarks show that Java byte codes typically execute at about 50% of the speed of well written C code for processor intensive tasks. The bottom line is that Java is significantly faster than dynamic languages such as SmallTalk and interpreted languages such as Visual Basic. The secret to Java’s speed is the design of the virtual machine instruction set. The instruction set is close enough to most native CPU instruction sets that there is very little overhead in translating from Java byte codes to native instructions. Future versions of the Java byte code interpreter will be able to translate from Java byte codes to native machine code on the fly (also known as “just-in-time compilation”), which will result in even greater execution speed.

8. Why Does Java Have “Automatic Garbage Collection” and “Multi-Threading”?

OK, so that’s really two questions. One of the priorities in creating the Java language was to keep the language simple. Or more specifically, the goal was to avoid a lot of the complexities of C++. One of the common complaints about coding is the work you must do to manage your memory, not to mention the consequences if you don’t do it properly. Studies have shown that up to 50% of a programmer’s time, when using non-garbage-collected languages such as C and C++, goes into managing memory storage. And, a significant amount of debugging time goes toward tracking down memory-related bugs.

The beauty of the Java Virtual Machine is that it takes care of memory management for you. This process is called “automatic garbage collection.” A low-priority thread periodically scans your applet’s memory for unused objects and recycles the memory they were using. It does this by keeping track of what parts of your program are using memory, and determining when those chunks of memory are no longer needed. Many programmers mistakenly think that garbage collection is inherently slower than manual memory management. This impression stems from the fact that up until now, most mainstream languages that used garbage collection were interpreted and thus inherently slow themselves. In fact, a well-implemented garbage collector is on average as fast if not faster than the best implementation of manual memory management. A well-implemented garbage collector can be faster than manual memory management because it can reclaim unused memory in one fell swoop instead of in hundreds of small increments.

As for multi-threading, we just saw one very good use of multiple threads. Aside from garbage collection, today’s fast microprocessors can easily support multiple threads of execution, allowing more flexible and robust solutions to many classical programming problems. For example, any asynchronous task, which requires polling of a state flag, can be spun off into a separate thread allowing the main thread of execution to continue unabated without worrying about the result of the task.

9. What is the Future for Java on the Macintosh?

As we mentioned above, Netscape is planning to release a Macintosh version of its browser that is Java-capable. Programming in Java on the Macintosh is a different story altogether. There are currently two options. As of this writing, Sun is planning on releasing a Macintosh version of their Java Development Kit in early 1996. By the time you read this article, Developer Release 1 of Roaster™, the other option on the Macintosh, will be shipping. No discussion of Java in a Macintosh programming magazine would be complete without mention of Roaster. However, Roaster is a product from our company, Natural Intelligence, so I’ll keep the marketing to a minimum and give you the basics.

Roaster is an integrated development environment for writing Java applets. Roaster consists of several components:

Project Window This is used for the organization of
your source code and compiled byte
codes in a Finder-like view.

Source Code Editor The editor includes a toolbar with a full
suite of code-editing functions, context-
sensitive color and style syntax
formatting, and drag and drop support.

Runtime Engine This allows you to put up a native
window in which you can test your
applets.

Compiler The compiler generates Java byte codes.

We’re including this description in the article to give you an idea of what will be in Natural Intelligence’s Macintosh applet development environment for Java. But hopefully, Sun’s environment will be out soon, so that you will have more than one option for developing in Java on the Macintosh. [Metrowerks has announced support for Java development as well. See Newsbits. - Ed. Asst. jtk]

10. Where Can I Get More Information?

I always balk at putting references to the net in articles that won’t be published until weeks after they’re written. The net is so dynamic that they may end up being out of date. So cross your fingers and check out these resources. Most should still be relevant by the time you read this, though I’m sure that there will be many more by the time this is published.

Java Home Page http://java.sun.com/ John December presents Java
http://www.rpi.edu/~decemj/works/java.html/

Java Jive http://catalog.com/dddu/javajive.html/

Natural Intelligence, Inc. http://www.natural.com/

Gamelan Java Resource Registry http://www.gamelan.com/

Java Usenet Newsgroup news:comp.lang.java

Java-Mac mailing list send “subscribe java-mac” to
majordomo@natural.com

These are just a few of the resources out there. Keep your eyes peeled for the inevitable avalanche of books and magazine articles on the subject.

Summary

In closing, despite your natural reaction (as a marketing savvy programmer) to dismiss the hype surrounding Java, there really is something to get excited about. While Java has its limitations, it is a definite leap ahead of today’s industry standard programming languages and approaches. With your support of the language, there is no doubt that Java will continue to thrive in the future.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Top Hat Studios unveils a new gameplay t...
There are a lot of big games coming that you might be excited about, but one of those I am most interested in is Athenian Rhapsody because it looks delightfully silly. The developers behind this project, the rather fancy-sounding Top Hat Studios,... | Read more »
Bound through time on the hunt for sneak...
Have you ever sat down and wondered what would happen if Dr Who and Sherlock Holmes went on an adventure? Well, besides probably being the best mash-up of English fiction, you'd get the Hidden Through Time series, and now Rogueside has announced... | Read more »
The secrets of Penacony might soon come...
Version 2.2 of Honkai: Star Rail is on the horizon and brings the culmination of the Penacony adventure after quite the escalation in the latest story quests. To help you through this new expansion is the introduction of two powerful new... | Read more »
The Legend of Heroes: Trails of Cold Ste...
I adore game series that have connecting lore and stories, which of course means the Legend of Heroes is very dear to me, Trails lore has been building for two decades. Excitedly, the next stage is upon us as Userjoy has announced the upcoming... | Read more »
Go from lowly lizard to wicked Wyvern in...
Do you like questing, and do you like dragons? If not then boy is this not the announcement for you, as Loongcheer Game has unveiled Quest Dragon: Idle Mobile Game. Yes, it is amazing Square Enix hasn’t sued them for copyright infringement, but... | Read more »
Aether Gazer unveils Chapter 16 of its m...
After a bit of maintenance, Aether Gazer has released Chapter 16 of its main storyline, titled Night Parade of the Beasts. This big update brings a new character, a special outfit, some special limited-time events, and, of course, an engaging... | Read more »
Challenge those pesky wyverns to a dance...
After recently having you do battle against your foes by wildly flailing Hello Kitty and friends at them, GungHo Online has whipped out another surprising collaboration for Puzzle & Dragons. It is now time to beat your opponents by cha-cha... | Read more »
Pack a magnifying glass and practice you...
Somehow it has already been a year since Torchlight: Infinite launched, and XD Games is celebrating by blending in what sounds like a truly fantastic new update. Fans of Cthulhu rejoice, as Whispering Mist brings some horror elements, and tests... | Read more »
Summon your guild and prepare for war in...
Netmarble is making some pretty big moves with their latest update for Seven Knights Idle Adventure, with a bunch of interesting additions. Two new heroes enter the battle, there are events and bosses abound, and perhaps most interesting, a huge... | Read more »
Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »

Price Scanner via MacPrices.net

Save $300 at Apple on 14-inch M3 MacBook Pros...
Apple has 14″ M3 MacBook Pros with 16GB of RAM, Certified Refurbished, available for $270-$300 off MSRP. Each model features a new outer case, shipping is free, and an Apple 1-year warranty is... Read more
Apple continues to offer 14-inch M3 MacBook P...
Apple has 14″ M3 MacBook Pros, Certified Refurbished, available starting at only $1359 and ranging up to $270 off MSRP. Each model features a new outer case, shipping is free, and an Apple 1-year... Read more
Apple AirPods Pro with USB-C return to all-ti...
Amazon has Apple’s AirPods Pro with USB-C in stock and on sale for $179.99 including free shipping. Their price is $70 (28%) off MSRP, and it’s currently the lowest price available for new AirPods... Read more
Apple Magic Keyboards for iPads are on sale f...
Amazon has Apple Magic Keyboards for iPads on sale today for up to $70 off MSRP, shipping included: – Magic Keyboard for 10th-generation Apple iPad: $199, save $50 – Magic Keyboard for 11″ iPad Pro/... Read more
Apple’s 13-inch M2 MacBook Airs return to rec...
Apple retailers have 13″ MacBook Airs with M2 CPUs in stock and on sale this weekend starting at only $849 in Space Gray, Silver, Starlight, and Midnight colors. These are the lowest prices currently... Read more
Best Buy is clearing out iPad Airs for up to...
In advance of next week’s probably release of new and updated iPad Airs, Best Buy has 10.9″ M1 WiFi iPad Airs on record-low sale prices for up to $200 off Apple’s MSRP, starting at $399. Sale prices... Read more
Every version of Apple Pencil is on sale toda...
Best Buy has all Apple Pencils on sale today for $79, ranging up to 39% off MSRP for some models. Sale prices for online orders only, in-store prices may vary. Order online and choose free shipping... Read more
Sunday Sale: Apple Studio Display with Standa...
Amazon has the standard-glass Apple Studio Display on sale for $300 off MSRP for a limited time. Shipping is free: – Studio Display (Standard glass): $1299.97 $300 off MSRP For the latest prices and... Read more
Apple is offering significant discounts on 16...
Apple has a full line of 16″ M3 Pro and M3 Max MacBook Pros available, Certified Refurbished, starting at $2119 and ranging up to $600 off MSRP. Each model features a new outer case, shipping is free... Read more
Apple HomePods on sale for $30-$50 off MSRP t...
Best Buy is offering a $30-$50 discount on Apple HomePods this weekend on their online store. The HomePod mini is on sale for $69.99, $30 off MSRP, while Best Buy has the full-size HomePod on sale... Read more

Jobs Board

Liquor Stock Clerk - S. *Apple* St. - Idaho...
Liquor Stock Clerk - S. Apple St. Boise Posting Begin Date: 2023/10/10 Posting End Date: 2024/10/14 Category: Retail Sub Category: Customer Service Work Type: Part Read more
*Apple* App Developer - Datrose (United Stat...
…year experiencein programming and have computer knowledge with SWIFT. Job Responsibilites: Apple App Developer is expected to support essential tasks for the RxASL Read more
Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.