Sunday, November 22, 2009

Java evolution (History of Java)

In 1990, the Sun Microsystems Inc, US has got a project, which is developing remote control software. Different remote controllers having different processors and so they have to develop different software. The team leader James Gausling has thought that why don't we develop single software which can run on different remote controllers. He decided to develop a new language. Generally on those days, all are used C language, which is system dependent.

They have developed a new language named OaK in 1993. But OaK name is already registered. So, they have decided to rename it as JAVA (Good quality of Tea is coming from Java Islands). The Sun Microsystems has released Java in June 1995 on the occasion of Sun World Conference.

Features of Java:


1. Simple - Java is a simple programming language. Learning and practicing Java is easy because of its resemblance with C and C++. The difficult concepts in C++ have been eliminated in Java.
Java = C++ - Complexities
. For example pointer concept has been eliminated in Java.

Question: Why pointers are eliminated in Java?
Pointers lead to confusion for a programmer. Pointers may crash a program. Using pointer virus and hacking programs can be written.

1. Object oriented - Unlike C++, Java is a purely object oriented programming language. Java programs uses objects and classes.

Object: An object is anything that exists in this real world. An object has properties and behaviors (actions).

In our program variables are used to represent properties. Actions are represented by methods. i.e.; An object contains variables and methods. i.e.; Objects need memory. JVM will allocate the memory required for objects.

Class: A class is a model or blue print for creating objects. Class doesn’t exist physically, it is only our idea. i.e.; A class contains the definition for variables and methods of its objects.

Below table depicts some class names and objects.

Class names Objects
Flower Lilli, Jasmine, Lotus
Book NoteBook, TextBook, RefBook
Actor Chiranjeevi, Kamal Hasan, Rajani
Actress Radha, Anushka, Tamnna, Sneha Ullal
Shirt T-Shirt, S-Sleve, Glasour
Sweet Jilebi, Coa, Kalakanda


C++ is not purely an object oriented programming language because without creating an object or a class we can write a C++ program. Whereas, without creating at least one class we can't write a program. So, Java is said to be a purely object oriented programming language.

3. Distributed: - Java is a distributed technology. Information is distributed on various computers on a network. Using Java, we can write programs which capture information and distribute ii to clients.

4. Robust: - Java programs will not crash easily because of its exception handling and its memory management features. Memory management was handled by JVM> i.e.; allocation and de-allocation of memory handled by JVM.

Memory Allocation: JVM's class loader sub system will allocate required memory for a program.

Memory de-allocation: JVM's garbage collector will free the allocated memory. Garbage collector will check the memory between every time interval and it used Mark and Sweep algorithm to de-allocate the memory for unused variables and objects.

Exception handling: Exception means a run time error. In Java we can handle the exceptions.

5. Secure: - Java enables the construction of virus free and tamper free systems.

6. Architecture neutral: - Java's byte code is not machine dependent. It can be run on any machine with any processor and with any O/S.

7. Portable: - A program yielding the same result on any computer is said to be portable. Java program give same results on all machines. Everything is clearly defined in Java specification and nothing is left to O/S.

8. Interpreted: - Java programs are compiled to generate the byte code. This byte code can be downloaded and interpreted by the interpreter in JVM.

9. High performance: - Along with interpreter, there will be JIT (Just in time) compiler which enhances the speed of execution.

10. Multi threaded: - We can create different processing in Java, called "threads". This is an essential feature to design server side program.

11. Dynamic: - We can develop programs in Java, which dynamically interact with the user on internet (Eg: Applets)

What made Java more popular?

Let's have a quick look at what made Java more popular among the existing programming languages like COBOL, FORTRAN, PASCAL, C, C++.

Programming language:


I'm going to ask some general questions before I explain about programming languages.

1. What is a language?
Your answer - ??
My answer - A language is a communication tool between two persons, for example you're reading this because you know the language English.

2. Why do we need a language?
Your answer - ??
My answer - A language is used to fulfill our needs (requests).

Like two humans can communicate with each other with a language, a human can communicate with computer by using programming languages to fulfill needs. The program that we wrote cannot be directly recognized by the computer. Computer recognizes only machine code. So, we have to convert our program into machine understandable signals. For this purpose we are having translators.

Translator

- It is a program which coverts program into machine understandable code (electric signals or pulses). There are three types of translators available.

Interpreter - Coverts only one line of the program at a time

Compiler - Coverts all lines of a program in a single step (Note: Compiler is 10 times faster than the interpreter)

Assembler - Converts assembly language instructions into machine level language.

Here I explain a sample process of compiler with C compiler. When you write and compile a program C language, the below tasks will be carried out
When we compile a program, the compiler will create a new object code (.obj) file. An object code is equivalent machine code for our program. Whenever we first execute our program, the compiler will create an executable file. An EXE file has the machine language instructions (A group of instructions that understand by a micro processor are called as instruction set) including header files also. (It directly executed without compiler). The first microprocessor in the world - 4044. Later on 8080, 8085, 8086, 8088, 80286, 80386, 80486, 80586 have been developed.

System dependent program


If a program is executable only on the computer system where it was developed - called system dependent program. All the existing languages before the invention of Java are system dependent. For example if you write a program on Windows which can't be executed on Linux. Hence, we can't use these languages to develop software which runs on internet.

Java is system independent, hence it is highly suitable for internet. Whenever we compile java source, it will create a class file. A class file contains byte code equivalent to our program. Each instruction size of a byte code is 1 byte. There are total of 220 byte code instructions available.

When we compile Java program, compiler will rewrite the program as another set of instructions. The rewritten code is said to be byte code.

JVM


JVM refers Java Virtual Machine. JVM is a program which will convert byte code instructions into machine language instructions understandable by Micro processor. Right Java program write once, later on run anywhere.

JVM is a system dependent, because it was developed in C language, where as class file is a system independent.

Question: What is the difference between class file and exe file
EXE file contains machine language instructions understandable by Micro processor, where as class file contains byte code instructions for JVM. EXE file is system dependent, where as class file is a system independent.

Sun Microsystems has developed different JVMs for different operating systems. Hence, you can write a single Java program and generate the class file which can be executed on any other operating system.