Vips Oops Unit 1
Vips Oops Unit 1
Paper Code:
Faculty : Dr. Shivanka
Assistant Professor
VIPS
Ø Introduction to Object Oriented Programming
Ø Benefits of Object Oriented Programming
Ø Java Features
Ø How Java Differs from other OO languages
Ø Java Environment
Ø Execution Process organization of the Java virtual Machine Model of Java
Ø Build your first Java Program
Ø General Structure of Java program
Ø Classes and objects
Ø Inheritance
Ø Data Encapsulation and Abstraction:
Object-oriented programming (OOP) is a programming
paradigm using "objects" – data structures consisting of
data fields and methods together with their interactions
– to design applications and computer programs.
Programming techniques may include features such as
data abstraction, encapsulation, messaging, modularity,
pol ym orphi sm , a nd i nhe ri t a nc e . M a n y m o d e rn
programming languages now support OOP.
Benefits of Object Oriented Programming
It is easy to modify the a part of the code without affecting the entire
program. It is easy to reuse the existing code. It is easy to extend the
code for performing new operations.
Security
vJava Is Simple
vJava Is Object-Oriented
vJava Is Distributed
vJava Is Interpreted
vJava Is Robust
vJava Is Secure
vJava Is Architecture-Neutral
vJava Is Portable
vJava's Performance
vJava Is Multithreaded
vJava Is Dynamic
Characteristics of Java
vJava Is Simple
vJava Is Object-Oriented
vJava Is Distributed
vJava Is Interpreted
vJava Is Robust
vJava Is Secure
vJava Is Architecture-Neutral
vJava Is Portable
vJava's Performance
vJava Is Multithreaded
vJava Is Dynamic
14
Characteristics of Java
vJava Is Simple Java is inherently object-oriented. Object-oriented
vJava Is Object-Oriented programming (OOP) is a popular programming
approach that is replacing traditional procedural
vJava Is Distributed programming techniques.
vJava Is Interpreted
One of the central issues in software development
vJava Is Robust is how to reuse code. Object-oriented
vJava Is Secure p r o g r a m m i n g p r o v i d e s g r e a t f l e x i b i l i t y,
modularity, clarity, and reusability through
vJava Is Architecture-Neutral encapsulation, inheritance, and polymorphism.
vJava Is Portable • focus on the data (objects) and methods
manipulating the data
vJava's Performance • all functions are associated with objects
vJava Is Multithreaded • almost all datatypes are objects (files, strings,
vJava Is Dynamic etc.)
• potentially better code organization and reuse
15
Characteristics of Java
vJava Is Simple Distributed computing involves several
computers working together on a network.
vJava Is Object-Oriented Java is designed to make distributed
vJava Is Distributed c o m p u t i n g e a s y. S i n c e n e t w o r k i n g
capability is inherently integrated into
vJava Is Interpreted Java, writing network programs is like
vJava Is Robust sending and receiving data to and from a
vJava Is Secure file.
vJava Is Architecture-Neutral
vJava Is Portable
vJava's Performance
vJava Is Multithreaded
vJava Is Dynamic
16
Characteristics of Java
vJava Is Simple
vJava Is Object-Oriented You need an interpreter to run Java
vJava Is Distributed programs. The programs are compiled into
vJava Is Interpreted the Java Virtual Machine code called
bytecode. The bytecode is machine-
vJava Is Robust independent and can run on any machine
vJava Is Secure that has a Java interpreter, which is part of
vJava Is Architecture-Neutral the Java Virtual Machine (JVM).
vJava Is Portable
vJava's Performance
vJava Is Multithreaded
vJava Is Dynamic
17
Characteristics of Java
vJava Is Simple Java compilers can detect many problems
vJava Is Object-Oriented that would first show up at execution time
in other languages. It has extensive
vJava Is Distributed compile-time and runtime error checking
vJava Is Interpreted • It has eliminated certain types of error-
vJava Is Robust prone programming constructs found
in other languages. There are no
vJava Is Secure pointers. Memory corruptions or
vJava Is Architecture-Neutral unauthorized memory accesses are
impossible
vJava Is Portable • Java has a runtime exception-handling
vJava's Performance feature to provide programming
vJava Is Multithreaded support for robustness.
• It has automatic garbage collection
vJava Is Dynamic tracks objects usage over time
18
Characteristics of Java
vJava Is Simple
vJava Is Object-Oriented
vJava Is Distributed
Java implements several security mechanisms
vJava Is Interpreted to protect your system against harm caused by
vJava Is Robust stray programs.
vJava Is Secure • usage in networked environments requires
more security
vJava Is Architecture-Neutral • memory allocation model is a major
vJava Is Portable defense
vJava's Performance • access restrictions are forced (private,
public)
vJava Is Multithreaded
vJava Is Dynamic
19
Characteristics of Java
vJava Is Simple
vJava Is Object-Oriented
vJava Is Distributed
vJava Is Interpreted
vJava Is Robust
vJava Is Secure
Write once, run anywhere
vJava Is Architecture-Neutral
vJava Is Portable With a Java Virtual Machine (JVM),
vJava's Performance you can write one program that will
run on any platform.
vJava Is Multithreaded
vJava Is Dynamic
20
Characteristics of Java
vJava Is Simple
vJava Is Object-Oriented
vJava Is Distributed
vJava Is Interpreted
vJava Is Robust
vJava Is Secure
vJava Is Architecture-Neutral
vJava Is Portable Because Java is architecture neutral,
vJava's Performance Java programs are portable. They can
be run on any platform without being
vJava Is Multithreaded recompiled.
vJava Is Dynamic
21
Characteristics of Java
vJava Is Simple
vJava Is Object-Oriented
vJava Is Distributed
vJava Is Interpreted
vJava Is Robust
vJava Is Secure
vJava Is Architecture-Neutral
vJava Is Portable Java’s performance is very high
vJava's Performance because of its architecture neutral and
vJava Is Multithreaded portable features.
vJava Is Dynamic
22
Characteristics of Java
vJava Is Simple
vJava Is Object-Oriented
vJava Is Distributed
vJava Is Interpreted
vJava Is Robust
vJava Is Secure
vJava Is Architecture-Neutral
vJava Is Portable
Multithread programming is smoothly
vJava's Performance integrated in Java, whereas in other
vJava Is Multithreaded languages you have to call procedures
specific to the operating system to enable
vJava Is Dynamic multithreading.
23
Characteristics of Java
vJava Is Simple
vJava Is Object-Oriented
vJava Is Distributed
vJava Is Interpreted
vJava Is Robust
vJava Is Secure
vJava Is Architecture-Neutral
vJava Is Portable
Java was designed to adapt to an evolving
vJava's Performance environment. New code can be loaded on the
vJava Is Multithreaded fly without recompilation. There is no need for
developers to create, and for users to install,
vJava Is Dynamic major new software versions. New features can
be incorporated transparently as needed.
24
ØSlower than compiled language such as C
ü an experiment in 1999 showed that Java was 3 or 4 times slower than C or C++
ü title of the article: “Comparing Java vs. C/C++ Efficiency Issues to Interpersonal Issues” (Lutz
Prechelt)
ü Running bytecode through the interpreter is not as fast as running machine code, which is
specific to that platform.
eter
er pr
Java Program Java Bytecode Int
MAC
compiler Interpreter
Inte
r pret
er Unix
ØFor most languages, compilation produces machine code
ØJava compilation produces “bytecode”
üIntermediate code readable by the VM
üTransferable across the Internet as applets
ØVM interprets BC into instructions
üPartly responsible for performance lag
ØByteCode produced on any platform may be executed on
any other platform which supports a VM
(translator)
verifier
virtual machine
JIT compiled
bytecode code
compiler
interpreter
CPU
ØJust-In-Time compiler
ØTranslates bytecode into machine code at runtime
ü1-time overhead when run initiated
üPerformance increase 10-30 times
ØNow the default for most JVM’s
üCan be turned off if desired
üJIT can apply statistical optimizations based on runtime usage
profile
ØJVM (J2EE & J2SE)
üWell-known Java Virtual Machine.
ØCVM , KVM (J2ME)
üSmall devices.
üReduces some VM features to fit resource-
constrained devices.
ØJCVM (Java Card)
üSmart cards.
üIt has least VM features.
and there are also lots of other JVMs
C++
C Java
In a first contact, Java seems like C++, and it's logical because Java takes the C and C++ syntax.
But Java has some important differences with C++. For instance, you can't use pointers in Java,
neither operators overload, neither multiple inheritance, neither predefined types. These features
of C++ that Java doesn't has, make it a simplest and more robust language. Interpreted Java is
furthermore slower than C++ (even 20 to 50 times slower than C in the original Java
interpreters).
: In Java, Primitive data types (like char, int, long...) have sizes and behaviors which
may be different in some platforms and operative systems. In Java language, unsigned data don't
exist. The boolean data has two values in Java : true and false. So it isn't an integer type, but you
can force "0" and "1" (which are integers) to be booleans.
The execution order of the operators in Java is same as in C.
The syntax of the following statements if, while, for and do is the
same as in C and C++. But there is an important difference : the proof expression
for each flux construction should return a boolean value (true or false). In C and
C++, the expression can return an integer.
Java Source
javadoc HTML Files
Code
javac
java jdb
Output
ØJava API and Virtual Machine insulate the Java program from hardware
dependencies.
ØJava API
• Collection of ready- • Core API
made software • Essentials: Object, String,
components that Input and Output...
provide many useful • Applets
capabilities. • Networking
• Internationalization
• Grouped into libraries • Security
(packages) of related • Software Components
components. • Object Serialization
• Java Database
Connectivity (JDBC)
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
ØCompile
üjavac HelloWorld.java
ØOne file named HelloWorld.class is created if the
compilation succeeds.
ØRun
üjava HelloWorld
• Since Java is object-oriented, programs are organized into modules called classes,
which may have data in variables and subroutines called methods.
class HelloWorld
{ public static void main (String[] args)
{ System.out.println(“Hello World!”);
}
}
•class keyword is used to declare a class in java.
•void is the return type of the method, it means it doesn't return any value.
For example, an instance of the class "Fruit" (a "Fruit" object) would be of the type "Fruit". A class
usually represents a noun, such as a person, place or (possibly quite abstract) thing. Programming
languages that include classes as a programming construct subtly differ in their support for various
class-related features. Most support various forms of class inheritance. Many languages also support
advanced encapsulation control features, such as access specifiers.
Object is an run time entity.
Is an Instance of class
The wrapping up of data and code into a single unit is called data encapsulation. The
data is not accessible to the outside world only those functions which are wrapped
into a class can only access the private data of the class.
Contd…
Data Encapsulation and Abstraction:
• The concept of data encapsulation is supported in C++ through the use of the public,
protected and private keywords which are placed in the declaration of the class.
• Note :
v Anything in the class placed after the public keyword is accessible to all the users of
the class
v Elements placed after the protected keyword are accessible only to the methods of the
class or classes derived from that class
v Elements placed after the private keyword are accessible only to the methods of the
class.
Inheritance is one of the most striking feature of object
oriented programming.