1
Unit – I
Introduction to Java?
Java is a high level, robust, secured, object-oriented programming language and platform
developed and by James Gosling and others at Sun Microsystems in 1991.
It is a combination of features of C and C++ with some essential additional concepts.
Java code that runs on one platform does not need to be recompiled to run on another
platform; it's called write once, run anywhere (WORA).
It was first introduced to the public in 1995 and is widely used to
create Internet applications and other software programs.
Today, Java (JDK) is maintained and owned by Oracle.
Originally name known as OAK (Object Application Kernel) or Greentalk.
Java can be used to create two types of programs.
Application Applets
An application is a program that runs on An Applet is a small window based
the user’s computers under the operating program that runs on HTML page using a
system java enabled web browser
like internet Explorer, Netscape
Navigator or an Applet Viewer.
.
Fig (a)
2
Java Program
Compiler (Byte code)
Java Virtual Machine (JVM) [Interpreter]
Execute Execute Execute
Linux OS Windows Mac OS
Fig (b)
Fig (a) and (b): Java Execution
There were five primary goals in the creation of the Java language:
1. It should use the object-oriented programming methodology.
2. It should allow the same program to be executed on multiple operating systems.
3. It should contain built-in support for using computer networks.
4. It should be designed to execute code from remote sources securely.
5. It should be easy to use by selecting what was considered the good parts of other object-
oriented languages.
3
Computer and its Languages:
Stage:
By the end of the 1980s and the early 1990s, object-oriented programming using C++
took hold.
Indeed, for a brief moment it seemed as if programmers had finally found the perfect
language. Because C++ blended the high efficiency and stylistic elements of C with the
object-oriented paradigm, it was a language that could be used to create a wide range of
programs.
However, just as in the past, forces were brewing that would, once again, drive computer
language evolution forward. Within a few years, the World Wide Web and the Internet
would reach critical mass. This event would precipitate another revolution in
programming.
Origin:
Java is a general-purpose, object-oriented programming language developed by Sun
Microsystems of USA in 1991.
Originally called Oak by James Gosling, one of the inventors of the language, Java was
designed for the development of software for consumer electronic devices like TVs,
VCRs, toasters and such other electronic machines.
This goal had a strong impact on the development team to make the language simple,
portable and highly reliable.
The Java team which included Patrick Naughton discovered that the existing languages
like C and C+ + had limitations in terms of both reliability and portability.
However, they modeled their new language Java on C and C++ but removed a number of
features of C and C++ that were considered as sources of problems and thus made Java a
really simple, reliable, portable, and powerful language.
Below Table lists some important milestones in the development of Java.
Year Development
1990 Sun Microsystems decided to develop special software that could be used to
manipulate consumer electronic devices.
A team of Sun Micro systems programmers headed by James Gosling was formed to
undertake this task.
After exploring the possibility of using the most popular object-oriented language
1991
C+ +, the team announced a new language named "Oak".
The team, known as Green Project team by Sun, demonstrated the application of their
1992
new language to control a list of home appliances using a hand-held device with a
tiny touch sensitive screen.
4
The World Wide Web CNWWJ appeared on the Internet and transformed the text-
1993
based Internet into a graphical-rich environment.
The Green Project team came up with the idea of developing Web applets (tiny
programs) using the new language that could run on all types of computers connected
to Internet
The team developed a Web browser called "Hot Java" to locate and run applet
1994
programs on Internet.
Hot Java demonstrated the power of the new language, thus making it instantly
popular among the Internet users.
Oak was renamed "Java", due to some legal snags.
1995
Java is just a name and is not an acronym.
Many popular companies including Netscape and Microsoft announced their support
to Java.
Java established itself not only as a leader for Internet programming but also as a
1996
general purpose, object-oriented programming language.
Java found its home. Sun releases Java Development Kit 1.0
Sun releases Java Development Kit 1.1 (JDK 1.1)
1997
Sun releases Java 2 with version 1.2 of the Software Development Kit (SDK 1.2)
1998
Sun releases Java 2 Platform, Standard Edition (J2SE) and Enterprise Edition (J2EE)
1999
J2SE with JDK 1.3 was released.
2000
J2SE with JDK 1.4 was released.
2002
J2SE with JDK 5.0 (instead of JDK 1.5) was released. This is known as J2SE 5.0
2004
Java SE 6
2006
Java SE 7
2011
Java SE 8
2014
Java SE 9
2017
Table: - Java Milestone
The most striking feature of the language is that it is a platform-neutral language.
5
Java is' the first programming language that is not tied to any particular hardware or
operating system.
Programs developed in Java can be executed anywhere on any system.
We can call Java as a revolutionary technology because it has brought in a fundamental
shift in how we develop and use programs. Nothing like this has happened to the software
industry before.
(Oak is a symbol of strength and chosen as a national tree of many countries like U.S.A., France,
Germany, Romania etc.)
Features for Java:-
The inventors of Java wanted to design a language which could offer solutions to some of
the problems encountered in modern programming. They wanted the language to be not only
reliable, portable and distributed but also simple, compact and interactive.
Sun Microsystems officially describes Java with the following attributes:
Platform-Independent
and Portable
Compiled and Object-
Interpreted
Robust and Secure Distributed
Familiar, Simple and
High Performance
Small
Multithreaded and Interactive Dynamic and Extensible
6
Although the above appears to be a list of buzzwords, they aptly describe the full potential of the
language. These features have made Java the first application language of the World Wide Web.
Java will also become the premier language for general purpose stand-alone applications.
Compiled and Interpreted
Usually a computer language is either compiled or interpreted.
Java combines both these approaches thus making Java a two-stage system.
First, Java compiler translates source code into what is known as bytecode instructions.
Bytecodes are' not machine instructions and therefore, in the second stage, Java
interpreter generates machine code that can be directly executed by the machine that is
running the Java program.
We can thus say that Java is both a compiled and an interpreted language.
Fig: Compiled and Interpreted
Platform-Independent and Portable
Fig (a) Platform-Independent
7
Fig (b) Portable
The most significant contribution of Java over other languages is its portability.
Java programs can be easily moved from one computer system to another, anywhere and
anytime.
Changes and upgrades in operating systems, processors and system resources will not
force any changes in Java programs. This is the reason why Java has become a popular
language for programming on Internet which interconnects different kinds of systems
worldwide.
We can download a Java applet from a remote computer onto our local system via
Internet and execute it locally. This makes the, Internet an extension of the user's basic
system providing practically unlimited number of accessible applets and applications.
Java ensures portability in two ways. First, Java compiler generates bytecode instructions
that can be implemented on any machine. Secondly, the size of the primitive data types
are machine-independent '.
Object-Oriented
Java is a true object-oriented language. Almost everything in Java is an object. All
program code and data reside within objects and classes.
Java comes with an extensive set of classes, arranged in packages that we can use in our
programs by inheritance.
The object model in Java is simple and easy to extend.
Robust and Secure
Fig: Secure
Java is a robust language.
It provides many safeguards to ensure reliable code.
It has strict compile time and run time checking for data types.
It is designed as a garbage-collected language relieving the programmers virtually all
memory management problems.
Java also incorporates the concept of exception handling which captures series errors and
eliminates any risk of crashing the system.
Security becomes an important issue for a language that is used for programming on
Internet.
Threat of viruses and abuse of resources is everywhere.
8
Java systems not only verify all memory access but also ensure that no viruses are
communicated with an applet.
The absence of pointers in Java ensures that programs cannot gain access to memory
locations without proper authorization.
Distributed
Java is designed as a distributed language for creating applicatiOI1S on networks.
It has the ability to share both data and programs.
Java applications can open and access remote objects on Internet as easily as they can do
in a local system. This enables multiple programmers at multiple remote locations to
collaborate and work together on a single project.
Simple, Small and Familiar
Java is a small and simple language.
9
Many features of C and C+ + that are either redundant or sources of unreliable code are
not part of Java. For example, Java does not use pointer, preprocessor header files, goto
statement and many others.
It also eliminates· operator overloading and multiple inheritance.
Familiarity is another striking feature of Java.
To make the language look familiar to the existing programmers, it was modeled on C
and C++ languages.
Java uses many constructs of C and C++ and therefore, Java code "looks like a C++"
code. In fact, Java is a simplified version of C++.
Fig: Simple, Small and Familiar
Multithreaded and Interactive
Multithreaded means handling multiple tasks simultaneously.
Java supports multithreaded programs. This means that we need not wait for the
application to finish one task before beginning another.
For example, we can listen to an audio clip while scrolling a page and at the same time
download an applet from a distant computer. This feature greatly improves the interactive
performance of graphical applications.
The Java runtime comes with tools that support multi process synchronization and
construct smoothly running interactive systems.
High Performance
Java is impressive for an interpreted language, mainly due to the use of intermediate
bytecode. According to Sun, Java speed is comparable to the native C/C++.
Java architecture is also designed to reduce overheads during runtime. Further, the
incorporation of multithreading enhances the overall execution speed of Java programs.
Dynamic and Extensible
Java is a dynamic language.
Java is capable of dynamically linking in new class libraries, methods, and objects.
Java can also determine the type of class through a query, making it possible to either
dynamically link or abort the program, depending on the response.
Java programs support functions written in other languages such as C and C+ +. These
functions are known as native methods. This facility enables the programmers to use the
efficient functions available in these languages. Native methods are linked dynamically at
runtime.
10
11