Notes

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Friday, May 13, 2022 12:56 PM

Concept of Object
Object
• What is an Object :
An object can be defined as an entity having a specific identity, specific character, and specific behavior.

Criteria for Object:


An object, in real world, can be one of the following:
1. anything that is visible or touchable.
2. something that may be apprehended intellectually.
3. something towards which one can initiate action or thought.

Example of Object:
"You' are also an example of object. Your unique identity is your name. Your characteristics are you have eyes,
ears, nose, hands, legs, heart, brain, liver....etc Your behaviour is: you can walk, talk, eat, sleep, sing, dance,
etc.

State is defined as the set of values held by its attribute


Behavior is defined as the set of actions an object can perform
Attributes are individual characteristics that differentiate one object from another

Behavior represented through methods known as member methods


Attributes are represented through data items known as member variables

• Class
A CLASS IS A BLUEPRINT THAT SYMBOLISED a set of objects that shared common structure and common behaviour.

Need for Class:


In an OOP it is use to wrap variables and Methods in a Single unit;

• Object Factory
A producer of objects that accepts some basic information and creates objects based on this information

Classes as object Factory:


Basically the class is an object maker or object factory. It contains all the statements needed to create an object, its
attributes, as well as the statements to describe the operations that the object will be able to perform.

Object as Instances of a class:


Object is an instances of a class which can access variable and method of the class with dot operator.

Data Abstraction
• Data Abstraction:
DATA Abstraction is an act of representing essential features without including the background details or
explanation

Example of Abstraction:
Take another example of a 'switchboard'. You just press certain switches according to your requirement. What
is happening inside, how it is happening what the internal circuit is etc. you needn't know. Again this is
abstraction, you know only the essential things to operate on switchboard without knowing the background
details of switchboard.

How Abstraction is implemented:


Java offers ADT Abstract Data Types to implement abstraction. The ADTs are;
help 'what' from 'how'.
client use specification for interaction with data.
client do not get to know the implementation details

Need for Abstraction:


To show just relevant data/ information
• Data Encapsulation:
Encapsulation means characteristics and behaviour are combined in one unit. This means that encapsulation is a way of
combining both data (that represents characteristics)and functions (that represents behaviour) that operate in that data under a single unit.

The only way to access the data is provided by the function that are combined along with the data this function are called
methods or Member function in object-oriented language

Need for Encapsulation:


encapsulation helps us to keep related fields and methods together, which makes our code cleaner and easy
to read.

Data Encapsulation and Abstraction are interrelated:


abstraction and encapsulation are interrelated concepts: abstraction focus upon the observable behavior of an object whereas
encapsulation Falls upon the implementation that gives rise to this behavior encapsulation is most often achieved through information
Hiding, which is the process of all secrets of an object that does not contribute to its essential characteristics; The structure of an object
is hidden, as well as the implementation of its method

The software objects also have state and behaviour.


• Their state (also called characteristic)is maintained through variables or data items.
• Their behaviour is implemented through functions generally called methods.

In an object,
(i) there are variables to hold data, called member variables.
(ii) the values of these member variables define the state of an object.
(iii) there are member functions/operations/methods that define the behaviour of objects.

When the objects require, they pass/request information to one another. This interaction is called message passing.

• Method
A member function is also called as Method.

A member function representing a behaviour is called Method.

The behaivour of an object is described through associated functions termed as methods.


• Behaviour is implemented through function which are called methods

• Message
A way of Sending/Receiving information to/From another object.

The message sending object is called sender


The message Recieving object is called Receiver

Type of Java Program:


Stand-alone Java Application Java Applets or Java internet Applets
A stand-alone Java application is a the Java program that can run in a web Browser .
Used to create interactive games and create animation
Java Program that can run independently on a computer
Example Acrobat PDF Reader

Machine Language:
computer was developed to carry out that word written in which language called language machine language
instructions are expressed as binary language called machine code.
It's sequence of Zeros and ones.
A computer can directly execute a program only if is written own machine language.

Assembly Language:
Consists of mnemonic codes.
Assembler converts Assembly language to machine language.
Java compilation processes is different from traditional compilation process as it converts the machine code for a virtual
machine known as JVM on the Java Virtual Machine the machine code for JVM is called bytecode it has the extension
called .java the bytecode and needs Java interpreter to convert it into the machine code of the computer on which it is to be
executed this interpreter is a part of JVM

JVM also includes JIT (just-in-time) compiler that compiles selected portion of bytecode into executable code the remaining
code is simply interpreted

JRE (Java Runtime Environment) JVM along, with the many other classes libraries constitutes the JRE

features of Java
Java consists of many features, some important features are
object-oriented
Because it treat everything as object
Robust
Allocation and de-location of data is automatic
platform independent
"Write once run anywhere" As java applications can run on platform that has corresponding JVM installed in it.
simple
It is easy and simple to learn

Values and Data types :

Character Set:
Alphabets: letter, A-Z (Uppercase) and (LowerCase);
Number: digit(0-9);
Special characters: ?, %,],},> etc;
Token
• All character in a Java program are grouped into symbol called Token
These are the smallest individual in a program.

Token
Keywords Identifiers Literals Punctuators Operators

Keywords in Java
keywords are also known as reserved words that have a special meaning to the Java compiler
Java compiler reserves these words for its own use and hence they are not available for being the
name of the variable or method

example Boolean default if public break import return byte double

Identifiers in Java
Identifiers are fundamental building blocks of a program and are used to name different components of a program such as
variable ,method and object
for example public class welcome here welcome is the identifier

Literals
Literals are sequence of character that represent value in program and store in variable
literals are made up of digits letters and other characters

Java supports following are types of literals numeric non-numeric Boolean and null

numeric literals are values that are consists of digits 0 to 9 a decimal point a positive or negative sign they are of two types
integer or real literals integer literal shows numeric values which are whole only

the real literals shows the floating points literals as they represents value with the decimal point

non numeric literals in Java


they are of two types character literal and string literals
Character literal are the type of literals which represents exactly One character enclosed in single
quote whereas string literals which shows one or more character enclosed in double quotes are
called string literals Boolean literals Boolean literals are used for the logic there are two little little
little girls

Operator in Java
Operators are symbols used to perform a mathematical or logical operation on a given expression The variable literals are
combined to build an expression.
• Unary Operator:
A unary (meaning only one) operator requires only one operand.
E.g. = , -, ++, --,!'
• Binary Operator
A binary(meaning only two ) operator requires two operands.
E.g. =, -, %, &&
• Ternary operator
A ternary (meaning only three ) operator requires three operands.
E.g. ? :

Syntax : variable = Expression1 ? Expression2: Expression3

Types of Operator

A static method is a method that belongs to a class, but it does not belong to an instance of that class and this method can be called without the instance or object of that class.
Every method in java defaults to a non-static method without a static keyword preceding it. non-static methods can access any static method and static variable also, without
using the object of the class.

From <https://www.geeksforgeeks.org/difference-between-static-and-non-static-method-in-java/>

From <https://www.geeksforgeeks.org/difference-between-static-and-non-static-method-in-java/>

You might also like