Data Types used in Java

0 views
Skip to first unread message

G C Reddy Software Testing

unread,
Aug 12, 2022, 3:21:51 AM8/12/22
to gcr...@googlegroups.com
Data Types used in Java
https://youtu.be/aevYqwr2nDg
-------------------------------------------
1. Data Type is a classification of the type of data that a variable or final variable/constant or method can store in a computer program

a. Variables
b. Final Variables/Constant
c. Method (with return a value)
d. Method Arguments

Example:

1.
int x=100;
String country="India";

2.
public int add(int num1, int num2) {
int result;
result=num1+num2;
return result;
}

3.
(int num1, int num2)

4.
final int price=1000;

2. Data Types specify sizes and types that can be stored in a variable.

byte a=100;
short b=10000;
int c=100000;
long d=9898787876l;

String x="Hyderabad";
char y='R';
boolean z= true;

3. Java Supports Explicit Declaration of data types

Java:

int x;
x=100;
x=10.23; //Invalid
y=200;

Python:

x=100
.
.
x="India"
.
.
x=10.234

4. Java Data Type Conversion

Assign Values to Variables is two types
1. Initialization
int x=100;
int y;
.
.
y=1234;

2. Reading
Read User Input
Read data from files

India - > "India" - No conversion
100 -> "100" - Convert the String type data to integer type
10.234 - > "10.234" - Convert the String type data to float type

Ex:
String num1="10";
String num2="20";

System.out.println(num1+num2);//1020
int x= Integer.parseInt(num1);
int y= Integer.parseInt(num2);
System.out.println(x+y);//20
-------------------------------------------

Reply all
Reply to author
Forward
0 new messages