-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava_varaiables.java
More file actions
79 lines (53 loc) · 1.69 KB
/
Copy pathjava_varaiables.java
File metadata and controls
79 lines (53 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package first1.java;
public class java_varaiables {
public static void main(String[] args) {
//byte b=-129;
//byte b=128;
//range should between -128 to 127
//short s=32768;
//range for short is -32768 to 32767
/*
* Multi line comment
*
*/
//TYPE PROMOTION AND TYPE CASTING
byte b=10;
byte c=10;
int d=b*c;//the result of a arithmetic operation will give u a integer by default - type promotion has happened
System.out.println(d);
byte ee=(byte)d;
System.out.println(ee);
int value=257;
byte e=(byte)value;
System.out.println(e);
byte x=100;
int xint=x;//compatible - its like a bigger vessel taking a smaller vessel in it.
double dd=23.456;
int intdd=(int)dd;
System.out.println(intdd);//this will also loose the precision
//VALID IDENTIFIERS
// variables are suppose to adhere with qualified names (valid identifiers)
//int 2i; - Variable name cannot start with a number
//int %i; - Variable name cannot start with a special character other than $ and _ .
int _i;// valid identifier - _ is accepted
int $i;// valid identifier - $ is accepted
int money$_1;//valid identifier - can also be combination - number can be added in between or at the end.
//IDENTIFIER DECLARATION AND INITIALIZATION
//number types
byte bnum=100;
short snum=100;
int num=100;
long lnum=100;
//floating
float fnum=100.12f;
double dnum=34.434;
//character
char cc='A';// character is of int type
int ccint=cc;
System.out.println("ASCII value of a...."+ccint);
int myint=169;
System.out.println((char)myint);
boolean boo=true;//in java it wont accept 0 or 1
String str="hello world";
}
}