Course Contents:
- Introduction
- History and development of java
- Platform independence
- Byte code
- Object-oriented characteristics
- How to write and execute?
History and development of
Java
Year
|
Development
|
1990
|
Sun
Microsystems decided to develop special software that could used to
manipulate consumer electronic devices.
|
1991
|
After
exploring the possibility of using the most popular object-oriented language
C++, the team of Sun Microsystems announced a new language “OAK”.
|
1992
|
They
use their new language to control a list of home appliances using hand held
devices with a tiny touch sensitive screen.
|
1993
|
The
team came up with idea of developing web applets (tiny programs) using the
new language that could run on all types of computers connected to internet.
|
1994
|
The
team developed a web browser called “HotJava” to locate and run applet
program on internet. This becomes the most popular among the internet users.
|
1995
|
Oak
was renamed “Java”. Java is just a name not an acronym and many popular
companies like Netscape and Microsoft also support this language.
|
Platform Independence
If the software/program
written in particular languages for a particular platform run in any other platform
without changing the program, then we can say such types of programming
language as platform independence i.e. run on any platform without changing the
original program.
Java programs can be easily
moved from one computer system to another, anywhere and anytime. Changes in the
operating systems, processors and system resources will not force any changes
in java program. So the java is the platform independent language.
Due to its independence
nature java becomes popular language for programming on internet which interconnects
different kinds of systems worldwide. Java becomes platform independent due to its
two properties:
- Java compiler generates
bytecode that can be implemented on any machine.
- The size of primitive data
types are machine independent.
Bytecode
When the program written in
java is compiled, the compiler generates an intermediate code instead of
directly to platform specific machine code. This intermediate code is known as
bytecode and is machine independent. This byte code is then translated to
machine code by a interpreter known as Java virtual machine which is
incorporated with every operating system.
Characteristics of
Object-Oriented language
- Emphasis is on data rather than procedures.
- Programs are divided into objects.
- Data structures are designed such that they characterize the objects.
- Functions & data are tied together in the data structures so that data abstraction is introduced in addition to procedural abstraction.
- Data is hidden & can’t be accessed by external functions.
- Object can communicate with each other through f unction.
- New data & functions can be easily added.
- Follows Bottom up approach.
Features of Object Oriented
Language:
1.Objects
Objects are the entities in
an object oriented system through which we perceive the world around us. We
naturally see our environment as being composed of things which
have recognizable identities
& behavior. The entities are then represented as objects in the program.
They may represent a person, a place, a bank account, or any item that the
program must handle. For example,
Automobiles are objects as they have size, weight, color etc. as attributes (i.e.
data) and starting, pressing the brake, turning the wheel, pressing accelerator
pedal etc. as operation (that is functions).
- Understanding the real world and a practical base for designers
- Decomposition of a problem into objects depends on the nature of problem.
2. Classes
A class is a collection of objects
of similar type. For example, manager, peon, secretary, clerk are member of the
class employee and class vehicle includes objects car, bus, etc.
It defines a data type, much
like a struct in C programming language and built in data type(int char, float
etc). It specifies what data and functions will be included in objects of that
class. Defining class doesn’t create an object but class is the description of
objects attributes and behaviors.
Person Class : Attributes: Name,
Age, Sex etc.
Behaviors: Speak(),
Listen(), Walk()
Vehicle Class: Attributes:
Name, model, color, height etc
Behaviors: Start(), Stop(),
Accelerate() etc.
When class is defined,
objects are created as
<classname>
<objectname> ;
If employee has been def
ined as a class, then the statement
employee manager; Will
create an object manager belonging to the class employee.
Each class describes a possibly
infinite set of individual objects; each object is said to be an instance of
its class and each instance of the class has its own value for each attribute
but shares the attribute name and operations with other instances of the class.
The following point gives the idea of class:
- A class is a template that unites data and operations.
- A class is an abstraction of the real world entities with similar properties.
- Ideally, the class is an implementation of abstract data type.
3. Encapsulation and Data
Abstraction
The wrapping up of data and
function into a single unit is called encapsulation. Encapsulation is most striking
feature of a class. The data is not accessible from outside of class. Only
member function can access data on that class. The insulation of data from
direct access by the program is called data hiding. That is data can be hidden making
them private so that it is safe from accidental alteration.
Abstraction is representing essential
features of an object without including the background details or explanation.
It focuses the outside view of an object, separating its essential behavior from
its implementation.
The class is a construct in
C++ for creating user-defined data types called Abstract Data Types (ADT).
4. Inheritance:
Inheritance is the process
by which objects of one class acquire the characteristics of object of another class.
In OOP, the concept of inheritance provides the idea of reusability. We can use
additional features to an existing class without modifying it. This is possible
by deriving a new class (derived class) from the existing one (base class). This
process of deriving a new class from the existing base class is called
inheritance.
It supports the concept of
hierarchical classification. It allows the extension and reuse of existing code
without having to rewrite the code.
5.Polymorphism
Polymorphism means “having many
forms”. The polymorphism allows different objects to respond to the same message
in different ways, the response specific to the type of object.
Polymorphism is important
when object oriented programs dynamically creating and destroying the objects in
runtime. Example of polymorphism in OOP is operator overloading, function overloading.
For example, operator symbol
„+ is used for arithmetic operation between two numbers, however by overloading
(means given additional job) same operator „+ can be used for different purpose
like concatenation of strings.
Dynamic Biding
Binding refers to the linking
a function call to the code to be executed in response to the call.
Dynamic binding means that
the code associated with a given function call is not known until the time of
the call at run time. It is associated with polymorphism & inheritance.
6.Message Passing
An Object-Oriented program
consists of set of objects that communicate with each other. Object communicates
with each other by sending and receiving message (information).
A message for an object is a
request for execution of a procedure and therefore will invoke a function or procedure
in receiving object that generate the desired result. Message passing involves specifying
the name of the object name of the function (message) and the information to be
sent.
How to write and execute
java program
The following steps are
involved during writing and executing java program.
- Write a java program on any java editor or notepad
- Save it inside the folder bin which is located at this path C:\Program Files\Java\jdk1.6.0\bin\
- The name of the file must be same as the class name with extension .java
Procedure for compiling and
running the java program
- Open command mode
- Set command mode path as C:\Program Files\Java\jdk1.6.0\bin\
- Type <javac>space<filename.java> in command mode to compile the java program.
- If there exist any error, compiler generates errors and removes that error. This process continues till the program becomes error free.
- If the program is error fr ee then in compilation phase the compiler generates the intermediate code of the original source code with extension <filename.class>. Which is known as bytecode?
- Then run the program with command <java>space<filename>.
- Then you can see the required output.
No comments:
Post a Comment