Java Fundamentals by Rahul Chauhan
Java Fundamentals by Rahul Chauhan
T
Source Code
Translator Machine Code Computer
(Compiler or
or
Or Software
Program
Interpreter)
Arithmetic + - * / %
Shorthand/Compound += -= *= /= %=
Increment-Decrement ++ --
Relational < <= > >= == !=
Logical && || !
Conditional ?:
Assignment =
Arithmetic + - * / %
Shorthand/Compound += -= *= /= %=
Increment-Decrement ++ --
Relational < <= > >= == !=
Logical && || !
Conditional ?:
int a; 10 = a;
a = 10;
int a = 10;
int a = 10, b = 15;
int a, b;
a = b = 10;
int a; int a;
a = 10 / 2; a = 10 % 2;
SOP(a); SOP(a);
10 ++ ; int a=10;
a+ +;
SOP(a);
true false
Exp. 2 Exp. 3
int a=10,b=5;
int c=a<b ? a+12/3-2 : b%5+a-7;
SOP(c);
Integer Integer
+
Character - Integer
* Integer
Integer / Character
% Character
Character
For Example:
7+2 = 9
7/2 = 3 (not 3.5)
‘a’+10 = 107
10+ ‘a’ = 107
‘h’*10 = 1040
For Example:
7.0+2 = 9.0
7/2.0 = 3.5
‘a’+10.1=107.1
10.0+ ‘a’=107.0
‘h’*10.0=1040.0
Floating Point
String
String +
Character
String
Integer
Floating Point
String String
+
Character
String
For Example:
5 + “hi” = “5hi”
“hi”+5 = “hi5”;
4+2+ “hi” = “6hi”
5.8+ “hi” = “5.8hi”;
5+6+ “hi” + 5+6= “11hi56”
“hello”+ “hi” = “hellohi”
“hello”+ ‘a’= “helloa” (not hello97)
‘a’ + “hello” = “ahello”
Integer
-
Floating Point
*
String
Character /
%
String
int age=15;
if (age>60) {
// statements of if
}
else if (age>18) {
// statements of else if
}
else {
// statements of else
}
// statements after if else if
while ( TestExpression) {
// statements
}
do {
// statements
} while ( TestExpression) ;
while (Test-Exp){
// statements
if (BreakCondition) {
// statements
break;
}
// statements
}
while (Test-Exp){
// statements
if (BreakCondition) {
// statements
continue;
}
// statements
}
void display ( ) {
SOP( “I Love My INDIA” );
SOP( “I Live in INDIA” );
SOP( “I am Happy” );
}
Function Body
Types of Functions:
• Function with No Arguments and No Return Type
• Function with Arguments but No Return Type
• Function with No Arguments but Return Type
• Function with Arguments and Return Type
• Function with simple Return keyword