data types in java | AsgarTech

 AsgarTech



 data types in java

In Java, data types define the type of data that can be stored in a variable. There are two categories of data types in Java: primitive and non-primitive (also known as reference types).


Primitive data types are the basic data types built into the Java language. There are eight primitive data types in Java:


byte - an 8-bit integer with a range from -128 to 127.

short - a 16-bit integer with a range from -32,768 to 32,767.

int - a 32-bit integer with a range from -2,147,483,648 to 2,147,483,647.

long - a 64-bit integer with a range from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.

float - a 32-bit floating-point number.

double - a 64-bit floating-point number.

char - a 16-bit Unicode character.

boolean - a true/false value.


Strings. These data types are defined by the programmer and are based on the primitive data types


Here's an example of declaring variables with different data types in Java:


Example code:

int myInt = 10;
double myDouble = 3.14;
boolean myBoolean = true;
char myChar = 'a';
String myString = "Hello, World!";
int[] myArray = {1, 2, 3, 4, 5};


In the example above, we declared variables with different data types, including int, double, boolean, char, String, and an int array. By knowing the different data types in Java, you can declare variables with the appropriate type to hold the data you need to store.



how to give introduction for begineers/student

sum of two variable in c , c++ , java , python by taking value from user

Data types In C programming

asgarTech

No comments: