Thursday, February 28, 2008

The Java Platform


A platform is the hardware or software environment in which a program runs. We've already mentioned some of the most popular platforms like Microsoft Windows, Linux, Solaris OS, and Mac OS. Most platforms can be described as a combination of the operating system and underlying hardware. The Java platform differs from most other platforms in that it's a software-only platform that runs on top of other hardware-based platforms.
The Java platform has two components:
The Java Virtual Machine
The Java Application Programming Interface (API) You've already been introduced to the Java Virtual Machine; it's the base for the Java platform and is ported onto various hardware-based platforms.
The API is a large collection of ready-made software components that provide many useful capabilities. It is grouped into libraries of related classes and interfaces; these libraries are known as packages. The next section, What Can Java Technology Do? highlights some of the functionality provided by the API.

The Java Programming Language


The Java programming language is a high-level language that can be characterized by all of the following buzzwords:
Simple
Architecture neutral
Object oriented
Portable
Distributed
High performance
Multithreaded
Robust
Dynamic
Secure
Each of the preceding buzzwords is explained in The Java Language Environment , a white paper written by James Gosling and Henry McGilton.
In the Java programming language, all source code is first written in plain text files ending with the .java extension. Those source files are then compiled into .class files by the javac compiler. A .class file does not contain code that is native to your processor; it instead contains bytecodes — the machine language of the Java Virtual Machine1 (Java VM). The java launcher tool then runs your application with an instance of the Java Virtual Machine.

Friday, February 8, 2008

JAVA

Java is an object-oriented language derived from C++ with strong support for networking, threading, and component-oriented development. Java source code is compiled to a form called bytecode which is platform-independent. The bytecode is stored in .class files which can, potentially, be transferred across a network to machines of different types, and then converted by each machine to its native machine code using a VM (Virtual Machine). The VM may do that either by interpreting the bytecode (classic model) or by compiling and running it method by method (when the VM incorporates a JIT — Just-In-Time compiler).
The key to Java's platform independence is simplicity. It achieves this by discarding some of C++ features and adding some of its own:
Java has no pointers.
Java does not have multiple inheritance. The same effect is achieved by implementing interfaces.
Java has no preprocessor (hence no macros).
Java does not allow global variables.
Java has a singly-rooted hierarchy. (Everything is descended from Object).
There is strong support for exception handling — the compiler checks to make sure exceptions are properly caught using Exception classes.
There is also strong support for multithreading — the Thread class allows the programmer to quickly create and control lightweight processes.
As Java is simpler and stricter than C++ it makes some compromises:
Java is slower than C++. Originally the VM would interpret the code line by line, and it could run as much as twenty times slower. Today most code is run with a JIT compiler such as Hotspot and may approach C++ speeds.
Low-level tasks must be done by interfacing with other languages — native methods.
An application (especially an applet) may be limited in what it can do over a network owing to Java's strong security model. In many ways this is a strength of course