0% found this document useful (0 votes)
29 views5 pages

2-Class As The Basis of All Computation

Uploaded by

Archana Gaur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views5 pages

2-Class As The Basis of All Computation

Uploaded by

Archana Gaur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Class as the Basis of all

Computation CHAP T ER :2

OOP OBJECT
Object oriented programming is an approach that An object is a typical instance of a class and
provides, a way of modularizing programs by thereby behaving as per the class definition. The
creating partitioned memory area for both data object can have state and behavior, which is
and functions, that can be used as templates for expressed by the variables and methods within
creating copies of such modules on demand. that object. It consists of 2 parts:
• Data structure, referred to as attributes.
• Processes that may correctly change data
WHAT IS CLASS structure, referred to as functions or methods.
A class represents a set of common properties and
behaviours shared by all objects. Example
A person object has the following attributes :
• First name
CLASSES AS ABSTRACTIONS • Last name
FOR SETS OF OBJECTS • Age
• Weight.
• A class is a named software representation for an
abstraction.
• An object is a distinct instance of a given class MESSAGES
that is structurally identical to all instances of Software objects interact and communicate with
that class. each other by sending messages to each other.
• Software code in OOP is written to define classes,
instantiate objects, and manipulate these objects.
CHARACTERISTICS OF
CLASS AS OBJECT FACTORY OBJECTS
The real world objects share two characteristics,
An object factory is a producer of objects. It
state and behavior :
accepts some information about how to create an
object, such as values depicting its state and then • State: The state is also called as attribute or
returns an instance of that object. properties of object.
Class is an object maker or object factory as it • Behavior: The capability of an object to do
contains all the statements needed to create an something is its behavior.
object, its attributes as well as the statements to • Identity: The name associated with an object
describe the operations that the object will be able helps in identifying the object.
to perform. By utilizing this and by providing initial
values depicting an object’s state, new objects can
be created from the class as and when required.

Get your FREE Practice Paper for this Chapter!


Sign up to oswal.io now Click Here
OOPs Principles

Encapsulation Inheritance Polymorphism Abstraction


It is the mechanism that This is the process of The ability to take more than The concept of giving
binds code and the creating new classes one form is called polymorphism performing the required
attributes together. called derived classes for example a method can function without
from existing classes perform different operations showing internal and
called super classes. with different type or no. of implementation detail,
arguments. is called abstraction.

VARIABLE
• A variable is a memory location to store any data or constant.
• The declaration of a variable generally takes the following form: <type>variablename>

CONSTANTS
A constant is a fixed value which can not be changed during the execution of program. Constants are of the
following type :
• Integer constant : 12, 2000, – 10 etc.
• Real constant : 0.00012, – 2.8707, 29.287, –0.28
• Character constants : ‘A’, ‘–’, ”, ‘.’
• String constants : “RAM”, “A/49, Kamla Nagar, Agra” “12 28”
• Boolean constant : true, false.

CONCEPT OF DATA TYPE


Java like any other language provides ways and facilitates to handle different types of data by providing
data types. Data types are means to identify the type of data and associated operators of handling it.
Java data types are of two types : • Primitive data type • Derived data type

PRIMITIVE DATA TYPE


Primitive data types are also called basic data types. These are inbuilt data types available in Java. These
data types are used to define other derived data types. Java supports the following four types of primitive
data types :
(i) Numeric Integral Types : The data types that are used to store whole number numeric values falls
under this subcategory.

Type Size Minimum Value Maximum Value


byte One byte —128 127
Short Two bytes —32,768 32,767
int Four bytes —2,147,483,648 2,147,483,647
long Eight bytes —9,223,372,036,854,775,808 9,223,372,036,854,775,807

Get your FREE Practice Paper for this Chapter!


Sign up to oswal.io now Click Here
(ii) Fractional Numeric Type : These data types can store fractional numbers i.e., numbers having decimal
points.

Type Size Minimum Value Maximum Value


float 4 bytes 3.4e — 038 3.4e + 038
double 8 bytes 1.7e — 308 1.7e + 308

(iii) Character Type : It is used to store characters.

Type Size Minimum Value Maximum Value


Char 16 bits (2 bytes) Single character 0 to 65.536

(iv) Boolean Type : It is used to represent a single True/False value.

Type Size Minimum Value Maximum Value


boolean 8 bits (used only 1 bit) Logical or boolean values True or False

DERIVED DATA TYPES


These data types also called compound or user defined data types. These are defined or derived by primitive
data type. Classes, Arrays and Interfaces are examples of derived data type.

CLASS AS A COMPOSITE TYPE


The data types that are based on fundamental or primitive data types are known as composite data types.
Since these data types are created by users these are also known as user-defined data types.

OPERATORS
Operators are tokens that perform operations on values to produce results. Java provides the following
operators :
(i) Arithmetic operators : These operators perform arithmetical operations.
(ii) Relational operators : These operators are used to compare the values.
(iii) Logical operators : They perform logical operations.
(iv) Assignment operators : They assign one value to a variable or a constant.
(v) Shift operators : They performs bit manipulation on data by shifting the bits right or left. (>>, <<, >>>)
(vi) Bitwise operators : These operators work with integral types i.e., byte, short; int and log type. (&,!,↑,–)
(vii) Conditional or ternary operators : It is an operator that works on more than two operands and
performs a decision making like if....else. It has the following form: condition ? Value 1 : Value 2 :

Get your FREE Practice Paper for this Chapter!


Sign up to oswal.io now Click Here
OTHER OPERATORS
([ ], –, (Parameters), (type), new, instance of)
(i) Arithmetic Operators
Operators Description Example
+ Addition a+b
– Subtraction a–b
× Multipication a×b
/ Division a/b
% Modulus a%b

(ii) Relational Operators


Operators Description Example
== check for equality a==b
!= not equal to a!=b
< less than a<b
> greater than a>b
<= less than or equal to a<=b
>= greater than or equal to a>=b

(iii) Logical Operators


Operators Description Example
&& And opr 1 && opr 2
|| Or opr 1 | | opr 2
! Not ! opr 1

(iv) Assignment Operators


Operators Description Example
= Equal to a=7
+= Add to the variable a + = 5 means a = a + 5
–= Subtract from variable a – = 5 means a = a – 5
×= Multiply to variable a × = 2 means a = a × 2
/= Divide into variable a / = 2 means a = a/2
%= Modulus by variable a % = 2 means a = a % 2

OPERATION ON PRIMITIVE DATA TYPES


Primitive data type operations deal only with value i.e., actual read value (rvalue). That is, they store the
read value directly in them.

Get your FREE Practice Paper for this Chapter!


Sign up to oswal.io now Click Here
Expressions
An expression in Java is any valid combination of operators, constants and variables i.e., a legal combination
of Java tokens. The expressions in Java can be of any type :

Arithmetic Expression Relational Expression Compound Expressions

Statements gets executed


sequentially in this type of
construct.

Pure integer expressions Pure real expressions Mixed expression

In pure expressions, all the operands are of same type


and in mixed expressions the operands are of mixed
type i.e., mixture of real and integer expressions.

Get your FREE Practice Paper for this Chapter!


Sign up to oswal.io now Click Here

You might also like