Java Programming Notes CO4I
Chapter-1
1. Basic concepts of object oriented programming
The concepts of object oriented programming are as follows:
1. Classes
A class consist of data and methods.
A class is a collection of objects of similar type of objects.
Classes are user defined data.
Once class has been defined,we can create any number of object belonging to that class.
Eg.
class Person
{
String name;
int age;
void accept( String n,int a)
{
name=n;
age=a;
}
void display()
{
System.out.println(“Name=”+name);
System.out.println(“Age=”+age);
}
2. Objects
Objects are basic run time entities in object oriented system. They may represent a place, a bank
account, a table of data or any item that the program must handle.
Objects are variables of class.
Objects are generally used to access members (data and methods) of class.
Eg. Person p =new Person()
Here p is an object of Person class
3. Data abstraction
Data abstraction refers to act of representing essential features without including background
details or explanations.
Classes use the concept of abstraction and are defined as the list abstraction attribute such as size,
weight and cost and function to operate on this attribute. They encapsulate all essential properties
of objects that they are to be created since the class used the concept of data abstraction they are
1
, Java Programming Notes CO4I
known as abstract data types(ADT).
4. Data encapsulation
Data encapsulation means wrapping of data and functions into a single unit. It is most striking
feature of class. The data is not accessible to the outside world and only functions which are
wrapped in the class can access it.
Thus insulation of data from direct access from program is called data hiding.
5. Inheritence
Inheritence is the process by which object of one class can acquire the properties of the objects of
other classes. Inheritence means one class of object inherits the data and behavoiur(methods)
from another class .
The old is refered as a base class and new one is called as derived class. The new class has
combined features of both the classes.
6. Polymorphism
Polymorphism is the ability to take more than one form.
For eg: an operation may demonstrate different behaviour in different instance. The behavior
depends upon the type of data used in the operation. As addition of two integer numbers gives
addition while addition of two strings gives concatenation.
7. Dynamic binding
Binding refers to the linking of a procedure call to the Procedure definition (code) to be executed
in response to the call.
Binding is classified as static binding and dynamic binding.
Static binding means that the code associated with given procedure call is known at compile time.
Dynamic binding means that the code associated with given procedure call is not known until the
time of the call at run time.
Dynamic binding associated with polymorphism and inheritance.
8. Message Passing
Message passing involves specifying the name of object, the name of the method and the
information to be sent.
Example:.
p.accept(“abc”,18);
Here p is an object of Person class.
Accept is message
Arguments is information
1.1 Benefits of OOP
2
, Java Programming Notes CO4I
OOP emphasis on data rather than procedure.
Programs are divided into objects.
Objects are characterized by functions or data structure that operates on data.
Functions that operates on the data of an object are tied together in the data structure.
Data is hidden and cannot be accessed by external functions.
Objects may communicate with each other through functions.
New data and functions can be easily added whenever necessary.
Follows bottom-up approach in program design.
2. Java Features:
1. Compiler/Interpreter
Java Source Code (.java file) is compiled to byte codes(.class file) that are interpreted by a Java
virtual machines (JVM) .
This provides portability to any machine for which a virtual machine has been written.
The two steps of compilation and interpretation allow for extensive code checking and improved
security.
Java source code Java Compiler Byte code Interpreter Machine code
(.java file) (javac) (.class file) (java)
2. Platform Independence
Java byte code achieves the Write-Once-Run-Anywhere approach so running on different
platforms is possible. As we know java is both compiler & interpreter based language. Once the
java code also known as source code is compiled, it gets converted to Byte Code which is
portable & can be easily executed on all operating systems. Byte code generated is basically
represented in hexa decimal format in .class file. This .class file contains bytecode which is
executed JVM(Java virtual machine) which is a runtime environment for java. Now this .class file
can be run in any environment with the help of JVM and JVM convert bytecode into native
code.
Java Virtual Machine like its real counter part, executes the program and generate output. To
execute any code, JVM utilizes different components. JVM is divided into several components
like the stack, the garbage-collected heap, the registers and the method area.
3
, Java Programming Notes CO4I
Above fig. shows that JVM for different operating system is different.The JVM must translate the
bytecode into machine language, and since the machine language depends on the operating
system being used, it is clear that the JVM is platform (operating system) dependent – in other
words, the JVM is not platform independent.
3. Object Oriented
Supports all the concepts of object oriented programming language like object classes,
polymorphism etc.
Java is pure object oriented Language – Each and every code in java comes under a class,
including main().
Following is the example shows that even main function is comes under a class:
class Demo
{
public static void main(String args[])
{
System.out.println(“hello”);
}
}
4. Robust and Secure
Exception handling built-in, strong type checking (that is, all data must be declared an explicit
type), local variables must be initialized.
Automatic Memory Management
o Automatic garbage collection - memory management handled by JVM.
Java is secure as several dangerous features of C & C++ eliminated
o No memory pointers
o No preprocessor
o Array index limit checking
5.Dynamic Binding
4
Chapter-1
1. Basic concepts of object oriented programming
The concepts of object oriented programming are as follows:
1. Classes
A class consist of data and methods.
A class is a collection of objects of similar type of objects.
Classes are user defined data.
Once class has been defined,we can create any number of object belonging to that class.
Eg.
class Person
{
String name;
int age;
void accept( String n,int a)
{
name=n;
age=a;
}
void display()
{
System.out.println(“Name=”+name);
System.out.println(“Age=”+age);
}
2. Objects
Objects are basic run time entities in object oriented system. They may represent a place, a bank
account, a table of data or any item that the program must handle.
Objects are variables of class.
Objects are generally used to access members (data and methods) of class.
Eg. Person p =new Person()
Here p is an object of Person class
3. Data abstraction
Data abstraction refers to act of representing essential features without including background
details or explanations.
Classes use the concept of abstraction and are defined as the list abstraction attribute such as size,
weight and cost and function to operate on this attribute. They encapsulate all essential properties
of objects that they are to be created since the class used the concept of data abstraction they are
1
, Java Programming Notes CO4I
known as abstract data types(ADT).
4. Data encapsulation
Data encapsulation means wrapping of data and functions into a single unit. It is most striking
feature of class. The data is not accessible to the outside world and only functions which are
wrapped in the class can access it.
Thus insulation of data from direct access from program is called data hiding.
5. Inheritence
Inheritence is the process by which object of one class can acquire the properties of the objects of
other classes. Inheritence means one class of object inherits the data and behavoiur(methods)
from another class .
The old is refered as a base class and new one is called as derived class. The new class has
combined features of both the classes.
6. Polymorphism
Polymorphism is the ability to take more than one form.
For eg: an operation may demonstrate different behaviour in different instance. The behavior
depends upon the type of data used in the operation. As addition of two integer numbers gives
addition while addition of two strings gives concatenation.
7. Dynamic binding
Binding refers to the linking of a procedure call to the Procedure definition (code) to be executed
in response to the call.
Binding is classified as static binding and dynamic binding.
Static binding means that the code associated with given procedure call is known at compile time.
Dynamic binding means that the code associated with given procedure call is not known until the
time of the call at run time.
Dynamic binding associated with polymorphism and inheritance.
8. Message Passing
Message passing involves specifying the name of object, the name of the method and the
information to be sent.
Example:.
p.accept(“abc”,18);
Here p is an object of Person class.
Accept is message
Arguments is information
1.1 Benefits of OOP
2
, Java Programming Notes CO4I
OOP emphasis on data rather than procedure.
Programs are divided into objects.
Objects are characterized by functions or data structure that operates on data.
Functions that operates on the data of an object are tied together in the data structure.
Data is hidden and cannot be accessed by external functions.
Objects may communicate with each other through functions.
New data and functions can be easily added whenever necessary.
Follows bottom-up approach in program design.
2. Java Features:
1. Compiler/Interpreter
Java Source Code (.java file) is compiled to byte codes(.class file) that are interpreted by a Java
virtual machines (JVM) .
This provides portability to any machine for which a virtual machine has been written.
The two steps of compilation and interpretation allow for extensive code checking and improved
security.
Java source code Java Compiler Byte code Interpreter Machine code
(.java file) (javac) (.class file) (java)
2. Platform Independence
Java byte code achieves the Write-Once-Run-Anywhere approach so running on different
platforms is possible. As we know java is both compiler & interpreter based language. Once the
java code also known as source code is compiled, it gets converted to Byte Code which is
portable & can be easily executed on all operating systems. Byte code generated is basically
represented in hexa decimal format in .class file. This .class file contains bytecode which is
executed JVM(Java virtual machine) which is a runtime environment for java. Now this .class file
can be run in any environment with the help of JVM and JVM convert bytecode into native
code.
Java Virtual Machine like its real counter part, executes the program and generate output. To
execute any code, JVM utilizes different components. JVM is divided into several components
like the stack, the garbage-collected heap, the registers and the method area.
3
, Java Programming Notes CO4I
Above fig. shows that JVM for different operating system is different.The JVM must translate the
bytecode into machine language, and since the machine language depends on the operating
system being used, it is clear that the JVM is platform (operating system) dependent – in other
words, the JVM is not platform independent.
3. Object Oriented
Supports all the concepts of object oriented programming language like object classes,
polymorphism etc.
Java is pure object oriented Language – Each and every code in java comes under a class,
including main().
Following is the example shows that even main function is comes under a class:
class Demo
{
public static void main(String args[])
{
System.out.println(“hello”);
}
}
4. Robust and Secure
Exception handling built-in, strong type checking (that is, all data must be declared an explicit
type), local variables must be initialized.
Automatic Memory Management
o Automatic garbage collection - memory management handled by JVM.
Java is secure as several dangerous features of C & C++ eliminated
o No memory pointers
o No preprocessor
o Array index limit checking
5.Dynamic Binding
4