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

Whitethorn Games combines two completely...
If you have ever gone fishing then you know that it is a lesson in patience, sitting around waiting for a bite that may never come. Well, that's because you have been doing it wrong, since as Whitehorn Games now demonstrates in new release Skate... | Read more »
Call of Duty Warzone is a Waiting Simula...
It's always fun when a splashy multiplayer game comes to mobile because they are few and far between, so I was excited to see the notification about Call of Duty: Warzone Mobile (finally) launching last week and wanted to try it out. As someone who... | Read more »
Albion Online introduces some massive ne...
Sandbox Interactive has announced an upcoming update to its flagship MMORPG Albion Online, containing massive updates to its existing guild Vs guild systems. Someone clearly rewatched the Helms Deep battle in Lord of the Rings and spent the next... | Read more »
Chucklefish announces launch date of the...
Chucklefish, the indie London-based team we probably all know from developing Terraria or their stint publishing Stardew Valley, has revealed the mobile release date for roguelike deck-builder Wildfrost. Developed by Gaziter and Deadpan Games, the... | Read more »
Netmarble opens pre-registration for act...
It has been close to three years since Netmarble announced they would be adapting the smash series Solo Leveling into a video game, and at last, they have announced the opening of pre-orders for Solo Leveling: Arise. [Read more] | Read more »
PUBG Mobile celebrates sixth anniversary...
For the past six years, PUBG Mobile has been one of the most popular shooters you can play in the palm of your hand, and Krafton is celebrating this milestone and many years of ups by teaming up with hit music man JVKE to create a special song for... | Read more »
ASTRA: Knights of Veda refuse to pump th...
In perhaps the most recent example of being incredibly eager, ASTRA: Knights of Veda has dropped its second collaboration with South Korean boyband Seventeen, named so as it consists of exactly thirteen members and a video collaboration with Lee... | Read more »
Collect all your cats and caterpillars a...
If you are growing tired of trying to build a town with your phone by using it as a tiny, ineffectual shover then fear no longer, as Independent Arts Software has announced the upcoming release of Construction Simulator 4, from the critically... | Read more »
Backbone complete its lineup of 2nd Gene...
With all the ports of big AAA games that have been coming to mobile, it is becoming more convenient than ever to own a good controller, and to help with this Backbone has announced the completion of their 2nd generation product lineup with their... | Read more »
Zenless Zone Zero opens entries for its...
miHoYo, aka HoYoverse, has become such a big name in mobile gaming that it's hard to believe that arguably their flagship title, Genshin Impact, is only three and a half years old. Now, they continue the road to the next title in their world, with... | Read more »

Price Scanner via MacPrices.net

B&H has Apple’s 13-inch M2 MacBook Airs o...
B&H Photo has 13″ MacBook Airs with M2 CPUs and 256GB of storage in stock and on sale for up to $150 off Apple’s new MSRP, starting at only $849. Free 1-2 day delivery is available to most US... Read more
M2 Mac minis on sale for $100-$200 off MSRP,...
B&H Photo has Apple’s M2-powered Mac minis back in stock and on sale today for $100-$200 off MSRP. Free 1-2 day shipping is available for most US addresses: – Mac mini M2/256GB SSD: $499, save $... Read more
Mac Studios with M2 Max and M2 Ultra CPUs on...
B&H Photo has standard-configuration Mac Studios with Apple’s M2 Max & Ultra CPUs in stock today and on Easter sale for $200 off MSRP. Their prices are the lowest available for these models... Read more
Deal Alert! B&H Photo has Apple’s 14-inch...
B&H Photo has new Gray and Black 14″ M3, M3 Pro, and M3 Max MacBook Pros on sale for $200-$300 off MSRP, starting at only $1399. B&H offers free 1-2 day delivery to most US addresses: – 14″ 8... Read more
Department Of Justice Sets Sights On Apple In...
NEWS – The ball has finally dropped on the big Apple. The ball (metaphorically speaking) — an antitrust lawsuit filed in the U.S. on March 21 by the Department of Justice (DOJ) — came down following... Read more
New 13-inch M3 MacBook Air on sale for $999,...
Amazon has Apple’s new 13″ M3 MacBook Air on sale for $100 off MSRP for the first time, now just $999 shipped. Shipping is free: – 13″ MacBook Air (8GB RAM/256GB SSD/Space Gray): $999 $100 off MSRP... Read more
Amazon has Apple’s 9th-generation WiFi iPads...
Amazon has Apple’s 9th generation 10.2″ WiFi iPads on sale for $80-$100 off MSRP, starting only $249. Their prices are the lowest available for new iPads anywhere: – 10″ 64GB WiFi iPad (Space Gray or... Read more
Discounted 14-inch M3 MacBook Pros with 16GB...
Apple retailer Expercom has 14″ MacBook Pros with M3 CPUs and 16GB of standard memory discounted by up to $120 off Apple’s MSRP: – 14″ M3 MacBook Pro (16GB RAM/256GB SSD): $1691.06 $108 off MSRP – 14... Read more
Clearance 15-inch M2 MacBook Airs on sale for...
B&H Photo has Apple’s 15″ MacBook Airs with M2 CPUs (8GB RAM/256GB SSD) in stock today and on clearance sale for $999 in all four colors. Free 1-2 delivery is available to most US addresses.... Read more
Clearance 13-inch M1 MacBook Airs drop to onl...
B&H has Apple’s base 13″ M1 MacBook Air (Space Gray, Silver, & Gold) in stock and on clearance sale today for $300 off MSRP, only $699. Free 1-2 day shipping is available to most addresses in... Read more

Jobs Board

Medical Assistant - Surgical Oncology- *Apple...
Medical Assistant - Surgical Oncology- Apple Hill Location: WellSpan Medical Group, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply 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
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
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
Business Analyst | *Apple* Pay - Banco Popu...
Business Analyst | Apple PayApply now " Apply now + Apply Now + Start applying with LinkedIn Start + Please wait Date:Mar 19, 2024 Location: San Juan-Cupey, PR Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.