Concept of Objects: State, Behavior & Identity of an object
The concept of objects is fundamental to object-oriented programming (OOP), and it revolves around three key aspects: state, behavior, and identity.
State:
Definition: For any given moment, the state of an object is formed from its characteristics.
Example: The state of ‘car’ can include properties like color, speed, fuel level and present gear.
Behavior:
Definition: This is a terminology that refers to the actions or methods that are performed by an object. They describe how the given object relates with others or its environment.
Example: Behaviors for cars can include accelerate, brake, changeGear, turnLeft.
Identity:
Definition: An object’s identity is what separates it from other objects. It helps differentiate between multiple instances of the same class in the system.
Example: Every car on the road has certain unique identity such as a license plate number or Vehicle Identification Number (VIN).
Reference---https://easyexamnotes.com/concept-of-objects-state-behavior-identity-of-an-object/
States
1.Statically typed languages
2.Dynamically typed languages
Statically typed languages:
Statically typed languages are the languages like C, C++, Java, etc, In this type of language the data type of a variable is known at the compile time which means the programmer has to specify the data type of a variable at the time of its declaration. We have to pre-define the return type of function as well as the type of variable it is taking or accepting for further evaluations.
`
`
Syntax:
data_type variable_name;
`
`
Example:int age=10;
Dynamically typed language:
These are the languages that do not require any pre-defined data type for any variable as it is interpreted at runtime by the machine itself. In these languages, interpreters assign the data type to a variable at runtime depending on its value. We don’t even need to specify the type of variable that a function is returning or accepting in these languages. JavaScript, Python, Ruby, Perl, etc are examples of dynamically typed languages.
Example: This example demonstrates JavaScript as a dynamically typed language:
Example in python: age=10
Reference:https://www.geeksforgeeks.org/what-is-a-typed-language/
➢ Data Types in Java:-
Data types refer to the different sizes and values that can be stored in the variable.
Two types of data type are in Java programming:
(A) Primitive data types: The primitive data types consist of int, float,boolean, byte, short, long, char and double.
(B) Non-primitive data types(TBD): The non-primitive data types include
arrays, interfaces and class etc.
➢ Java Primitive Data Types:-
There are following primitive data types available in Java
programming language.
(1) Byte data type
(2) Boolean data type
(3) Int data type
(4) Short data type(TBD)
(5) Char data type
(6) Double data type
(7) Float data type
(8) Long data type(TBD)
(1) Byte Data Type: - It is the first data type with least memory size
allocation which can be used for numbers of small ranges.
(a) The memory size is allocated 1 byte.
(b) It can represent a total 256(28).
(c) byte can represent from 0 to 127 on positive side (as zero is positive number
per programming) and on the negative side it can represent the number -1 to
128.
(d) The default value for byte is zero (0).
Example:- byte a1 = 10;
(2) Boolean Data Type: - The boolean data type is a one bit information.
Only two possible values are of Boolean data type. Which are true and
false.
(a) It has not something range of values of the variable.
(b) The values true or false are case-sensitive keywords.
Example:- boolean a = false; boolean b=true;
(3) Int Data Type:-
The int data type is a 32-bits signed type. Minimum value of int data type is -
2,147,483,648 and maximum value of int data type is 2,147,483,647 precision
type.
(a) Its default value is 0.
(b) On the positive side 0 to 2,147,483,647 and on the negative side -1 to
2,147,483,647
(c) It can represent a total of 4,294,967,296
Example:- int a = 100000;
int b = -200000;
(4) Short Data Type:-
The short data type is a 16-bit signed type. Its value-range lies between -
32,768 to 32,767. Minimum value of short is -32,768 and maximum value
of short is 32,767.
(a) Its default value is 0.
(b) It can represent total 65536(216) numbers.
Example:- short s = 10000;
(5) Char Data Type:-
It has a single 16-bit Unicode character. Value-range of char data type lies
between -127 to 128 .The char data type is used to store characters.
(a) It stores a single character such as a letter, number and punctuation mark
or other symbol.
(b) Characters are a single letter enclosed in single quotes.
Example:- char b = 'A'; char a=’#’;
(6) Double Data Type:-
double data type is a 64 bits signed type. Its value range is unlimited. The
double data type is generally used for decimal (points) values just like float. The
double data type does not use for precise values, such as currency.
(a) Its default value is 0.0d.
Example:- double d1 = 122.39;
(7) Float Data Type:-
The float data type has a single-precision 32-bits types and its value range is
unlimited.
(a) Its default value is 0.0F.
Example:- float f1 = 134.5f;
(8) Long Data Type:-
It has a 64-bit two's complement integer.
Minimum value long data type is - 9,223,372,036,854,775,808 and
maximum value of long data type is 9,223,372,036,854,775,807.
(a) Its default value is 0.
Example:- long a = 100000L;
➢ Non-Primitive Data Types:-(TBD)
There are following non- primitive data types available
in Java programming language.
(1) Array: - An array is the collection of homogeneous
(or similar types) data type.
(a) An array is an object that holds a fixed number of
values of homogeneous or similar data-type.
(b) The length of an array is assigned when the array is
created and after creation, its length is fixed.
Example:- int a[]=new int[6];
(2) Class: - A class is a “user defined data type” from which objects are
created of class. In general, class declarations can include components. And
it consists of data and methods in the form of a unit.
(a) Modifiers: - A class can be public or default access.
(b) Class name: - The name of class should begin with an initial capital letter.
(c) Body: - The class body is enclosed by braces {}.
Example: - public class car
(3) Interface(TBD): - An interface is basically a kind of class. So an interface is collection of “methods” without actual definitions and “variables”.Thus it is the responsibility of the class that to define and implement thecodes of these methods.
Example: -
`interface item
{
Static final int code=101;
Static final string name =”fan”;
Void display ();
}
Reference:https://www.geeksforgeeks.org/data-types-in-java/
Example for Primitive data types:
public class Players
{
int score;//Primitive data types
float strikeRate;//Primitive data types
public static void main (String[] args)
{
Players rohit=new Players();//object creation
Players virat=new Players();//object creation
rohit.score=98;
virat.score=86;
rohit.strikeRate=98.8f;
virat.strikeRate=85.5f;
System.out.println(rohit.strikeRate);
System.out.println(virat.strikeRate);
}
}
OUTPUT:
neelakandan@neelakandan-HP-Laptop-15s-eq2xxx:~/Documents/B14$ javac Players.java
neelakandan@neelakandan-HP-Laptop-15s-eq2xxx:~/Documents/B14$ java Players
98.8
85.5
neelakandan@neelakandan-HP-Laptop-15s-eq2xxx:~/Documents/B14$ ^C
neelakandan@neelakandan-HP-Laptop-15s-eq2xxx:~/Documents/B14$
Top comments (0)