Home Java javaTutorial TODAY CLASS-BOUT- STATE,DATATYPE.

TODAY CLASS-BOUT- STATE,DATATYPE.

Jan 02, 2025 pm 02:55 PM

TODAY CLASS-BOUT- STATE,DATATYPE.

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 ();
}
Copy after login

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);
}

}
Copy after login

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$ 

Copy after login

The above is the detailed content of TODAY CLASS-BOUT- STATE,DATATYPE.. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1267
29
C# Tutorial
1239
24
Is the company's security software causing the application to fail to run? How to troubleshoot and solve it? Is the company's security software causing the application to fail to run? How to troubleshoot and solve it? Apr 19, 2025 pm 04:51 PM

Troubleshooting and solutions to the company's security software that causes some applications to not function properly. Many companies will deploy security software in order to ensure internal network security. ...

How do I convert names to numbers to implement sorting and maintain consistency in groups? How do I convert names to numbers to implement sorting and maintain consistency in groups? Apr 19, 2025 pm 11:30 PM

Solutions to convert names to numbers to implement sorting In many application scenarios, users may need to sort in groups, especially in one...

How to simplify field mapping issues in system docking using MapStruct? How to simplify field mapping issues in system docking using MapStruct? Apr 19, 2025 pm 06:21 PM

Field mapping processing in system docking often encounters a difficult problem when performing system docking: how to effectively map the interface fields of system A...

How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log? How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log? Apr 19, 2025 pm 11:45 PM

Start Spring using IntelliJIDEAUltimate version...

How to elegantly obtain entity class variable names to build database query conditions? How to elegantly obtain entity class variable names to build database query conditions? Apr 19, 2025 pm 11:42 PM

When using MyBatis-Plus or other ORM frameworks for database operations, it is often necessary to construct query conditions based on the attribute name of the entity class. If you manually every time...

How to safely convert Java objects to arrays? How to safely convert Java objects to arrays? Apr 19, 2025 pm 11:33 PM

Conversion of Java Objects and Arrays: In-depth discussion of the risks and correct methods of cast type conversion Many Java beginners will encounter the conversion of an object into an array...

How to use the Redis cache solution to efficiently realize the requirements of product ranking list? How to use the Redis cache solution to efficiently realize the requirements of product ranking list? Apr 19, 2025 pm 11:36 PM

How does the Redis caching solution realize the requirements of product ranking list? During the development process, we often need to deal with the requirements of rankings, such as displaying a...

E-commerce platform SKU and SPU database design: How to take into account both user-defined attributes and attributeless products? E-commerce platform SKU and SPU database design: How to take into account both user-defined attributes and attributeless products? Apr 19, 2025 pm 11:27 PM

Detailed explanation of the design of SKU and SPU tables on e-commerce platforms This article will discuss the database design issues of SKU and SPU in e-commerce platforms, especially how to deal with user-defined sales...

See all articles