The Best Coaching Centre
Introduction of Java
A team
of 5 members of Sun Microsystems Inc. - James Gosling, Patrick
Naughton, Chris Warth, Ed Frank and Mike Sheridan developed a programming
language named OAK in 1991 to program for an electronic devices (Home
Appliances). “Oak” was renamed as Java in 1995. Java is a 3rd Generation
OOP language as well as a leader for Internet Programming.
Type of
Java Programs
1.
Application Program
A Stand
Alone program that runs as a true application without a browser using JVM is
known as Application Program which usually contains a main function.
2.
Applet Program
A Java
program that can be included in an HTML page which can be executed on a web
browser. It uses a java.applet package to add small interactive components to a
webpage.
Translator
The
computer understands only Machine Language. So the programs written in any
programming language (High-Level Language or Object-Oriented Language) must be
translated into a Machine Language, so that the computer can understand an
execute it.
Translation
Process in High-Level Languages:
|
Source Program in HLL (Source Code) |
à |
Compiler (All at Once) |
à |
Machine Language (Machine Code) or (Object Code) |
OR
|
Source Program in HLL (Source Code) |
à |
Interpreter (Line by Line) |
à |
Machine Language (Machine Code) or (Object Code) |
Java
Program Translation Process:
Java
uses two translators
1.
Java Compiler
2.
Java Interpreter
|
Java Source Program |
à |
Java Compiler (javac) |
à |
Java Byte Code |
à |
Java Interpreter (java JVM |
à |
Machine Language |
|
Source Code .java file |
|
|
|
(Native Code) .class file |
|
|
|
(Machine Code) or (Object Code) |
Java
program is first translated by Java Compiler which converts the given Source
Code into Java Byte Code. The Java Byte Code is a Native Code which is a common
for all types of machines irrespective of the hardware or software used in a
machine. In next step, Java Interpreter (JVM) will translate the Java Byte Code
into Machine Language which can be executed on end-user computer.
i.e.
Java programs using a compiler (javac) for converting Java source code (.java
files) to Java bytecode (.class files). Once this is done, Java Virtual
Machine (JVM) loads the .class files at run time and converts them to a machine
understandable code using an interpreter.
Java is
a Platform-Independent Language which means the program written in a
Java Language can be executed on any kind of platform irrespective of the
hardware or software used in a machine without any changes in Java program. It
also known as WORA (Write Once Run Anywhere).
Java
Development Kit (JDK) is a bundle of software
components that is used to develop Java based applications includes JRE, and
the compilers and tools (like JavaDoc, and Java Debugger) to create and compile
programs.
JRE is
an acronym for Java Runtime Environment. It is an implementation of the
Java Virtual machine, which actually executes Java programs. It includes the JVM
(Java Virtual machine), core libraries and other additional components
to run applications and applets written in Java.
The JDK
is a superset of the JRE, and contains everything that is in the JRE,
plus tools such as the compilers and debuggers necessary for developing applets
and applications. It also includes browser plugins for Applet
execution. The JRE does not contain tools and utilities such as compilers or debuggers
for developing applets and applications.
Usually,
when you only care about running Java programs on your browser or computer you
will only install JRE. That's all you need. On the other hand, if you are
planning to do some Java development, you will also need JDK.
Features
of Java:
1.
Simple Coding
2.
Robust – Java provides a automatic memory management and a garbage collection
along with strong exception handling (checking & handling for errors)
mechanism that makes it robust.
3.
Secured – it support many in-built security that makes the system secure from
crash.
4.
Object Oriented – It support OOPs concepts.
5.
Platform Independent
6. WORA
- Write Once Run Anywhere
Object
Oriented Programming Concept or Principles of OOPs:
1. Object - An identifiable entity with two
characteristics – State and Behavior is known as Object. A State represents the
properties of an object and Behavior represents What task an object can do. An
Object is an Instance of a Class. It contains all the Instance Variables which
is defined in a same class as a non-static variable.
2.
Class - Class is a blueprint or template
for an Object. Class works as an Object Factory. A class defines the State and
Behavior of an Object. A class is a collection of Data and Methods together as
a single unit. Class is also used to create a new User Defined Data type which
contains similar or non-similar type of values. i.e. A class is used to create
a new data type which can contains a different type of values. It also known as
Composite Data Type.
3.
Encapsulation - The process of wrapping up of Data
& its associated functions which work on the same data is known as
Encapsulation. To implement the concept of Encapsulation, a class is used.
4. Data
Abstraction - It specifies that the necessary
things will be available for use without knowing the background things like how
it is working. It is implemented using private and protected access specifier
in Java. It actually hides the data from being accessible in other classes.
5.
Polymorphism - Polymorphism is the concept
where an object behaves differently in different situations. There are two
types of polymorphism:
Compile-Time
Polymorphism (Early Binding or Static Binding or Linking) Implemented through
Function Overloading, Constructor Overloading & Operator Overloading &
Linking is done at Compile-Time.
Run-Time
Polymorphism (Late Binding or Dynamic Binding or Linking) Where Linking is done
at Run-Time.
Runtime
polymorphism is implemented when we have “IS-A” relationship between objects.
This is also called as method overriding because subclass has to override the
super class method for runtime polymorphism.
6.
Inheritance - Reusability is yet another
aspect of OOP paradigm. It is always nice if we could reuse something that
already exists rather than creating the same all over again. Java classes can
be reused in several ways. This is basically done by creating new classes,
reusing the properties of existing ones. The mechanism of deriving a new class
from an old one is called Inheritance. The old class is known as the base
class or super class or parent class and the new one is called the subclass or
derived class or child class.
Inheritance
is implemented using a keyword extends for a
class and a keyword implements for an Interface in Java.
The inheritance
allows subclasses to inherit all the variables and methods of their parent
classes.
Inheritance
may take different forms:
1.
Single inheritance (only
one super class)
2.
Multiple inheritance
(several super classes)
3.
Hierarchical inheritance
(one super class, many subclasses)
4.
Multilevel inheritance
(Derived from a derived class)
5.
Hybrid inheritance


0 Comments