0% found this document useful (0 votes)
53 views

Unit 3

The document discusses object-oriented programming (OOP) and Java. It defines OOP concepts like objects, classes, inheritance, polymorphism, encapsulation and abstraction. It compares procedural programming with OOP. It also discusses the history and features of Java, the Java virtual machine architecture including classloaders, method area, heap, stack, program counter and native method stack. It explains the need for OOP, its principles and applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Unit 3

The document discusses object-oriented programming (OOP) and Java. It defines OOP concepts like objects, classes, inheritance, polymorphism, encapsulation and abstraction. It compares procedural programming with OOP. It also discusses the history and features of Java, the Java virtual machine architecture including classloaders, method area, heap, stack, program counter and native method stack. It explains the need for OOP, its principles and applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 42

UNIT-I

INTRODUCTION TO OOPs
Introduction - need of object oriented

programming - principles of object oriented

languages - procedural languages Vs. OOPs -

applications of OOPs - history of JAVA - java

virtual machine -java features - program

structures - installation of JDK1.6


Introduction
• OOPs- Object Oriented Programming System
It uses objects in programming

• POP- Procedure Oriented Programming


It uses functions in programming
Need of object oriented programming
Procedural languages Vs. OOPs
Procedural Language OOPs
Program is divided into small parts
Program is divided into small parts called objects
called functions
Procedural programming follows top Object oriented programming
down approach follows bottom up approach
Object oriented programming have
There is no access specifiers in access specifiers like private, public,
procedural programming protected etc

Adding new data and function is not


easy Adding new data and function is easy

Procedural programming does not have


any proper way for hiding data so it Object oriented programming provides
is less secure data hiding so it is more secure
Procedural languages Vs. OOPs
Procedural Language OOPs

In procedural programming, Overloading is possible in object


overloading is not possible. oriented programming.

In procedural programming, function is In object oriented programming, data is


more important than data. more important than function.

Procedural programming is based Object oriented programming is based


on unreal world. on real world.

Examples: C, FORTRAN, Pascal, Basic


etc. Examples: C++, Java, Python, C# etc.
Principles of object oriented
languages
• Object-Oriented Programming is a
methodology or paradigm to design a program
using classes and objects

• It simplifies software development and


maintenance
OOPs CONCEPTS
Object
• Any entity that has state and behavior is
known as an object

• Ex: chair, pen, table, keyboard, bike, etc. It can


be physical or logical

• An Object can be defined as an instance of a


class
Class

• Collection of objects is called class. It is a


logical entity

• It can be defined as a blueprint from which


you can create an individual object.

• Class doesn't consume any space


Inheritance

• A new class is derived from the existing class

• When one object acquires all the properties


and behaviors of a parent object, it is known
as inheritance.

• It provides code reusability. It is used to


achieve runtime polymorphism.
Polymorphism

• If one task is performed in different ways, it is


known as polymorphism

• Ex: to convince the customer differently, to


draw something Ex: shape, triangle, rectangle,
etc.

• In Java, we use method overloading and


method overriding to achieve polymorphism.
Abstraction

• Hiding internal details and showing


functionality is known as abstraction

• Ex: phone call, we don't know the internal


processing

• In Java, we use abstract class and interface to


achieve abstraction
Encapsulation

• Binding (or wrapping) code and data together


into a single unit are known as encapsulation

• Ex: a capsule, it is wrapped with different


medicines

• A java class is the example of encapsulation


Advantages of OOPs
• OOP is faster and easier to execute

• OOP provides a clear structure for the programs

• OOP helps to keep the Java code easier to


maintain, modify and debug

• OOP makes it possible to create full reusable


applications with less code and shorter
development time
Applications of OOPs
• User interface design such as windows, menu
• Real Time Systems
• Simulation and Modeling
• Object oriented databases
• AI and Expert System
• Neural Networks and parallel programming
• Decision support and office automation
systems
History of JAVA
• James Gosling(Fatehr of Java), Mike Sheridan,
and Patrick Naughton initiated the Java language
project in June 1991.

• The small team of sun engineers called Green


Team(Sun Micro System)

• Initially designed for small, embedded systems in


electronic appliances like set-top boxes

• It was called "Greentalk" by James Gosling, and the


file extension was .gt
History of JAVA

• After that, it was called Oak and was


developed as a part of the Green project

• In 1995, Oak was renamed as "Java“ 

• Java is used in internet programming, mobile


devices, games, e-business solutions, etc..
Java Features
• Simple - Java is very easy to learn, and its
syntax is simple, clean and easy to understand

• Object-Oriented-Everything in Java is an
object. We organize our software as a
combination of different types of objects that
incorporates both data and behavior

• Portable-Java is portable because it facilitates


to carry the Java bytecode to any platform
Java Features
• Platform independent-write once, run any where,
every where language

• Secured- It is best known for its security. Using


Java, we can develop virus-free systems

• Robust- strong
– It uses strong memory management
– lack of pointers it avoids security problems
– There is automatic garbage collection
– Exception handling 
Java Features
• Architecture neutral- no implementation
dependent features, for ex: the size of
primitive types is fixed(32 bit 64 bit processor)

