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

Object Oriented Programming With JAVA

The document provides an overview of Object-Oriented Programming (OOP) principles using Java, including key features such as security and portability. It discusses core OOP concepts like encapsulation, inheritance, polymorphism, and abstraction, along with practical examples of Java program compilation, type conversion, arrays, and operators. Additionally, it covers arithmetic, relational, bit-wise, and logical operators, including increment and decrement operations.

Uploaded by

Sharada A
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Object Oriented Programming With JAVA

The document provides an overview of Object-Oriented Programming (OOP) principles using Java, including key features such as security and portability. It discusses core OOP concepts like encapsulation, inheritance, polymorphism, and abstraction, along with practical examples of Java program compilation, type conversion, arrays, and operators. Additionally, it covers arithmetic, relational, bit-wise, and logical operators, including increment and decrement operations.

Uploaded by

Sharada A
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Object Oriented

Programming with JAVA


(BCS306A)
1 BY
SHARADA.A.
CONTENTS:

• INTRODUCTION

• OOPS PRINCIPLES

• Java program compilation

• Type Conversion and Casting

• Arrays

• Operators
INTRODUCTION
Key features of Java

 security
 portability

Java is purely object oriented programming (OOP) language. Here, we will discuss the basics
of OOPs
concepts.

Two Paradigms :

 Process oriented model


 Object oriented model
Three OOP Principles

 Encapsulation
 Inheritance
 Polymorphism

Abstraction :
Abstraction can be thought of as hiding the implementation details from the end-user. A powerful way
to manage abstraction is through the use of hierarchical classifications. This allows us to layer the semantics
vehicle and can be thought of as a single object. But, from inside, car is a collection of several subsystems
of complex systems, breaking them into more manageable pieces. For example, we consider a car as a
viz. steering, brakes, sound system, engine etc. Again, each of these subsystems is a collection of individual
parts (Ex. Sound system is a combination of a radio and CD/tape player). As an owner of the car, we manage
it as an individual entity by achieving hierarchical abstractions.

Hierarchical abstractions of complex systems can also be applied to computer programs. The data from a
traditional process-oriented program can be transformed by abstraction into its component objects. A sequence of
process steps can become a collection of messages between these objects.
Java program compilation

A java program source code is a text file containing one or more class
definitions is called as compilation unit.

Simple Example Program:


Type Conversion and Casting

When one type of data is assigned to another type of variable, an automatic type conversion will
take Java’s Automatic Conversions place if the following two conditions are met:

• The two types are compatible.


• The destination type is larger than the source type.

A cast is simply an explicit type conversion.


It has this general form: (target-type) value

Here, target-type specifies the desired type to convert the specified value to.
For example,
int a; byte b; b = (byte) a;
Illustration of type conversion
class Conversion }
{ System.out.println("d and b " + d + " " +
public static void main(String args[]) b);
}
{
byte b;
int i = 257;
double d = 323.142;
System.out.println("\nConversion of
int to byte.");
b = (byte) i;
System.out.println("i and b " + i + "
" + b);
System.out.println("\nConversion of
double to int.");
i = (int) d;
System.out.println("d and i " + d + "
" + i);
System.out.println("\nConversion of
double to byte."); b
= (byte) d;
ARRAYS

Collection of similar data-types, are accessed using index, also


known as contiguous memory allocation.
Demonstration of 2-d array
class TwoDArray
{
public static void main(String args[])
{ int twoD[][]= new int[3][4]; int i, j;

for(i=0; i<3; i++) The output would be –

for(j=0; j<4; j++) twoD[i][j] 0123


= i+j; 1234
2345
for(i=0; i<3; i++)

{ for(j=0; j<4; j++)


System.out.print(twoD[i][j] + " ");

System.out.println();

}
}
}
OPERATORS
 Arithmetic
 Relational
 Bit-wise
 Logical

Arithmetic Compound Assignment Operators:

There are compound assignment operators for all of the arithmetic, binary operators. Thus,
any statement of the form :
var = var op expression;
can be rewritten as : var op= expression;  (in java)
Here is a sample program that shows several op= assignments in
action:
// Demonstrate several assignment operators.
class OpEquals {
public static void main(String[] args) {
int a = 1;
int b = 2;
int c = 3; The output of this program is shown
a += 5; here:
b *= 4; a=6
c += a * b; b=8
c %= 6; c=3
System.out.println("a = " + a);
System.out.println("b = " + b);
System.out.println("c = " + c);
}
}
Increment and Decrement

The increment operator increases its operand by one. The decrement operator decreases
its operand by one. For example, this statement:
x = x + 1;
can be rewritten like this by use of the increment operator:
x++;
Similarly, this statement:
x = x - 1;
is equivalent to
x--;
The following program demonstrates the increment operator .
// Demonstrate ++.
class IncDec {
public static void main(String[] args) {
int a = 1;
int b = 2; The output of this program
int c; follows:
int d; a=2
c = ++b; b=3
d = a++; c=4
c++; d=1
System.out.println("a = " + a);
System.out.println("b = " + b);
System.out.println("c = " + c);
System.out.println("d = " + d);
}
}
SHIFT OPERATORS:

You might also like