Академический Документы
Профессиональный Документы
Культура Документы
Santanu Basak
Dept. Of CSE, UEM, Jaipur
Introduction
Introduction
Modular programming
It is the process of subdividing a computer
program into separate sub-programs.
A module is a separate software component.
Introduction
Top-Down
In Top-Down development we start out with
your main function and then think of the main
steps you need to take, then you break up each
of those steps into their subparts and so on.
Introduction
Bottom-Up
In Bottom-Up programming you think of the
basic functionality and the parts you're going to
need and build them up.
Structured programming
Introduction
Smalltalk
Objective C
C++ (an extension of C language) -
procedural language with object oriented
extension
Features of object oriented paradigm
Class
User-defined data types.
BASIC CONCEPT OF OOPS (OBJECT-ORIENTED
PROGRAMMING)
Object
a person, a place, a bank account.
It takes some space in memory.
When a program is executed, the objects interact by sending
messages to one another.
A customer object sending request for getting balance to
account object.
Each object contains data and code to manipulate the data.
An object can interact without knowing the details of each
others data or code.
It is sufficient to know the types of message accepted and the
type of response returned by the object.
Object is like a black box
BASIC CONCEPT OF OOPS (OBJECT-ORIENTED
PROGRAMMING)
Abstraction : ATM
One level : using valid ATM card we can
make a transaction.
There are subsystems : a system that validate
the card, pin, balance
Get money.
Money come out.
So each of the parts has unique behavior and
each part can be updated easily.
BASIC CONCEPT OF OOPS (OBJECT-ORIENTED
PROGRAMMING)
Login module
Withdraw module
Change pin module
Cash transfer module
Mini-statement module
Polymorphism
Encapsulation :
Inheritance
Data Encapsulation
wrapping of data and functions / methods
into a single unit
Basic of encapsulation is a class (contains
data and code)
Data Hiding
Data Hiding : Protect data from direct
access (access modifiers : public, protected,
private, default)
Comparison : Java vs C++
Sl.
No Java C++
1. True object oriented language C with object oriented language
2. Strictly object oriented Both procedural and object oriented
3. Does not support operator Support
overloading
4. Does not support pointer Support
5. Does not support global variable, Support
declare within class
6. Platform independent Platform dependent
7. Does not support multiple Support
inheritance for classes but supports
using interface
8. Java has finalize() method It has destructor
9. It is not a subset of C or C++ It is a superset of C
Java Features 1
Compiled and interpreted
Two stage system
Platform independent and portable
Code can be moved from one system to another
Object oriented
Almost everything is an object. Code and data exist in
object and classes
Robust and secure
Well made
Garbage collection
Exception handling
secure
Absence of pointer
Java Features 2
Distributed
Remote object can be accessed on internet
Developers can work from different location on
single task
Multithreaded
Managing multiple tasks simultaneously
One application does not need to wait for completion
of another
Extensible
Supports code of other language
Source code Execution
Java Source
Java Compiler Java Virtual Machine
Code javac java
Bytecode (.class) Machine code
(.java)
JVM
class ClassName {
//class body
}
Method/s in Java
class MyClass {
void methodName(){
//method body
}
int methodName2(){
//method body
return 0;
}
float methodName3(float a){
//method body
return a;
}
}
Method calling in Java
class MyClass {
void test(){
class MyClass2 {
public static void main(String args[]){
//method body int i=0;
} float f=0f;
int test2(){ MyClass m1 = new MyClass();
}
}
Chapter 7
Types of Polymorphism
Polymorphism
Compiletime Runtime
Polymorphism Polymorphism
Static Binding Dynamic Binding
(Method Overloading,
(Method overriding)
Constructor Overloading)
Compiletime Polymorphism
Static Binding
Method Overloading
Constructor Overloading
Method Overloading
It is possible to define more than
one methods with same name in a
class
Methods share same name
No of parameter/s different
Types of parameter/s different
Method Overloading (Overload.java)
class OverloadDemo {
void test() {
System.out.println("No Parameters");
}
class Overload {
public static void main(String args[]){
//create an instance for class OverloadDemo
OverloadDemo od=new OverloadDemo();
class Overload2 {
public static void main(String args[]){
//create an instance for class OverloadDemo
OverloadDemo2 od=new OverloadDemo2();
System.out.println(c.add(10, 20));
System.out.println(c.add(10f, 20f));
System.out.println(c.add(10.1d, 20.2d));
}
}
Constructor Overloading
Compiletime Polymorphism (static binding) (MyClass2.java)
class Cal { class MyClass {
int a,b; public static void main(String args[]){
Cal(){ int result;
a=0; //instance with default constructor
b=0; Cal c1=new Cal();
} result = c1.getResult();
Cal(int i, int j) { System.out.println(result);
a=i;
b=j; //instance with two parameter constructor
} Cal c2=new Cal(10,20);
int getResult() { result = c2.getResult();
return a+b; System.out.println(result);
} }
} }
Using Object As Parameter (MyClass3.java)
ClassName.methodName()
ClassName.variableName
Static block
Can be used to initialize static
variables
Executes exactly once when that
class is loaded
System.out.println()
System is a final class of package java.lang
out is an instance of class PrintStream,
declare in class System as final static
println() is a method of PrintStream class
PrintStream is a class of package java.io
System class has only one constructor,
defined as private
Introducing final
final makes a field constant
So cannot be modified
You must initialize a final field during
declaration
Or value can be assigned within a
constructor
If vaTest() is called
Chapter 8
Inheritance (Table.java & Table2.java)
Java
The Complete Reference
by
Herbert Schildt