02.2 From C To Java
02.2 From C To Java
} }
}
Minimal Code block to Run
C JAVA
// return type of main can be void or int // return type of main must be void
return 0;
} }
}
Minimal Code block to Run
C JAVA
public class Main{
int main(int argc, char* argv[]) { public static void main(String[] args) {
return 0;
} }
}
Variable Declaration
C JAVA
public class Main{
int main(int argc, char* argv[]) { public static void main(String[] args) {
int x = 5; int x = 5;
return 0; }
} }
Fundamental Types in Java
▪Integers: byte, short, int, long
▪Floating points: float, double
▪Characters: char
▪boolean
▪void
▪String
Output
C JAVA
public class Main{
int main(int argc, char* argv[]) { public static void main(String[] args) {
int x = 5; int x = 5;
return 0;
}
}
}
Arithmetic Operators
▪Addition (+) class Arithmetic {
System.out.println(y);
▪Division (/)
int z = (y - x) % 5;
▪Modulus (%) System.out.println(z);
float f = pi / 0.62F;
System.out.println(f);
}
Arithmetic Operators
Shorthand operators are also provided:
Arithmetic Operators
Pre/Post operators:
Relational Operators
▪Operators:
▪Equivalent (==)
▪Not Equivalent (!=)
▪Less than (<)
▪Greater than (>)
▪Less than or equal (<=)
▪Greater than or equal (>=)
▪Relational Expressions always returns boolean value
Relational Expressions
THANK YOU