CS8392 OBJECT ORIENTED PROGRAMMING Unit1
CS8392 OBJECT ORIENTED PROGRAMMING Unit1
CS8392 OBJECT ORIENTED PROGRAMMING Unit1
J GNANA JESLIN,
CS8392 -OBJECT ORIENTED
PROGRAMMING
• UNIT-1 INTRODUCTION TO OOP AND JAVA
FUNDAMENTALS
• UNIT -2 INHERITANCE AND INTERFACES
1. https://www.tutorialspoint.com/java/index.h
tm
2. https://www.javatpoint.com/java-tutorial
3. https://www.w3schools.com/java/
4. https://www.geeksforgeeks.org/java-
tutorial/
5. https://docs.oracle.com/javase/tutorial/
UNIT - I
INTRODUCTION TO OOP
AND JAVA
FUNDAMENTALS
Object Oriented Programming – Abstraction – objects and
classes – Encapsulation- Inheritance – Polymorphism-
OOP in Java – Characteristics of Java – The Java Environment
– Java Source File Structure – Compilation.
Fundamental Programming Structures in Java – Defining
classes in Java – constructors, methods -access specifiers –
static members -Comments, Data Types, Variables,
Operators, Control Flow, Arrays , Packages – JavaDoc
comments.
S TOPIC
NO
1 Object Oriented Programming-Abstraction–objects and
classes-Encapsulation-Inheritance-Polymorphism
2 Characteristics of Java –The Java Environment -Java Source
File -Structure –Compilation. Java –Data Types, Variables,
Operators
3 Control Flow, Arrays , Methods
4 Defining classes in Java, constructors,
5 Access specifiers -Static members ,
6 Packages –Java Doc comments.
Introduction to Programming
Concepts
Human Language
• Commonly used to express feelings and
understand other person expressions.
• It can be oral or gestural kind of
communication
Human Language
Computer Language:
• Computer languages are the languages by
which a user command a computer to work
on the algorithm which a user has written to
get an output.
COMPUTER PROGRAM
PROGRAMMING LANGUAGE
LEVELS OF PROGRAMMING
LANGUAGE
C –PROGRAM JAVA PROGRAM
• https://www.eclipse.org/downloads/
Online compilers
• https://www.codechef.com/ide
• https://www.onlinegdb.com/online_java_com
piler
• https://www.tutorialspoint.com/compile_java
_online.php
• https://compiler.javatpoint.com/opr/online-
java-compiler.jsp
PROGRAMMING PARADIGMS
Main Program
Data
– Unstructured Programming
– Procedural programming
• Structured programming
– Modular programming
– Object-oriented programming
OBJECT ORIENTED PROGRAMMING
• Object Oriented Programming is a
Methodology or Paradigm to design a
Program/Software application based on
objects.
• Objects are real-world entity.
• Any things we see, that could be
differentiated from another is called object.
Object-Orientation
• It is a kind of thinking methodology
– Everything in the world is an object;
– Any system is composed of objects (certainly
a system is also an object);
– The evolution and development of a system is
caused by the interactions among the objects
inside or outside the system
Everything in the world is an object
• A flower, a tree, an animal
• A student, a professor
• A desk, a chair, a classroom, a building
• A university, a city, a country
• The world, the universe
• A subject such as CS, IS, Math, History, …
Any system is composed of objects
• A law system
• A cultural system
• An educational system
• An economic system
• An Information system
• A computer system
Object Oriented Programming
Features
• Object
• Class
• Inheritance
• Polymorphism
•Abstraction
•Encapsulation
OBJECT ORIENTED PROGRAMMING
Program is composed of a collection of individual
units, or objects, as opposed to a traditional view
in which a program is a list of instructions to
the computer
Object B
Data variable
Object A Object C
Member Function
Data variable Data variable
Object2
Data
Data2 + Procedures
Data12
Object3
Data3 + Procedures3
Object4
Data4 + Procedures4
OBJECTS
• Modularity
• Information-hiding
• Code re-use
• Pluggability and debugging ease
CLASSES
A class is the blueprint from which individual
objects are created.
Classes are made up of objects.
• A class is a group of objects which have
common properties.
• It is a logical entity. It can't be physical.
• Class doesn't consume any space, Objects do.
DECLARING A CLASS
• A class must have a valid identifier name; it can begin with
an alphabetic character, the underscore, or the dollar sign.
class MyClass {
member variables;
…
member functions () ;
…
} // end class MyClass
Example : Objects and Classes
object class
class Student
char name
int rollNo
setName()
setRollNo()
calcMarks()
Jodie Daria Jane Brittany
R001 R002 R003 R004
ABSTRACTION
Is the act of representing the essential features
ignoring the background details.
Abstraction means ignoring irrelevant features,
properties, or functions and emphasizing the
relevant ones...
“Relevant” to what?
subclass superclass
or extends or
derived class base class
PRINT
25000
20000
<access specifier>[return_Type]
methodname(parameter list)
{
Statements;
[return value]
}
Method declaration have four basic parts:
1) Method name
2) Return type
3) Parameter list
4) Body of the method
Types of methods
• Based on the processing of fields methods are divided into
two categories:
– Mutators
» Methods that change field values of an object
are called mutator methods.
• Fields.
• Constants.
• Methods.
import java.io.*;
class circle
{
static int r=2; // static field
static double a;
static final double pi=3.14; //static constant
static double area() //static method
{
a=pi*r*r;
return a;
}
}
class area
{
public static void main(String args[])
{
System.out.println("the value of pi="+circle.pi);
System.out.println("the value of
radius="+circle.r);
System.out.println("the value of
area="+circle.area());
}
}
PACKAGES
• Way to group a related class and interface into
one unit.
• Packages are essentially a means of organizing
classes together as groups.
• Package declaration
– The first statement, other than comments, in a Java
source file, must be the package declaration.
– Syntax
• package packagename;
– E.g.:
• package area;
• While creating a package, care should be taken that the
statement for creating a package must be written before any
other import statements
LEGAL ILLEGAL
– import mypackage.mysubpackage.MyClass;
Two ways to import a package
Importing a specific Package Member
• import mypackage.Calculator;
Importing an Entire Package
• import mypackage.*;
Package statement should be the
package mypackage; first statement. It is optional
import java.awt.*;
import java.uti.*;
class MyClass{
//attributes and functions import statements are optional.
} There can be any no of import
public class Demo{ statements.
//attributes and functions
}
value of method.
/**
*value of pi
**/