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

Dropbox 193.4.5594 - Cloud backup and sy...
Dropbox is a file hosting service that provides cloud storage, file synchronization, personal cloud, and client software. It is a modern workspace that allows you to get to all of your files, manage... Read more
Google Chrome 122.0.6261.57 - Modern and...
Google Chrome is a Web browser by Google, created to be a modern platform for Web pages and applications. It utilizes very fast loading of Web pages and has a V8 engine, which is a custom built... Read more
Skype 8.113.0.210 - Voice-over-internet...
Skype is a telecommunications app that provides HD video calls, instant messaging, calling to any phone number or landline, and Skype for Business for productive cooperation on the projects. This... Read more
Tor Browser 13.0.10 - Anonymize Web brow...
Using Tor Browser you can protect yourself against tracking, surveillance, and censorship. Tor was originally designed, implemented, and deployed as a third-generation onion-routing project of the U.... Read more
Deeper 3.0.4 - Enable hidden features in...
Deeper is a personalization utility for macOS which allows you to enable and disable the hidden functions of the Finder, Dock, QuickTime, Safari, iTunes, login window, Spotlight, and many of Apple's... Read more
OnyX 4.5.5 - Maintenance and optimizatio...
OnyX is a multifunction utility that you can use to verify the startup disk and the structure of its system files, to run miscellaneous maintenance and cleaning tasks, to configure parameters in the... Read more
Hopper Disassembler 5.14.1 - Binary disa...
Hopper Disassembler is a binary disassembler, decompiler, and debugger for 32- and 64-bit executables. It will let you disassemble any binary you want, and provide you all the information about its... Read more

Latest Forum Discussions

See All

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 »
Live, Playdate, Live! – The TouchArcade...
In this week’s episode of The TouchArcade Show we kick things off by talking about all the games I splurged on during the recent Playdate Catalog one-year anniversary sale, including the new Lucas Pope jam Mars After Midnight. We haven’t played any... | Read more »
TouchArcade Game of the Week: ‘Vroomies’
So here’s a thing: Vroomies from developer Alex Taber aka Unordered Games is the Game of the Week! Except… Vroomies came out an entire month ago. It wasn’t on my radar until this week, which is why I included it in our weekly new games round-up, but... | Read more »
SwitchArcade Round-Up: ‘MLB The Show 24’...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for March 15th, 2024. We’re closing out the week with a bunch of new games, with Sony’s baseball franchise MLB The Show up to bat yet again. There are several other interesting games to... | Read more »
Steam Deck Weekly: WWE 2K24 and Summerho...
Welcome to this week’s edition of the Steam Deck Weekly. The busy season has begun with games we’ve been looking forward to playing including Dragon’s Dogma 2, Horizon Forbidden West Complete Edition, and also console exclusives like Rise of the... | Read more »
Steam Spring Sale 2024 – The 10 Best Ste...
The Steam Spring Sale 2024 began last night, and while it isn’t as big of a deal as say the Steam Winter Sale, you may as well take advantage of it to save money on some games you were planning to buy. I obviously recommend checking out your own... | Read more »
New ‘SaGa Emerald Beyond’ Gameplay Showc...
Last month, Square Enix posted a Let’s Play video featuring SaGa Localization Director Neil Broadley who showcased the worlds, companions, and more from the upcoming and highly-anticipated RPG SaGa Emerald Beyond. | Read more »
Choose Your Side in the Latest ‘Marvel S...
Last month, Marvel Snap (Free) held its very first “imbalance" event in honor of Valentine’s Day. For a limited time, certain well-known couples were given special boosts when conditions were right. It must have gone over well, because we’ve got a... | Read more »
Warframe welcomes the arrival of a new s...
As a Warframe player one of the best things about it launching on iOS, despite it being arguably the best way to play the game if you have a controller, is that I can now be paid to talk about it. To whit, we are gearing up to receive the first... | Read more »
Apple Arcade Weekly Round-Up: Updates an...
Following the new releases earlier in the month and April 2024’s games being revealed by Apple, this week has seen some notable game updates and events go live for Apple Arcade. What The Golf? has an April Fool’s Day celebration event going live “... | Read more »