• Interpreted- byte-code runs on the JVM,


which is usually a software-based interpreter

• High Performance- Java is faster than other


traditional interpreted programming
languages because of Java bytecode
Java Features
• Multithreaded-A thread is like a separate
program, executing concurrently. Programs that
deal with many tasks at once by defining
multiple threads
 
• Distributed- It facilitates users to create
distributed applications in Java(RMI)

• Dynamic- It supports dynamic loading of classes.


It means classes are loaded on demand
JVM (Java Virtual Machine) Architecture
• Java Virtual Machine (JVM) is a engine that
provides runtime environment to drive the Java
Code or applications. It converts Java bytecode
into machines language.

• JVM is a part of Java Run Environment (JRE). In


other programming languages, the compiler
produces machine code for a particular system.
However, Java compiler produces code for a
Virtual Machine known as Java Virtual Machine.
• First, Java code is complied into bytecode. This
bytecode gets interpreted on different
machines

• Between host system and Java source,


Bytecode is an intermediary language.

• JVM in Java is responsible for allocating


memory space.
JVM
• A specification where working of JVM is
specified. But implementation provider is
independent to choose the algorithm.

• An implementation Its implementation is
known as JRE (Java Runtime Environment)

• Runtime Instance Whenever you write java


command on the command prompt to run the
java class, an instance of JVM is created
JVM
The JVM performs following operation,
– Loads code
– Verifies code
– Executes code
– Provides runtime environment
JVM provides definitions for the,
– Memory area
– Class file format
– Register set
– Garbage-collected heap
– Fatal error reporting etc
JVM ARCHITECTURE
JVM ARCHITECTURE
1) Classloader
2) Class(Method) Area
3) Heap
4) Stack
5) Program Counter Register
6) Native Method Stack
7) Execution Engine
8) Java Native Interface
JVM- Class loader
1) Classloader: is a subsystem of JVM which is used to load class
files. Whenever we run the java program, it is loaded first by
the classloader.

• There are three built-in classloaders in Java


– Bootstrap ClassLoader
– Extension ClassLoader
– System/Application ClassLoader

• Bootstrap ClassLoader : This is the first classloader which is


the super class of Extension classloader. It loads the rt.jar file
which contains all class files of Java Standard Edition
JVM- Class loader
• Extension ClassLoader: This is the child classloader
of Bootstrap and parent classloader of System
classloader. It loades the jar files located
inside $JAVA_HOME/jre/lib/ext directory

• System/Application ClassLoader:child classloader


of Extension classloader. It loads the classfiles from
classpath. By default, classpath is set to current
directory. We can change the classpath "-classpath"
switch. It is also known as Application classloader.
2) Class(Method) Area: It stores per-class structures such as
the runtime constant pool, field and method data, the code
for methods

3) Heap : It is the runtime data area in which objects are


allocated

4) Stack :
• Java Stack stores frames. It holds local variables and partial
results
• Each thread has a private JVM stack, created at the same
time as thread
• A new frame is created each time a method is invoked. A
frame is destroyed when its method invocation completes
5) Program Counter Register: PC (program
counter) register contains the address of the
Java virtual machine instruction currently
being executed

6) Native Method Stack: It contains all the


native methods used in the application.

7) Execution Engine: It contains a virtual


processor and Interpreter and Just-In-
Time(JIT) compiler(improve the performance)
8) Java Native Interface : Java Native Interface
(JNI) is a framework which provides an
interface to communicate with another
application written in another language like C,
C++, Assembly etc.
Program structure
• Documentation Section
• Package Declaration
• Import Statements
• Interface Section
• Class Definition
• Class Variables and Variables
• Main Method
• Methods and Behaviors
• Documentation Section :  basic
information about a Java program. author's
name, date of creation, version, program
name, company name, and description of the
program

• Comments:
– single-line
– multi-line
– documentation 
• Single-line Comment: It starts with a pair of
forwarding slash (//)

• Multi-line Comment: It starts with a /* and ends


with */. We write between these two symbols

• Documentation Comment: It starts with the


delimiter (/**) and ends with */
• Package Declaration: package declaration is
optional. It is placed just after the
documentation section

Ex: package computer; 

• Import Statements: contains the many


predefined classes and interfaces
Ex: import java.util.Scanner;
Ex:import java.util.*;
• Interface Section : It is an optional section. We
use the interface keyword to create an interface.

• Class Definition : It is vital part of a Java program.


Without the class, we cannot create any Java
program. A Java program may conation more
than one class definition.
Ex: class Student   
{  
//class definition
}  
• Class Variables and Constants : we define
variables and constants that are to be used
later in the program.
class Student //class definition  
{  
String sname;  //variable  
int id;   
double percentage;   
}  
• Main Method : It is essential for all Java
programs. Because the execution of all Java
programs starts from the main() method. It is
an entry point of the class

public static void main(String args[])  
{  

}  
• Methods and behavior :we define the functionality of the
program by using the methods. The methods are the set of
instructions that we want to perform.
class Demo   
{  
public static void main(String args[])  
{  
void display()  
{  
System.out.println("Welcome");  

}

 
• installation of JDK

You might also like