Java Is Object Oriented Prog. Lang Java Is Object Oriented Prog. Lang
Java Is Object Oriented Prog. Lang Java Is Object Oriented Prog. Lang
Lang
History of Java
Features of Java
1. Simple
2. Platform independent
3. Architectural neutral
4. Portable
5. Multi threading
6. Distributed
7. Networked
8. Robust
9. Dynamic
10. Secured
11. High performance
12. Interpreted
13. Object Oriented Programming Language
1.Simple
Simple: JAVA is simple because of the following factors:
i. JAVA is free from pointers hence we can achieve less development
time and less execution time [whenever we write a JAVA program we
write without pointers and internally it is converted into the equivalent
pointer program].
ii. Rich set of API (application programming interface) is available to
develop any complex application.
iii. The software JAVA contains a program called garbage collector
which is always used to collect unreferenced (unused) memory
location for improving performance of a JAVA program. [Garbage
collector is the system JAVA program which runs in the background
along with regular JAVA program to collect unreferenced memory
locations by running at periodical interval of times for improving
performance of JAVA applications.
iv. JAVA contains user friendly syntaxs for developing JAVA
applications.
2. Platform Independent
A program or technology is said to be platform independent if and only if
which can run on all available operating systems.
The languages like C, Cpp are treated as platform dependent languages since
these languages are taking various amount of memory spaces on various
operating systems [the operating system dos understands everything in the
form of its native format called Mozart (MZ)
whereas the operating system Unix understands everything in its native
format called embedded linking format (elf). When we write a C or Cpp
program on DOS operating and if we try to transfer that program to Unix
operating system, we are unable to execute since the format of these
operating systems are different and more over the C, Cpp software does not
contain any special programs which converts one format of one operating
system to another format of other operating system].
The language like JAVA will have a common data types and the common
memory spaces on all operating systems and the JAVA software contains the
special programs which converts the format of one operating system to
another format of other operating system.
Hence JAVA language is treated as platform independent language.
3. Architectural Neutral
A language or technology is said to
be architectural neutral which can
run on any available processors in
the real world. The language like C,
Cpp are treated as architectural
dependent. The language like JAVA
can run on any of the processor
irrespective of their architecture and
vendor.
4. Portable
Portable: A portable language is one
which can run on all processors
irrespective their architectures and
providers. The language like C, Cpp
are treated as non-portable
languages whereas the java is called
portable language.
Portability = platform independent +
architectural neutral
5. Distributed
A service is said to be a distributed
service which runs in multiple servers and
that service can be accessed by n number
of clients across the globe. In order to
develop distributed applications we must
require architecture called trusted network
architecture. To develop these applications
we require a technology called J2EE.
Distributed applications are preferred by
large scale organizations.
6. Robust
Java program will not crash easily
because of its exception handling
and its memory management
features.
Memory allocations- JVMs class
loader subsystem
Memory de-allocations- JVMs
garbage collector.
7. High Performance
OOPs Principles
1.
2.
3.
4.
5.
6.
7.
8.
Class.
Object.
Inheritance.
Data Abstraction.
Data Encapsulation.
Polymorphism.
Dynamic Binding.
Message Passing.
1.CLASS
A class is a way of binding the data
members(variables) and associated methods in a single
unit.
Any JAVA program if we want to develop then that should
be developed with respective class only i.e., without class
there is no JAVA program.
In object oriented programmings, generally we write two
types of methods. They are member methods and nonmember methods.
A member method is one which is comes under the
scope of the class. In JAVA we use only member methods.
Non-member methods are those which are not comes
under the scope of the class. JAVA does not allow nonmember methods at all.
2.Object
OBJECT: In order to store the data for the data members of
the class, we must create an object.
1. Instance (instance is a mechanism of allocating sufficient
amount of memory space for datamembers of a class) of a
class is known as an object.
2. Class variable is known as an object.
3. Grouped item (grouped item is a variable which allows us
to store more than one value) is known as an object.
4. Value form of a class is known as an object.
5. Logical runtime entity is known as an object.
6. Real world entities are called as objects.
NOTE:
JAVA always follows dynamic memory allocation but not
static memory allocation.
In order to create a memory space in JAVA we must use an
operator called new. This new operator is known as dynamic
memory allocation operator.
Object Diagram
Object
VARIABLES IN JAVA
A variable is an identifier whose value
will be changed during execution of the
program.
Rules for writing variables:
i. First letter must be an alphabet.
ii. No special symbols are allowed
except underscore.
iii. No keywords should use as variable
names.
STATIC VARIABLES
2) Programmatically instance
variable
declaration should not be
preceded
by keyword static.
2) Programmatically static
variable
declaration must be preceded by
keyword static.
3. Data Abstraction
Data abstraction is a mechanism of
retrieving the essential details
without dealing with background
details.
Note: In real world we have three
levels of abstractions. They are
1. Physical level,
2. Conceptual/logical level and
3. View level abstraction.
4. Data Encapsulation
Data encapsulation is the process of
wrapping up on data and associated
methods in a single unit.
Data encapsulation is basically used for
achieving data/information hiding i.e.,
security.
When we want to send the data from client
to the server we must always send in the
from of JAVA object only. Since, by default
the JAVA object is in encrypted form
5. Inheritance
Inheritance is the process of taking the
features(data members +methods) from
one class to another class.
The class which is giving the features is
known as base/parent class.
The class which is taking the features is
known as derived/child/sub class.
Instance is known as sub classing or
derivation or extendable classes or
reusability.
Advantages of INHERITANCE
I. Application development time is very
less.
II. Redundancy (repetition) of the code
is reducing. Hence we can get less
memory cost and consistent result.
III. Instrument cost towards the project
is reduced.
IV. We can achieve the slogan write
ones reuse/run anywhere (WORA) of
JAVA.
Method Overloading
Method Overloading :method name is same , signature is different and
return type may or may not be different.
signature : sum(int a, int b)
sum(float a, float b)
sum(int a, float b)
sum(float a,int b)
sum(int a, int b, int c)
ex:
class A{
public void display(float a, float b){
//block of stmts
s.o.pln("skdfjdf");
}
//overloaded method
public int display(int a, int b){
}
Method Overriding
Method Overriding:
Method heading is same , but body is different is known as
Method overriding.
Example :
class Sum{
public void sum(){
System.out.println("I am from sum method of Sum class");
}
}
class Sub extends Sum{
// overridden method
public void sum(){
System.out.println("I am from sum method of Sub class");
}
}
6. Polymorphism
Polymorphism is a process of representing
one form in many forms.
In object oriented programming's , we
have two types of polymorphisms. They
are Static polymorphism and
Dynamic polymorphism.
Static polymorphism we are achieving
through method overloading.
Dynamic polymorphism we are achieving
through method overriding.
Static Polymorphism
The term static polymorphism is associated
with overloaded methods because it gives
the impression that a single named method
will accept a number of different argument
types. In fact, each overloaded method is
separate and the compiler can see the
difference between them.
In this case, the argument types are fixed
at compile time and are considered static.
This has nothing to do with the Java
keyword static.
Dynamic Polymorphism
Dynamic polymorphism is where a class
overrides a super class method or implements
an interface. For example, any class may
override the any method called void sum()
method and provide its own implementation,
and this is known at compile time. However, for
a simple Java program that instantiates a series
of objects and calls their void sum() method,
the compiler does not consider the object
references differently. Any differences in the
objects' void sum() implementations are only
seen at runtime, so they are considered
dynamic.
7. Dynamic Binding
8. Message Passing
CONSTANTS in java
Constant is an identifier whose value cannot
be changed during execution of the program.
In JAVA to make the identifiers are as
constants, we use a keyword called final.
Final is a keyword which is playing an
important role in three levels. They are at
variable level, at method level and at class
level.
i. When we dont want to change the value of
the variable, then that variable must be
declared as final.