Skip to content

Commit 455ebbd

Browse files
authored
Merge pull request #3 from uvhareesh/develop
Operators concept
2 parents 933edf0 + 196fd9d commit 455ebbd

File tree

6 files changed

+318
-110
lines changed

6 files changed

+318
-110
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package coreJava;
2+
3+
public class AssignmentOperators {
4+
5+
public static void main(String[] args) {
6+
//5. Assignment = += -+ *= /= %=
7+
8+
int a=10;
9+
int b=10;
10+
a+=5; //a=a+5;
11+
b=b-5; //b=b-5;
12+
System.out.println(a);
13+
System.out.println(b);
14+
15+
int c=10;
16+
a*=2; //c=c*2;
17+
System.out.println(c);
18+
19+
int d=10;
20+
d/=2; //d=d/2;
21+
System.out.println(d);
22+
23+
int e=10;
24+
e%=2; //e=e%2;
25+
System.out.println(e);
26+
27+
/* difference b/w == = ?
28+
* == is relational operators it compares the value
29+
* = is assignment operator , it assigns the value
30+
*/
31+
32+
}
33+
34+
}

src/coreJava/DataTypes.java

Lines changed: 110 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,134 +1,134 @@
1-
package coreJava;
2-
3-
public class DataTypes {
4-
5-
public static void main(String[] args) {
1+
package coreJava;
62

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) {
176

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+
1818
/*
1919
// approach1 // if all the variables belongs to different data types
2020
int p=1;
2121
int o=2;
2222
int i=3;
2323
*/
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
2626
int p,o,i;
2727
p=1;
2828
o=2;
2929
i=3;
3030
*/
31-
31+
3232
// 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+
3535
//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);
3939

4040
// in single line we printed all variable values
41-
System.out.println(p+""+o+""+i+"");
42-
41+
System.out.println(p+""+o+""+i+"");
42+
4343
// in print statement we used join method for each value with ""
4444

4545

46-
//--------------------------------------------------------------------------
46+
//--------------------------------------------------------------------------
4747
// 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
132132

133133
}
134134

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package coreJava;
2+
3+
public class DecrementOperators {
4+
5+
public static void main(String[] args) {
6+
//5.Decrement operators --
7+
8+
//case1
9+
int a=10;
10+
System.out.println(a);
11+
12+
// a=a-1;
13+
//instead of writing 2 times "a" we can use below code
14+
a--;
15+
System.out.println(a);
16+
17+
//case2 post decrement
18+
19+
int b=10;
20+
int res=b--;
21+
System.out.println(res);
22+
23+
//expected o/p is 11 but we received 10 because first 10 is assigned to res then value is decrement with a++
24+
//first assignment is happen then decrement will happen
25+
26+
System.out.println(a);
27+
28+
//case3 Pre increment
29+
30+
int c=10;
31+
int res1=--c;
32+
System.out.println(res1);
33+
// first decrement the value then assignment is happen
34+
35+
System.out.println(c);
36+
37+
}
38+
39+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package coreJava;
2+
3+
public class IncrementOperator {
4+
5+
public static void main(String[] args) {
6+
7+
//4.Increment & Decrement operators ++ --
8+
9+
//case1
10+
int a=10;
11+
System.out.println(a);
12+
13+
// a=a+1;
14+
//instead of writing 2 times "a" we can use below code
15+
a++;
16+
System.out.println(a);
17+
18+
//case2 post increment
19+
20+
int b=10;
21+
int res=b++;
22+
System.out.println(res);
23+
24+
//expected o/p is 11 but we received 10 because first 10 is assigned to res then value is incremented with a++
25+
//first assignment is happen then increment will happen
26+
27+
System.out.println(a);
28+
29+
//case3 Pre increment
30+
31+
int c=10;
32+
int res1=++c;
33+
System.out.println(res1);
34+
// first increment the value then assignment is happen
35+
36+
System.out.println(c);
37+
38+
}
39+
40+
}

0 commit comments

Comments
 (0)