Price Scanner via MacPrices.net

Apple Education is offering $100 discounts on...
If you’re a student, teacher, or staff member at any educational institution, you can use your .edu email address when ordering at Apple Education to take $100 off the price of a new M3 MacBook Air.... Read more
Apple Watch Ultra 2 with Blood Oxygen feature...
Best Buy is offering Apple Watch Ultra 2 models for $50 off MSRP on their online store this week. Sale prices available for online orders only, in-store prices may vary. Order online, and choose... Read more
New promo at Sams Club: Apple HomePods for $2...
Sams Club has Apple HomePods on sale for $259 through March 31, 2024. Their price is $40 off Apple’s MSRP, and both Space Gray and White colors are available. Sale price is for online orders only, in... Read more
Get Apple’s 2nd generation Apple Pencil for $...
Apple’s Pencil (2nd generation) works with the 12″ iPad Pro (3rd, 4th, 5th, and 6th generation), 11″ iPad Pro (1st, 2nd, 3rd, and 4th generation), iPad Air (4th and 5th generation), and iPad mini (... Read more
10th generation Apple iPads on sale for $100...
Best Buy has Apple’s 10th-generation WiFi iPads back on sale for $100 off MSRP on their online store, starting at only $349. With the discount, Best Buy’s prices are the lowest currently available... Read more
iPad Airs on sale again starting at $449 on B...
Best Buy has 10.9″ M1 WiFi iPad Airs on record-low sale prices again for $150 off Apple’s MSRP, starting at $449. Sale prices for online orders only, in-store price may vary. Order online, and choose... Read more
Best Buy is blowing out clearance 13-inch M1...
Best Buy is blowing out clearance Apple 13″ M1 MacBook Airs this weekend for only $649.99, or $350 off Apple’s original MSRP. Sale prices for online orders only, in-store prices may vary. Order... Read more
Low price alert! You can now get a 13-inch M1...
Walmart has, for the first time, begun offering new Apple MacBooks for sale on their online store, albeit clearance previous-generation models. They now have the 13″ M1 MacBook Air (8GB RAM, 256GB... Read more
Best Apple MacBook deal this weekend: Get the...
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 15-inch M3 MacBook Air (Midnight) on sale...
Amazon has the new 15″ M3 MacBook Air (8GB RAM/256GB SSD/Midnight) in stock and on sale today for $1249.99 including free shipping. Their price is $50 off MSRP, and it’s the lowest price currently... Read more

Jobs Board

Early Preschool Teacher - Glenda Drive/ *Appl...
Early Preschool Teacher - Glenda Drive/ Apple ValleyTeacher Share by Email Share on LinkedIn Share on Twitter Read more
Senior Software Engineer - *Apple* Fundamen...
…center of Microsoft's efforts to empower our users to do more. The Apple Fundamentals team focused on defining and improving the end-to-end developer experience in Read more
Relationship Banker *Apple* Valley Main - W...
…Alcohol Policy to learn more. **Company:** WELLS FARGO BANK **Req Number:** R-350696 **Updated:** Mon Mar 11 00:00:00 UTC 2024 **Location:** APPLE VALLEY,California Read more
Medical Assistant - Surgical Oncology- *Apple...
Medical Assistant - Surgical Oncology- Apple Hill WellSpan Medical Group, York, PA | Nursing | Nursing Support | FTE: 1 | Regular | Tracking Code: 200555 Apply Now Read more
Early Preschool Teacher - Glenda Drive/ *Appl...
Early Preschool Teacher - Glenda Drive/ Apple ValleyTeacher Share by Email Share on LinkedIn Share on Twitter Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.