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

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 »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »

Price Scanner via MacPrices.net

13-inch M2 MacBook Airs in stock today at App...
Apple has 13″ M2 MacBook Airs available for only $849 today in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty is included,... Read more
New today at Apple: Series 9 Watches availabl...
Apple is now offering Certified Refurbished Apple Watch Series 9 models on their online store for up to $80 off MSRP, starting at $339. Each Watch includes Apple’s standard one-year warranty, a new... Read more
The latest Apple iPhone deals from wireless c...
We’ve updated our iPhone Price Tracker with the latest carrier deals on Apple’s iPhone 15 family of smartphones as well as previous models including the iPhone 14, 13, 12, 11, and SE. Use our price... Read more
Boost Mobile will sell you an iPhone 11 for $...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering an iPhone 11 for $149.99 when purchased with their $40 Unlimited service plan (12GB of premium data). No trade-in is required... Read more
Free iPhone 15 plus Unlimited service for $60...
Boost Infinite, part of MVNO Boost Mobile using AT&T and T-Mobile’s networks, is offering a free 128GB iPhone 15 for $60 per month including their Unlimited service plan (30GB of premium data).... Read more
$300 off any new iPhone with service at Red P...
Red Pocket Mobile has new Apple iPhones on sale for $300 off MSRP when you switch and open up a new line of service. Red Pocket Mobile is a nationwide MVNO using all the major wireless carrier... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, available for $759 for 8-Core CPU/7-Core GPU/256GB models and $929 for 8-Core CPU/8-Core GPU/512GB models. Apple’s one-year warranty is... Read more
Updated Apple MacBook Price Trackers
Our Apple award-winning MacBook Price Trackers are continually updated with the latest information on prices, bundles, and availability for 16″ and 14″ MacBook Pros along with 13″ and 15″ MacBook... Read more
Every model of Apple’s 13-inch M3 MacBook Air...
Best Buy has Apple 13″ MacBook Airs with M3 CPUs in stock and on sale today for $100 off MSRP. Prices start at $999. Their prices are the lowest currently available for new 13″ M3 MacBook Airs among... Read more
Sunday Sale: Apple iPad Magic Keyboards for 1...
Walmart has Apple Magic Keyboards for 12.9″ iPad Pros, in Black, on sale for $150 off MSRP on their online store. Sale price for online orders only, in-store price may vary. Order online and choose... Read more

Jobs Board

Solutions Engineer - *Apple* - SHI (United...
**Job Summary** An Apple Solution Engineer's primary role is tosupport SHI customers in their efforts to select, deploy, and manage Apple operating systems and Read more
DMR Technician - *Apple* /iOS Systems - Haml...
…relevant point-of-need technology self-help aids are available as appropriate. ** Apple Systems Administration** **:** Develops solutions for supporting, deploying, 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.