Chapter 1 Introduction

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

CHAPTER ONE: INTRODUCTION

History of Java
 In 1990, Sun Micro Systems Inc. (US) was conceived a project to develop software for consumer
electronic devices that could be controlled by a remote. This project was called Stealth Project but
later its name was changed to Green Project.
 In January 1991, Project Manager James Gosling and his team members met to discuss about this
project.
 Gosling thought C and C++ would be used to develop the project. But the problem he faced with
them is that they were system dependent languages. The trouble with C and C++ (and most other
languages) is that they are designed to be compiled for a specific target and could not be used on
various processors, which the electronic devices might use.
 James Gosling with his team started developing a new language, which was completely system
independent.
 This language was initially called OAK. Since this name was registered by some other company,
later it was changed to Java.
 James Gosling and his team members were consuming a lot of coffee while developing this
language. Good quality of coffee was supplied from a place called “Java Island’. Hence they fixed
the name of the language as Java.
 The symbol for Java language is cup and saucer.
 Sun formally announced Java at Sun World conference in 1995. On January 23rd 1996, JDK1.0
version was released.

The Java compiler

When you program for the Java platform, you write source code in .java files and then compile
them. The compiler checks your code against the language's syntax rules, then writes out bytecode
in .class files. Bytecode is a set of instructions targeted to run on a Java virtual machine (JVM).
In adding this level of abstraction, the Java compiler differs from other language compilers, which
write out instructions suitable for the CPU chipset the program will run on.
At runtime, the JVM reads and interprets .class files and executes the program's instructions on
the native hardware platform for which the JVM was written. The JVM interprets the bytecode
just as a CPU would interpret assembly-language instructions. The difference is that the JVM is a
piece of software written specifically for a particular platform.

1
The characteristics of Java

Simple

 Java is partially modeled on C++, but greatly simplified and improved. For instance,
pointers and multiple inheritances often make programming complicated.
 Java replaces the multiple inheritances in C++ with a simple language construct called
an interface, and eliminates pointers.
 Java uses automatic memory allocation and garbage collection, whereas C++ requires the
programmer to allocate memory and collect garbage.

Secure

o Java program cannot harm other system thus making it secure.


o Java provides a secure means of creating Internet applications.
o Java provides secure way to access web applications.
o As an Internet programming language, Java is used in a networked and distributed
environment.
o If you download a Java applet (a special kind of program) and run it on your computer, it
will not damage your system because Java implements several security mechanisms to
protect your system against harm caused by stray programs. The security is based on the
premise that nothing should be trusted.

2
Portable

 Because Java is architecture neutral, Java programs are portable. They can be run on any
platform without being recompiled. Moreover, there are no platform-specific features in
the Java language.
 In Java, the range of the integer is the same on every platform, as is the behavior of
arithmetic. The fixed range of the numbers makes the program portable. The Java
environment is portable to new hardware and operating systems. In fact, the Java compiler
itself is written in Java.
 Java programs can execute in any environment for which there is a Java run-time
system.(JVM)
 Java programs can be run on any platform (Linux, Window, Mac)
 Java programs can be transferred over world wide web (e.g. applets)

Object-oriented

 Java was designed from the start to be object-oriented. Object-oriented programming


(OOP) is a popular programming approach that is replacing traditional procedural
programming techniques.
 Everything in the world can be modeled as an object. A Java program is object-oriented
because programming in Java is centered on creating objects, manipulating objects, and
making objects work together.
 Object-oriented programming provides great flexibility, modularity, clarity, and Code reusability
through encapsulation, inheritance, and polymorphism.

Robust

o Java encourages error-free programming by being strictly typed and performing run-time
checks.
o Robust means reliable. No programming language can ensure complete reliability. Java
puts a lot of emphasis on early checking for possible errors, because Java compilers can
detect many problems that would first show up at execution time in other languages. Java
has eliminated certain types of error- prone programming constructs found in other
languages. It does not support pointers, for example, thereby eliminating the possibility of
overwriting memory and corrupting data.
o Java has a runtime exception-handling feature to provide programming support for
robustness. Java forces the programmer to write the code to deal with exceptions. Java can
catch and respond to an exceptional situation so that the program can continue its normal
execution and terminate gracefully when a runtime error occurs.

3
Multithreaded

 Multithreading is a program’s capability to perform several tasks simultaneously. For


example downloading a video file while, playing the video would be considered
multithreading. Multithread programming is smoothly integrated in Java, whereas in other
languages you have to call procedures specific to the operating system to enable
multithreading.
 Multithreading is particularly useful in graphical user interface (GUI) and network
