Q's & A's - Feb 1997

From EDM2
Revision as of 22:13, 14 January 2019 by Ak120 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

QUESTION: What is Java?

ANSWER: Java is a programming language developed at Sun Microsystems in 1991 as part of a research project to create a small, simple, fast and efficient language that could be used to develop embedded component software. With the increase in popularity of the Internet and World Wide Web, Java has been enhanced to enable secure and complex distributed interaction in real time over heterogeneous networks. Recently, Sun split off Java development into JavaSoft, a separate new subsidiary.

QUESTION: Why is Java becoming so popular?

ANSWER: Java allows developers to enable small applets to be sent across the Web and to run on thin, low-cost clients. In addition, for ease of learning, Java was designed to resemble C and C++; but, Sun made some important changes, including:

  • Java is simple. Sun removed many of the difficult features of C and C++ such as pointer arithmetic, the need to allocate and free memory, and multiple inheritance.
  • Java is small. Most Java interpreters use less than 256 KB of RAM.
  • Java is object-oriented. Java implements the same basic object technology as C++, but with some important omissions and additions. As new object technologies arise, Java will be able to easily embody these technologies into new classes.
  • Java is distributed. The Java class library includes networking classes that provide TCP/IP, HTTP, and FTP access. Again, as new and/or enhanced communication protocols are developed, Java will be in a position to quickly and easily provide access to them through its class library.
  • Java is platform independent and portable. Any machine that has a Java runtime system and/or Java-enabled browser can execute a Java application or applet. Java runtime systems are based upon Sun's "Java Virtual Machine Specification" that provides concrete definitions for implementing the language's instruction set, register set, class file format, stack implementation, garbage collection, and memory management.
  • Java is secure and robust. Because Java does not allow developers to allocate and free blocks of memory and because there is no pointer arithmetic, hackers and poor programmers will find it more difficult to introduce bugs onto remote systems. Java also provides null-pointer checking, array-bounds checking, exception handling, and object code verification. In addition, Java applets running on remote systems have very limited access to those remote systems--specifically, Java applets do not have the ability to read or write to the file systems of the remote machines. Finally, before running an applet or application, a Java interpreter must check the integrity of the code during the loading process.
  • The Java language is interpreted. Unlike C and C++, a Java interpreter can execute object code and does not require a link phase.

Currently 68 vendors own Java Virtual Machine licenses, 9 of those vendors have announced plans to embed the Java Virtual Machine into their operating systems, and more than 200,000 developers are writing Java code.

QUESTION: Why have C-programming elements like pointer arithmetic, struct's, typedef's, preprocessor directives, and memory deallocation been omitted from the Java language?

ANSWER: Removal of these elements makes the language simple to use and reduces a developer's opportunity to make mistakes. In addition, the removal of pointer arithmetic and memory deallocation makes the language more secure, making it difficult, if not impossible, for hackers and programmers to corrupt remote systems.

QUESTION: How is memory dynamically allocated and returned without pointer variables?

ANSWER: Java actually does take advantage of pointers. When objects are first instantiated with the new() method, a reference or object address is returned and saved in a variable. It is this reference that is used to access an object's public data and methods. Also, objects are always passed by reference and never by value when passed as arguments in a method.

In Java, there is no need to free or deallocate objects that have been instantiated with the new() method. One of the requirements of Sun's Java Virtual Machine Specifications, provides automatic garbage collection of objects that have gone out of scope and objects that have been assigned a null value.

QUESTION: It was mentioned earlier that Java doesn't support multiple inheritance. In the past I've relied heavily upon multiple inheritance to mix-in additional functionality and capability to my subclasses in an object-oriented and orderly fashion. Do I lose this in Java?

ANSWER: The Java language supports the collection of routines into objects called interfaces. An interface differs from a class in that it consists entirely of methods and does not have its own data. In addition the methods may or may not be defined within the interface itself.

While Java does not allow new subclasses to be derived from multiple classes, Java does allow multiple interfaces to be mixed-in or "implemented" with the new subclasses. The interfaces' methods can be overridden and implemented just as the inherited public methods from a parent class. As an example, a new subclass might be defined as follows:

   public class MyNewClass extends java.awt.Canvas
                           implements Runnableimplements AnotherInterface
                           implements OneMoreInterface
   {
       //: class definition goes here_includes the overriding of
       //: methods inherited from the java.awt.Canvas class as
       //: well as methods inherited from the Runnable, 
       //: AnotherInterface, and OneMoreInterface interfaces.
   }

QUESTION: Is there a difference between a Java application and a Java applet?

ANSWER: Yes, Java applications:

  • are stand-alone and do not require a Java-enabled browser.
  • are invoked with a JAVA.EXE command (or JAVAPM.EXE command on OS/2 if the Abstract Window Toolkit classes are used).
  • contain a class with a main() method.
  • are not subject to a strict security model.

On the other hand, Java applets:

  • are run within Java-enabled browsers or AppletViewer's.
  • do not contain a main() method or primary entry point.
  • are event driven and their flow of control is governed by a Java runtime.
  • are subject to a strict security model.

QUESTION: If a Java applet does not have the ability to read or write files for security reasons, why is there a java.io package?

ANSWER: While an applet running on a remote system does not have the ability to perform file input/output, stand-alone Java applications are able to read, write, and query file system information.

QUESTION: Can a Java client applet access other machines across the network?

ANSWER: No, applets are not allowed to open network connections to any computer except for the host that provided the initial .CLASS file.

QUESTION: The November 25, 1996 issue of PC Week reported that Microsoft is creating a separate, Windows-specific version of the Java language and indicates that Microsoft has renamed the Java Virtual Machine to the WIN32 Java Virtual Machine. Will I be able to execute applets created with Microsoft tools on other platforms when I'm browsing the World Wide Web?

ANSWER: Any Java applets or applications that use platform-dependent APIs or classes will run only on that specific platform. To put it simply, a Java applet that uses the WIN32 API will not run on an AIX workstation. It will run only on Windows. According to the December 2, 1996 issue of PC Week, JavaSoft is expected to launch a marketing and branding program to promote "pure Java" applications and implementations. This new branding is expected to discourage independent software vendors from writing Java applications that make use of platform-specific classes or APIs such as Microsoft Corporation's Active X. Java 1.1, which is due out early this year, will be separated into two categories: Core APIs and Extended APIs. PC Week stated that vendors holding Java licenses will be required to support the Core API, while the Extended API support will be optional.

QUESTION: Where can I get more information on Java?

ANSWER: Additional information can be found at the following web sites:

http://java.sun.com/
http://www.developer.ibm.com/
http://www.ibm.com/java/
http://www.gamelan.com/

Mickey Nix is a Senior Programmer in the IBM Solution Developer Marketing organization. For the past year, Mickey has assisted IBM's top independent software vendors in their efforts to port Windows applications to the OS/2 platform. Recently, Mickey was given the additional responsibility of network computing consultant.

Reprint Courtesy of International Business Machines Corporation, © International Business Machines Corporation