|
1 |
| -package coreJava; |
2 |
| - |
3 |
| -public class DataTypes { |
4 |
| - |
5 |
| - public static void main(String[] args) { |
| 1 | + package coreJava; |
6 | 2 |
|
7 |
| - //variables |
8 |
| - |
9 |
| - //int s; //declaration |
10 |
| - //s=100; //assignment |
11 |
| - |
12 |
| - int s=100; // declaration+assignment |
13 |
| - System.out.println(s); |
14 |
| - |
15 |
| - s=200; |
16 |
| - System.out.println(s); |
| 3 | + public class DataTypes { |
| 4 | + |
| 5 | + public static void main(String[] args) { |
17 | 6 |
|
| 7 | + //variables |
| 8 | + |
| 9 | + //int s; //declaration |
| 10 | + //s=100; //assignment |
| 11 | + |
| 12 | + int s=100; // declaration+assignment |
| 13 | + System.out.println(s); |
| 14 | + |
| 15 | + s=200; |
| 16 | + System.out.println(s); |
| 17 | + |
18 | 18 | /*
|
19 | 19 | // approach1 // if all the variables belongs to different data types
|
20 | 20 | int p=1;
|
21 | 21 | int o=2;
|
22 | 22 | int i=3;
|
23 | 23 | */
|
24 |
| - |
25 |
| - /* approach2 // only if allthe variable are belongs to same data type |
| 24 | + |
| 25 | + /* approach2 // only if all the variable are belongs to same data type |
26 | 26 | int p,o,i;
|
27 | 27 | p=1;
|
28 | 28 | o=2;
|
29 | 29 | i=3;
|
30 | 30 | */
|
31 |
| - |
| 31 | + |
32 | 32 | // approach3 //only if all the variable are belongs to same data type
|
33 |
| - int p=1,o=2,i=3; |
34 |
| - |
| 33 | + int p=1,o=2,i=3; |
| 34 | + |
35 | 35 | //for meaningful message in print statement we can use concatenation method
|
36 |
| - System.out.println("The Value of p is :"+p); |
37 |
| - System.out.println("The Value of o is :"+o); |
38 |
| - System.out.println("The Value of i is :"+i); |
| 36 | + System.out.println("The Value of p is :"+p); |
| 37 | + System.out.println("The Value of o is :"+o); |
| 38 | + System.out.println("The Value of i is :"+i); |
39 | 39 |
|
40 | 40 | // in single line we printed all variable values
|
41 |
| - System.out.println(p+""+o+""+i+""); |
42 |
| - |
| 41 | + System.out.println(p+""+o+""+i+""); |
| 42 | + |
43 | 43 | // in print statement we used join method for each value with ""
|
44 | 44 |
|
45 | 45 |
|
46 |
| -//-------------------------------------------------------------------------- |
| 46 | + //-------------------------------------------------------------------------- |
47 | 47 | // Data types
|
48 |
| - |
49 |
| - // Numeric Data Types |
50 |
| - |
51 |
| - int a=100, b=200; |
52 |
| - System.out.println("The Value of a is :"+a); |
53 |
| - System.out.println("The Value of b is :"+b); |
54 |
| - System.out.println(a+b); |
55 |
| - System.out.println("The sum of an and b is : "+(a+b)); |
56 |
| - |
57 |
| - byte by=125; |
58 |
| - System.out.println(by); |
59 |
| - |
60 |
| - short sh=32767; |
61 |
| - System.out.println(sh); |
62 |
| - |
63 |
| - long l=21212121234443534L; // literal is needed |
64 |
| - // L should add, it can be lower or uppercase |
65 |
| - System.out.println(l); |
66 |
| - |
67 |
| - // Decimal numbers - float, double |
68 |
| - |
69 |
| - float item_price=15.5f; // literal is needed |
70 |
| - //f should add, it can be lower or uppercase |
71 |
| - System.out.println(item_price); |
72 |
| - |
73 |
| - double dbl=1234.4343412; |
74 |
| - System.out.println(dbl); |
75 |
| - |
76 |
| - // characters |
77 |
| - |
78 |
| - char grade='A'; // single character in single quotes - '' |
79 |
| - System.out.println(grade); |
80 |
| - |
81 |
| - String name="Harish"; // String is non-premitive type and multiple characters with double quotes - "" |
82 |
| - System.out.println(name); |
83 |
| - |
84 |
| - //char ch='abc'; //invalid |
85 |
| - //Stirng ch='abc';//invalid |
86 |
| - //String ch='A';//invalid |
87 |
| - String ch="A"; //valid |
88 |
| - System.out.println(ch); |
89 |
| - |
90 |
| - boolean bl=true; //allows only true or false |
91 |
| - System.out.println(bl); |
92 |
| - |
93 |
| - boolean bl1=false;//allows only true or false |
94 |
| - System.out.println(bl1); |
95 |
| - |
96 |
| - //boolean bl="true";//invalid |
97 |
| - //boolean bl="false";//invalid |
98 |
| - |
99 |
| - //String bl=true;//invalid |
100 |
| - String bl2="true";//valid |
101 |
| - |
102 |
| - //---------------------------------------------------------------------- |
103 |
| - |
104 |
| - //difference between variable and const/final |
105 |
| - int x=100; |
106 |
| - System.out.println(x); |
107 |
| - x=200; |
108 |
| - System.out.println(x); |
109 |
| - |
110 |
| - final int y=300; |
111 |
| - System.out.println(y); |
112 |
| - // y=400;// not allowed |
113 |
| - //System.out.println(y); |
114 |
| - |
115 |
| - // variables declaration without final keyword we can change the values but wiht final keyword we cnat chaneg the value. in javascript instea dof final, const keyword is used. |
116 |
| - |
117 |
| - //java is statistically typed programming language |
118 |
| - //python is dynamically typed programming language |
119 |
| - //javascript is dynamically typed scripting language |
120 |
| - |
121 |
| - //Example : |
122 |
| - |
123 |
| - int q=100; |
124 |
| - //x="welcome";//it is not allowed in java but in javascript and python it is allowed |
125 |
| - //in python or javascript we no need to specify the data types explicitly. |
126 |
| - |
127 |
| - /* |
128 |
| - r=100; |
129 |
| - r="welcome"; |
130 |
| - */ |
131 |
| - //it is allowed in dynamically typed programming language - javascript / python |
| 48 | + |
| 49 | + // Numeric Data Types |
| 50 | + |
| 51 | + int a=100, b=200; |
| 52 | + System.out.println("The Value of a is :"+a); |
| 53 | + System.out.println("The Value of b is :"+b); |
| 54 | + System.out.println(a+b); |
| 55 | + System.out.println("The sum of an and b is : "+(a+b)); |
| 56 | + |
| 57 | + byte by=125; |
| 58 | + System.out.println(by); |
| 59 | + |
| 60 | + short sh=32767; |
| 61 | + System.out.println(sh); |
| 62 | + |
| 63 | + long l=21212121234443534L; // literal is needed |
| 64 | + // L should add, it can be lower or uppercase |
| 65 | + System.out.println(l); |
| 66 | + |
| 67 | + // Decimal numbers - float, double |
| 68 | + |
| 69 | + float item_price=15.5f; // literal is needed |
| 70 | + //f should add, it can be lower or uppercase |
| 71 | + System.out.println(item_price); |
| 72 | + |
| 73 | + double dbl=1234.4343412; |
| 74 | + System.out.println(dbl); |
| 75 | + |
| 76 | + // characters |
| 77 | + |
| 78 | + char grade='A'; // single character in single quotes - '' |
| 79 | + System.out.println(grade); |
| 80 | + |
| 81 | + String name="Harish"; // String is non-premitive type and multiple characters with double quotes - "" |
| 82 | + System.out.println(name); |
| 83 | + |
| 84 | + //char ch='abc'; //invalid |
| 85 | + //Stirng ch='abc';//invalid |
| 86 | + //String ch='A';//invalid |
| 87 | + String ch="A"; //valid |
| 88 | + System.out.println(ch); |
| 89 | + |
| 90 | + boolean bl=true; //allows only true or false |
| 91 | + System.out.println(bl); |
| 92 | + |
| 93 | + boolean bl1=false;//allows only true or false |
| 94 | + System.out.println(bl1); |
| 95 | + |
| 96 | + //boolean bl="true";//invalid |
| 97 | + //boolean bl="false";//invalid |
| 98 | + |
| 99 | + //String bl=true;//invalid |
| 100 | + String bl2="true";//valid |
| 101 | + |
| 102 | +//---------------------------------------------------------------------- |
| 103 | + |
| 104 | + //difference between variable and const/final |
| 105 | + int x=100; |
| 106 | + System.out.println(x); |
| 107 | + x=200; |
| 108 | + System.out.println(x); |
| 109 | + |
| 110 | + final int y=300; |
| 111 | + System.out.println(y); |
| 112 | + // y=400;// not allowed |
| 113 | + //System.out.println(y); |
| 114 | + |
| 115 | + // variables declaration without final keyword we can change the values but wiht final keyword we cnat chaneg the value. in javascript instea dof final, const keyword is used. |
| 116 | + |
| 117 | + //java is statistically typed programming language |
| 118 | + // python is dynamically typed programming language |
| 119 | + //javascript is dynamically typed scripting language |
| 120 | + |
| 121 | + //Example : |
| 122 | + |
| 123 | + int q=100; |
| 124 | + //x="welcome";//it is not allowed in java but in javascript and python it is allowed |
| 125 | + //in python or javascript we no need to specify the data types explicitly. |
| 126 | + |
| 127 | + /* |
| 128 | + r=100; |
| 129 | + r="welcome"; |
| 130 | + */ |
| 131 | + //it is allowed in dynamically typed programming language - javascript / python |
132 | 132 |
|
133 | 133 | }
|
134 | 134 |
|
|
0 commit comments