04-05-2013, 12:56 PM
Java & J2EE Made Easy
Java.pdf (Size: 4.88 MB / Downloads: 210)
Introduction
What is Java?
Java™ is a programming language introduced by Sun Microsystems Inc. Like
any other programming languages Java is also used for building software applications.
If this is the case, then why do we need Java? Good question. Here is what makes Java
distinctive from other programming languages. Most programming languages like C,
C++ etc, are targeted for a particular platform (a.k.a operating system). What this really
means is that, if we write a program in a language like C or C++ or any other language,
say on an OS like Windows, then the same program cannot be executed on a different
OS like, say Linux, without making some changes to the source code. These changes
could span anywhere from modifying few lines of code to rewriting the entire program.
This is not good, right? Therefore, we say such programming languages as being non
portable in nature.
When do we say a programming language as being portable?
When the machine code generated by compiler of a programming language can be used on
any OS without any modification, then we say the programming language as being
portable in nature.
Keeping the above philosophy in mind, creators of Java language made it portable.
Sweet! We’ll see how this portability is achieved later. For now, this portability feature is
what makes Java distinctive from other programming languages and this is the reason
why we call it as platform independent language. Believe me, this one feature is the
driving force and motivation for today’s modern enterprises that uses Java technologies.
And moreover, this is also the reason why we are interested in learning Java.
Java based Applications
Besides Java language being platform independent, it is the nature of applications that
we can build using Java makes it even more special. Java can be used to build two types
of applications as listed below:
1. Standalone applications
2. Internet applications
Standalone applications are the applications that run on a single computer. All the
command line applications and GUI based applications where funky windows are used
to interact with the applications fall in this category. This is one side of Java. The other
side of Java is that it can be used to build applications that can be run on the internet.
This is where Java unleashes its true power. We all agree without any slightest hesitation
that internet is part of our life. Here is how I look at internet and Java. Internet connects
people and organizations around the globe to exchange information. To achieve this, we
need to build high speed applications that run on internet. Prior to Java, there are other
languages and technologies with which internet applications are built, but they suffered
from serious problems and limitations. The advent of Java and its adaptability on
internet has completely changed dimensions of business organizations and the way
business is done. This is the true strength of Java, its adaptability on the Internet.
How does Java achieve Platform independency?
First things first. As I said before that Java is platform independent, the question is, how
does it achieve this independency? To understand, there is some thing called bytecode
that we need to know about. Most programming languages use compilers to translate
high level program to machine code of the OS in a single step. Once the machine code is
generated we cannot port it to a different OS and can only be used on that OS only.
Therefore, any language that uses just the compiler to compile as well as execute the
program is platform dependent. Java recognized this problem upfront and came with a
novel idea by breaking the compiler into two different programs as compiler and
interpreter.
Java uses compiler to translate high level Java code into bytecode, and uses the interpreter
to translate bytecode to machine code. This is a two step process as opposed to single
step process shown in Fig 1.1.