xxxxxxxxxx
class HelloWorld {
public static void main(String[] args) {
String a = "aaaa";
int num = 123;
final String cons = "I am constant";
System.out.print(a);
System.out.print(num);
System.out.print(cons);
}
}
xxxxxxxxxx
/* Depending on what variables you want to declare */
String hello = "hello"; //characters
short one = 12;//shorter integers
int two = 2000; //complete integer up too 32 bits
long number = 2000000; //complete integer up to 64 bits
float decimal = 1.512 //up to 7 decimal digits
double million = 1.387892847395 //up tp 16 decmial digits
Bool condition = true; // true or false
char a = "a"; // unicode character
xxxxxxxxxx
class Variables {
public static void main(String[] args) {
String msg = "Hello World"; // Strings
int number = 10; // Integers
float decimal = 7.369f; // Make sure to end the decimal with an f.
char letter = 'A'; // Characters
boolean result = true; // Booleans
}
}
xxxxxxxxxx
// Variable declaration and assignment
int myVariable = 10;
String myString = "Hello, World!";
boolean myBool = true;
double myDouble = 3.14;
// Variable usage
System.out.println(myVariable);
System.out.println(myString);
System.out.println(myBool);
System.out.println(myDouble);
xxxxxxxxxx
//variable is a container which holds the value//
//ex://
var characters = document.getElementbyID('character').value;
//above the variable is characters and value is character//
xxxxxxxxxx
//this are the most common ones
int x = 5;
String y = "hello";
System.out.println(x + y);
xxxxxxxxxx
/*
## Variable
- Container which holds the value while the Java program is executed.
- Assigned with a data type.
- Name of memory location.
## There are three types of variables in java:
1) Local variable
2) Static (or class) variable
3) Instance variable
*/
xxxxxxxxxx
improve the readability of code for other developers who read the code.
In some situations
xxxxxxxxxx
int a, b, c; // Declares three ints, a, b, and c.
int a = 10, b = 10; // Example of initialization
byte B = 22; // initializes a byte type variable B.
double pi = 3.14159; // declares and assigns a value of PI.
char a = 'a';