0% found this document useful (0 votes)
7 views19 pages

02.2 From C To Java

The document provides an introduction to Java, highlighting its powerful features, object-oriented nature, and syntax similarities to C/C++. It includes instructions for setting up Java on a local machine, comparisons between C and Java, and examples of basic code structures, variable declarations, and operators in Java. Additionally, it covers fundamental data types and relational operators.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views19 pages

02.2 From C To Java

The document provides an introduction to Java, highlighting its powerful features, object-oriented nature, and syntax similarities to C/C++. It includes instructions for setting up Java on a local machine, comparisons between C and Java, and examples of basic code structures, variable declarations, and operators in Java. Additionally, it covers fundamental data types and relational operators.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Introduction to Java

- SUBANGKAR KARMAKER SHANTO


Why Java?
▪Very powerful language
▪Object Oriented
▪Syntax similar to C/C++
▪Omits complex & unsafe features
▪Type safety
▪Garbage Collection
▪Popular Frameworks: Spring Boot Framework
SETUP IN LOCAL MACHINE
Running Java
❑Install JDK & JRE, add to PATH and run from terminal
❑JDK8+
❑Install IDE
❑IntelliJ IDEA
(https://www.jetbrains.com/idea/download/#section=windows)
❑NetBeans (https://netbeans.org/)
❑Eclipse
(https://www.eclipse.org/downloads/packages/release/neon/2/eclipse-
ide-java-developers)
Online IDE
▪Many available sites. Use any of them. Followings are some of them:
▪ https://www.onlinegdb.com/online_java_compiler
▪ https://www.tutorialspoint.com/compile_java_online.php
▪ https://www.jdoodle.com/online-java-compiler/
▪ https://repl.it/languages/java10
FROM C to JAVA
Comparision
C JAVA

▪File extension: main.c ▪File extension: main.java


▪Program is compiled ▪Program is first compiled and then interpreted
▪OS dependent ▪OS independent. Thanks to JVM
Minimal Code block to Run
C JAVA

public class Main{

void main() { public static void main(String[] args) {

} }

}
Minimal Code block to Run
C JAVA
// return type of main can be void or int // return type of main must be void

public class Main{

int main() { public static void main(String[] args) {

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;

char c = 'A'; char c = 'A';

float f, double d; float f, double d;

int mask = 0; boolean mask = false;

char *s = "abcd"; String s = "abcd";

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;

char *s = "abcd"; String s = "abcd";

printf("%s", s); System.out.println(s)

printf("%s-%d", s, x); System.out.println(s + "-" + x)

return 0;
}
}
}
Arithmetic Operators
▪Addition (+) class Arithmetic {

public static void main(String[] args) {


▪Subtraction (-) int x = 12;

▪Multiplication (*) int y = 2 * x;

System.out.println(y);
▪Division (/)
int z = (y - x) % 5;
▪Modulus (%) System.out.println(z);

final float pi = 3.1415F;

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

You might also like