programming. In GUI programming, there are many things going on at the same time. A
user can listen to an audio recording while surfing a Web page. In network programming,
a server can serve multiple clients at the same time. Multithreading is a necessity in
multimedia and network programming.

Architecture-neutral

 Java is not tied to a specific machine or operating system architecture.


 Machine independent i.e. Java is independent of hardware.
 Java is interpreted. This feature enables Java to be architecture-neutral, or to use an
alternative term, platform-independent. With a Java tfirtual Machine (JtfM), you can write
one program that will run on any platform.

Interpreted

 The programs are compiled into the Java tfirtual Machine code called bytecode. The
bytecode is machine-independent and can run on any machine that has a Java interpreter,
which is part of the Java tfirtual Machine (JtfM).
 With Java, you compile the source code once, and the bytecode generated by a Java
compiler can run on any platform with a Java interpreter. The Java interpreter translates
the bytecode into the machine language of the target machine.
 Java supports cross-platform code through the use of Java byte code.
 Byte code can be interpreted on any platform by JVM.

High performance

 Byte codes are highly optimized.


 JVM can execute them much faster.
 The new JtfM uses the technology known as just-in-time compilation. It compiles byte code
into native machine code, stores the native code, and re invokes the native code when its
byte code is executed. Sun recently developed the Java Hot Spot Performance Engine,
which includes a compiler for optimizing the frequently used code.

4
Distributed

 Distributed computing involves several computers working together on a network. Java is


designed to make distributed computing easy. Since networking capability is inherently
integrated into Java, writing network programs is like sending and receiving data to and
from a file.
 Java was designed with the distributed environment.
 Java can be transmitted & run over internet.

Dynamic

o Java was designed to adapt to an evolving environment. New class can be loaded on the
fly without recompilation. There is no need for developers to create, and for users to install,
major new software versions.

Object Oriented Approach

Abstraction
An essential element of object-oriented programming is abstraction. Abstraction is a powerful
methodology to manage complex systems. Abstraction is managed by well-defined objects and
their hierarchical classification. For example a car itself is a well-defined object, which is
composed of several other smaller objects like a gearing system, steering mechanism, engine,
which are again have their own subsystems. But for humans car is a one single object, which can
be managed by the help of its subsystems, even if their inner details are unknown.

Java is an object oriented language because it provides the features to implement an object oriented
model. These features include encapsulation, inheritance and polymorphism.

OOP is about developing an application around its data, i.e. objects which provides the access to
their properties and the possible operations in their own way.

Principles of OOP

1) Encapsulation

Encapsulation is to hide the implementation details from users. If a data member is private it means it can
only be accessed within the same class. No outside class can access private data member (variable) of other
class. Encapsulation is:

o Binding the data with the code that manipulates it.


o It keeps the data and the code safe from external interference and misuse.

5
2) Inheritance
 The mechanism by which an object acquires the some/all properties of another object.
 It supports the concept of hierarchical classification.

3) Polymorphism

 Polymorphism (from Greek, meaning “many forms”) is a feature that allows one interface
to be used for a general class of actions.
 Polymorphism means to process objects differently based on their data type.
 In other words it means one method with multiple implementations, for a certain class of
action. And which implementation to be used is decided at runtime depending upon the
situation (i.e., data type of the object)
 This can be implemented by designing a generic interface, which provides generic methods
for a certain class of action and there can be multiple classes, which provides the
implementation of these generic methods.

 Polymorphism could be static and dynamic. Overloading is static polymorphism while,


overriding is dynamic polymorphism.

 Overloading means two methods having same method name but take different input
parameters. This called static because, which method to be invoked will be decided at
the time of compilation.
 Overriding means a derived class is implementing a method of its super class.

Java editors
To write Java programs, a text editor will be needed.
 Notepad,
 net beans,
 eclipse, and
 IntelliJ are the most frequently used and popular java code editors.

6
Naming Conventions
 Naming conventions specify the rules to be followed by a Java programmer while
writing the names of packages, classes, methods etc.
 Package names are written in small letters.
e.g.: java.io, java.lang, java.awt etc
 Each word of class name and interface name starts with a capital
e.g.: Sample, AddTwoNumbers
 Method names start with small letters then each word start with a
capital
e.g.: sum (), sumTwoNumbers (), minValue ()
 Variable names also follow the same above method rule
e.g.: sum, count, totalCount
 Constants should be written using all capital letters
e.g.: PI, COUNT
 Keywords are reserved words and are written in small letters.
e.g.: int, short, float, public, void

You might also like