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

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 »
MoreFun Studios has announced Season 4,...
Tension has escalated in the ever-volatile world of Arena Breakout, as your old pal Randall Fisher and bosses Fred and Perrero continue to lob insults and explosives at each other, bringing us to a new phase of warfare. Season 4, Into The Fog of... | Read more »
Top Mobile Game Discounts
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links below... | Read more »
Marvel Future Fight celebrates nine year...
Announced alongside an advertising image I can only assume was aimed squarely at myself with the prominent Deadpool and Odin featured on it, Netmarble has revealed their celebrations for the 9th anniversary of Marvel Future Fight. The Countdown... | Read more »
HoYoFair 2024 prepares to showcase over...
To say Genshin Impact took the world by storm when it was released would be an understatement. However, I think the most surprising part of the launch was just how much further it went than gaming. There have been concerts, art shows, massive... | Read more »

Price Scanner via MacPrices.net

Apple Watch Ultra 2 now available at Apple fo...
Apple has, for the first time, begun offering Certified Refurbished Apple Watch Ultra 2 models in their online store for $679, or $120 off MSRP. Each Watch includes Apple’s standard one-year warranty... Read more
AT&T has the iPhone 14 on sale for only $...
AT&T has the 128GB Apple iPhone 14 available for only $5.99 per month for new and existing customers when you activate unlimited service and use AT&T’s 36 month installment plan. The fine... Read more
Amazon is offering a $100 discount on every M...
Amazon is offering a $100 instant discount on each configuration of Apple’s new 13″ M3 MacBook Air, in Midnight, this weekend. These are the lowest prices currently available for new 13″ M3 MacBook... Read more
You can save $300-$480 on a 14-inch M3 Pro/Ma...
Apple has 14″ M3 Pro and M3 Max MacBook Pros in stock today and available, Certified Refurbished, starting at $1699 and ranging up to $480 off MSRP. Each model features a new outer case, shipping is... Read more
24-inch M1 iMacs available at Apple starting...
Apple has clearance M1 iMacs available in their Certified Refurbished store starting at $1049 and ranging up to $300 off original MSRP. Each iMac is in like-new condition and comes with Apple’s... Read more
Walmart continues to offer $699 13-inch M1 Ma...
Walmart continues to offer new Apple 13″ M1 MacBook Airs (8GB RAM, 256GB SSD) online for $699, $300 off original MSRP, in Space Gray, Silver, and Gold colors. These are new MacBook for sale by... Read more
B&H has 13-inch M2 MacBook Airs with 16GB...
B&H Photo has 13″ MacBook Airs with M2 CPUs, 16GB of memory, and 256GB of storage in stock and on sale for $1099, $100 off Apple’s MSRP for this configuration. Free 1-2 day delivery is available... Read more
14-inch M3 MacBook Pro with 16GB of RAM avail...
Apple has the 14″ M3 MacBook Pro with 16GB of RAM and 1TB of storage, Certified Refurbished, available for $300 off MSRP. Each MacBook Pro features a new outer case, shipping is free, and an Apple 1-... Read more
Apple M2 Mac minis on sale for up to $150 off...
Amazon has Apple’s M2-powered Mac minis in stock and on sale for $100-$150 off MSRP, each including free delivery: – Mac mini M2/256GB SSD: $499, save $100 – Mac mini M2/512GB SSD: $699, save $100 –... Read more
Amazon is offering a $200 discount on 14-inch...
Amazon has 14-inch M3 MacBook Pros in stock and on sale for $200 off MSRP. Shipping is free. Note that Amazon’s stock tends to come and go: – 14″ M3 MacBook Pro (8GB RAM/512GB SSD): $1399.99, $200... Read more

Jobs Board

Housekeeper, *Apple* Valley Village - Cassi...
Apple Valley Village Health Care Center, a senior care campus, is hiring a Part-Time Housekeeper to join our team! We will train you for this position! In this role, Read more
Sublease Associate Optometrist- *Apple* Val...
Sublease Associate Optometrist- Apple Valley, CA- Target Optical Date: Apr 20, 2024 Brand: Target Optical Location: Apple Valley, CA, US, 92307 **Requisition Read more
*Apple* Systems Administrator - JAMF - Syste...
Title: Apple Systems Administrator - JAMF ALTA is supporting a direct hire opportunity. This position is 100% Onsite for initial 3-6 months and then remote 1-2 Read more
Relationship Banker - *Apple* Valley Financ...
Relationship Banker - Apple Valley Financial Center APPLE VALLEY, Minnesota **Job Description:** At Bank of America, we are guided by a common purpose to help Read more
IN6728 Optometrist- *Apple* Valley, CA- Tar...
Date: Apr 9, 2024 Brand: Target Optical Location: Apple Valley, CA, US, 92308 **Requisition ID:** 824398 At Target Optical, we help people see and look great - and Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.