Language Comparison

Download as pdf or txt
Download as pdf or txt
You are on page 1of 38

Language Comparison

Java, C#, Python and JavaScript

SoftUni Team
Technical Trainers
Software University
https://softuni.org
Table of Contents

1. Execution Model
2. Variables
3. Data Types
4. Printing on the Console
5. Conditional Statements
6. Loops
7. Development Environments (IDE)
2
Have a Question?

sli.do
#
3
Execution Model
Compiler vs. Interpreter
Language Execution Model
▪ Compiled languages source
code
compiler machine execution
code

▪ Source code is first compiled to machine code, then executed


▪ Syntax errors are found during the compilation (at compile time)
▪ Examples: C#, Java, C, C++, Swift, Go, Rust
▪ Interpreted languages source
code
execution

▪ Each command is read, parsed and executed by an interpreter


▪ Syntax errors are found at run-time, during execution
▪ Examples: Python, JavaScript, PHP, Perl, Ruby
5
Statically-Typed vs. Dynamic Typed
▪ Type systems in programming languages
▪ Statically-typed languages perform int n = 5; C#
type checking at compile time n = "Hi"; // error!
▪ Examples: C#, Java, Swift, C++ int func(int n) { … }

▪ Dynamically-typed languages
let n = 5; JS
perform type checking at runtime
n = "Hi"; // OK
▪ Examples: Python, JS, PHP
function f(n) { … }
▪ Combined typing: C#, TypeScript,
Objective-C, Dart, …
6
Variables
Declaring Variables in C#, Java, JS and Python
Declaring Variables in C# / Java
▪ To declare variable in C# / Java you need to use the pattern:
{data type} {variable name} = {value};

▪ C# ▪ Java
int firstNumber = 5; int firstNumber = 5;
string name = "Peter"; String name = "Peter";
bool isPassed = false; boolean isPassed = false;
char gender = 'F'; char gender = 'F';
double mathGrade = 5.49; double mathGrade = 5.49;
8
Declaring Variables in JavaScript
▪ To declare variable in JS you need to use the keyword let:
let {variable name} = {value};

▪ Examples:
let firstNumber = 5;
let name = "Peter";
let isPassed = false;
let mathGrade = 5.49;

9
Declaring Variables in Python
▪ Python has no keyword for declaring a variable
▪ Variables do not need to be declared with any particular type
▪ Examples of using variables in Python:
first_number = 5
name = "Peter"
is_passed = False
math_grade = 5.49

10
Data Types
Data Types in C#, Java, JS and Python
Primitive Data Types in C# and Java
▪ Built-in data types in C# ▪ Built-in data types in Java
▪ Integer – int, long ▪ Integer – int, long
▪ Real number – double, float ▪ Real number – double, float
▪ Text – string, char ▪ Text – String, char
▪ Boolean – boolean
▪ Boolean – bool
▪ Other – Object
▪ Other – object
int size = 50;
int size = 50; ((Object)size).getClass(
size.GetType() Int32 ) Integer

12
Data Types in JavaScript
▪ In JS data types are inferred from the values
▪ Not explicitly specified at variable declaration
▪ Primitive data types:
▪ number let size = 50;
▪ string typeof(size) number
▪ boolean let name = "Peter";
typeof(name) string
▪ object
let arr = [3, 5, 8];
▪ null
typeof(arr) object
▪ undefined
13
Data Types in Python
▪ In Python variables keep values of certain type
▪ The data type is inferred from the value
▪ Built-in data types in Python:
▪ int size = 50;
▪ float type(size) int
name = "Peter"
▪ str
type(name) str
▪ boolean values = [2, 3, 4]
▪ list type(values) list
14
Printing on the Console
Printing Data in C#, Java, JS and Python
Printing on the Console in C#
▪ Printing content and then going to a new line
Console.WriteLine("Peter");

▪ Printing content and staying on the same line


Console.Write(" and Maria");

▪ Printing with formatting


string name = "Maria";
int age = 25;
Console.WriteLine(
$"{name} is {age} years old.");
16
Printing on the Console in Java
▪ Printing content and then going to a new line
System.out.println("Peter");

▪ Printing content and staying on the same line


System.out.print(" and Maria");

▪ Printing with formatting


String name = "Maria";
int age = 25;
System.out.printf(
"%s is %d years old.", name, age);
17
Printing on the Console in JavaScript
▪ Printing content and then going to a new line
console.log("Peter");

▪ Printing content and staying on the same line


process.stdout.write("and Maria");
Works only at
▪ Printing with formatting the server-side

let name = "Maria";


let age = 25;
console.log(
`${name} is ${age} years old.`);
18
Printing on the Console in Python
▪ Printing content and then going to a new line
print("Peter");

▪ Printing content and staying on the same line


print("and Maria", end='');

▪ Printing with formatting


name = "Maria";
age = 25;
print(
f'{name} is {age} years old.');
19
Conditional Statements
If-Else Statements in C#, Java, JS and Python
If-Else Statements in C# and Java
▪ If-Else in C# ▪ If-Else in Java
double grade = 4.50; double grade = 4.50
if (grade >= 3.00) if (grade >= 3.00) {
{ System.out.println("Passed!");
Console.WriteLine("Passed!");
} else {
}
else System.out.println("Failed!");
{ }
Console.WriteLine("Failed!");
}

21
If-Else in JavaScript and Python
▪ If-Else in JavaScript ▪ If-Else in Python
let grade = 4.50; grade = 4.50
if (grade >= 3.00) { if grade >= 3.00:
console.log("Passed!"); print("Passed!")
} else { else:
console.log("Failed!"); print("Failed!")
}

22
Loops
Loops in C#, Java, JS and Python
While Loop in C# and Java
▪ While loop in C# ▪ While loop in Java
int counter = 0; int counter = 0;
while (counter <= 9) while (counter <= 9) {
{ System.out.println(counter);
Console.WriteLine(counter); counter++;
counter++; }
}

24
While Loop in JS and Python
▪ While loop in JS ▪ While loop in Python
let counter = 0; counter = 0
while (counter <= 9) { while counter <= 9:
console.log(counter); print(counter)
counter++; counter += 1
}

25
For Loop in C# and Java
▪ For-loop in C#
for (int i = 0; i <= 9; i++)
{
Console.WriteLine(i);
}

▪ For-loop in Java
for (int i = 0; i <= 9; i++) {
System.out.println(i);
}
26
For Loop in JS and Python
▪ For-loop in JS
for (let i = 0; i <= 9; i++) {
console.log(i);
}

▪ For-loop in Python
for i in range(0, 10):
print(x)

27
IDE
Integrated Development Environments
Most Popular IDE for C#

Visual Studio

29
Most Popular IDE for Java

IntelliJ IDEA

30
Most Popular IDE for JavaScript

Visual Studio Code

31
Most Popular IDE for Python

PyCharm

32
Universal Online IDEs

REPL.it
Online IDE for C#, Java, JS, Python and many others

33
Questions?

© SoftUni Global – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
SoftUni Diamond Partners
Educational Partners

36
Trainings @ Software University (SoftUni)
▪ Software University – High-Quality Education,
Profession and Job for Software Developers
▪ softuni.bg
▪ Software University @ Facebook
▪ facebook.com/SoftwareUniversity
▪ SoftUni Global
▪ softuni.org

37
License
▪ This course (slides, examples, demos, exercises, homework,
documents, videos and other assets) is copyrighted content
▪ Unauthorized copy, reproduction or use is illegal
▪ © SoftUni – https://about.softuni.bg/
▪ © Software University – https://softuni.bg
▪ © SoftUni Global – https://softuni.org

38

You might also like