Unit 1 Introduction To Java: Structure
Unit 1 Introduction To Java: Structure
Unit 1
Unit 1
Introduction to Java
Structure
1.1 Introduction
Objectives
1.2 History of Java
1.3 Features of Java
1.4 Java Magic: Byte Code
1.5 Summary
1.6 Terminal Questions
1.7 Answers
1.1 Introduction
Java is a simple language that can be learned easily, even if you have just
started programming. A Java programmer need not know the internal of
Java. The syntax of Java is similar to C++. Unlike C++, in which the
programmer handles memory manipulation, Java handles the required
memory manipulations, and thus prevents errors that arise due to improper
memory usage. This unit orients you towards understanding of basic Java
features. To further enrich your knowledge about the history and basic
features of Java read Java 2 Complete Reference.
Objectives
After studying this unit, you should be able to:
describe the history of Java
explain the features of Java
explain the Java Magic Byte Code
Page No. 1
Unit 1
that the existing programming languages were not well suited for use in
consumer electronics. The chief programmer of Sun Microsystems, James
Gosling, was given the task of creating the software for controlling consumer
electronic devices. The team wanted a fundamentally new way of computing,
based on the power of networks, and wanted the same software to run on
different kinds of computer, consumer gadgets and other devices. Patenting
issues gave a new name to Oak Java.
During that period, Mosaic, the first graphical browser, was released. Nonprogrammers started accessing the World Wide Web and the Web grew
dramatically. People with different types of machines and operating systems
started accessing the applications available on the web. Members of the
Oak team realized that Java would provide the required cross-platform
independence that is, independence from the hardware, the network, and
the operating system. Very soon, Java became an integral part of the web.
Java works just everywhere, from the smallest devices to supercomputer.
Java technology components (programs) do not depend on the kind of
computer, telephone, television, or operating system they run on. They work
on any kind of compatible device that supports the Java platform.
Self Assessment Questions:
1. The earlier name of Java was _____.
2. The members of Green Project were _____, _____ and _____.
3. _____ is the first graphical browser.
Page No. 2
Unit 1
executed, the code is fetched into the memory and interpreted on the users
machine. As an interpreted language, Java has simple syntax.
When you compile a piece of code, all errors are listed together. You can
execute only when all the errors are rectified. An interpreter, on the other
hand, verifies the code and executes it line by line. Only when the execution
reaches the statement with error, the error is reported. This makes it easy
for a programmer to debug the code. The drawback is that this takes more
time than compilation.
Compilation is the process of converting the code that you type, into a
language that the computer understands - machine language. When you
compile a program using a compiler, the compiler checks for syntactic errors
in code and list all the errors on the screen. You have to rectify the errors
and recompile the program to get the machine language code. The Java
compiler compiles the code to a bytecode that is understood by the Java
environment.
Bytecode is the result of compiling a Java program. You can execute this
code on any platform. In other words, due to the bytecode compilation
process and interpretation by a browser, Java programs can be executed on
a variety of hardware and operating systems. The only requirement is that
the system should have a Java-enabled Internet browser. The Java
interpreter can execute Java code directly on any machine on which a Java
interpreter has been installed.
Thanks to bytecode, a Java program can run on any machine that has a
Java interpreter. The bytecode supports connection to multiple databases.
Java code is portable. Therefore, others can use the programs that you
write in Java, even if they have different machines with different operating
systems.
Java forces you to handle unexpected errors. This ensures that Java
programs are robust (reliable), bug free and do not crash.
Due to strong type-checking done by Java on the users machine, any
changes to the program are tagged as error and the program will not
execute. Java is, therefore, secure.
Java is faster than other interpreter-based language like BASIC since it is
compiled and interpreted.
Sikkim Manipal University - DDE
Page No. 3
Unit 1
Page No. 4
Unit 1
Page No. 5
Unit 1
Simple
Secure
Portable
Object-oriented
Robust
Multithreaded
Architecture-neutral
Interpreted
High performance
Distributed
Dynamic
Two of these buzzwords have already been discussed: secure and portable.
Let's examine what each of them implies.
Simple
Java was designed to be easy for the professional programmer to learn and
use effectively. Assuming that you have some programming experience, you
will not find Java hard to master. If you already understand the basic
concepts of object-oriented programming, learning Java will be even easier.
Best of all, if you are an experienced C++ programmer, moving to Java will
require very little effort. Because Java inherits the C/C++ syntax and many
of the object-oriented features of C++, most programmers have little trouble
learning Java. Also, some of the more confusing concepts from C++ are
either left out of Java or implemented in a cleaner, more approachable
manner. Beyond its similarities with C/C++, Java has another attribute that
makes it easy to learn: it makes an effort not to have surprising features. In
Java, there are some clearly defined ways to accomplish a given task.
Object-Oriented
Although influenced by its predecessors, Java was not designed to be
source-code compatible with any other language. This allowed the Java
team the freedom to design with a blank slate. One outcome of this was a
clean, usable, pragmatic approach to objects. Borrowing liberally from many
seminal object-software environments of the last few decades, Java
manages to strike a balance between the purists "everything is an object"
paradigm and the pragmatists "stay out of my way" model. The object
Sikkim Manipal University - DDE
Page No. 6
Unit 1
model in Java is simple and easy to extend, while simple types, such as
integers, are kept as high performance non objects.
Robust
The multiplatformed environment of the Web places extraordinary demands
on a program, because the program must execute reliably in a variety of
systems. Thus, the ability to create robust programs was given a high
priority in the design of Java. To gain reliability, Java restricts you in a few
key areas, to force you to find your mistakes early in program development.
At the same time, Java frees you from having to worry about many of the
most common causes of programming errors. Because Java is a strictly
typed language, it checks your code at compile time. However, it also
checks your code at run time. In fact, many hard-to-track-down bugs that
often turn up in hard-to-reproduce run-time situations are simply impossible
to create in Java. Knowing that what you have written will behave in a
predictable way under diverse conditions is a key feature of Java. To better
understand how Java is robust, consider two of the main reasons for
program failure: memory management mistakes and mishandled
exceptional conditions (that is, run-time errors). Memory management can
be a difficult, tedious task in traditional programming environments. For
example, in C/C++, the programmer must manually allocate and free all
dynamic memory. This sometimes leads to problems, because
programmers will either forget to free memory that has been previously
allocated or, worse, try to free some memory that another part of their code
is still using. Java virtually eliminates these problems by managing memory
allocation and de-allocation for you. (In fact, de-allocation is completely
automatic, because Java provides garbage collection for unused objects.)
Exceptional conditions in traditional environments often arise in situations
such as division by zero or "File not found," and they must be managed with
clumsy and hard-to-read constructs. Java helps in this area by providing
object-oriented exception handling. In a well-written Java program, all runtime errors can and should be managed by your program.
Multithreaded
Java was designed to meet the real-world requirement of creating
interactive, networked programs. To accomplish this, Java supports
multithreaded programming, which allows you to write programs that do
many things simultaneously. The Java run-time system comes with an
Sikkim Manipal University - DDE
Page No. 7
Unit 1
Page No. 8
Unit 1
1.5 Summary
Java is :
o
Page No. 9
Unit 1
1.7 Answers
Self Assessment Questions:
1. Oak
2. Patrick Naughton, Mike Sheridan, James Gosling
3. Mosaic
4. Compilation
5. Portable
6. Secure
7. Multithreading
8. Web
9. Compiled and Interpreted
Terminal Questions:
1. Java is a simple, object-oriented, distributed, interpreted, robust, secure,
architecture neutral, portable, high-performance, multi-threaded and
dynamic language. (Refer section 1.3)
2. Bytecode is a highly optimized set of instructions designed to be
executed by the Java run-time system, which is called the Java Virtual
Machine (JVM). (Refer section 1.3)
Page No. 10