Java syntax
1. Variable Declaration:
Java:
1: int age = 30;
2: String name = "John";
3:
C#:
1: int age = 30;
2: string name = "John";
3:
JavaScript:
1: let age = 30;
2: const name = "John";
3: var city = "New York";
4:
Differences:
- Java and C# are statically typed, requiring explicit type declaration.
- JavaScript is dynamically typed, allowing variable declaration without specifying the type.
- JavaScript uses `let`, `const`, and `var` for variable declaration, with `let` and `const` being block-scoped and `var` being function-scoped.
2. Data Types:
Java:
- Primitive types: int, long, float, double, boolean, char, byte, short.
- Reference types: Classes, interfaces, arrays.
C#:
- Primitive types: int, long, float, double, bool, char, byte, short, decimal.
- Reference types: Classes, interfaces, arrays, delegates.
JavaScript:
- Primitive types: number, string, boolean, null, undefined, symbol.
- Reference types: Objects, arrays, functions.
Differences:
- Java and C# have a clear distinction between primitive and reference types.
- JavaScript has a more flexible type system, with automatic type conversion.
3. Operators:
Java:
- Arithmetic: +, -, *, /, %.
- Relational: ==, !=, >, <, >=, <=.
- Logical: &&, ||, !.
- Bitwise: &, |, ^, ~, <<, >>, >>>.
C#:
- Arithmetic: +, -, *, /, %.
- Relational: ==, !=, >, <, >=, <=.
- Logical: &&, ||, !.
- Bitwise: &, |, ^, ~, <<, >>.
JavaScript:
- Arithmetic: +, -, *, /, %.
- Relational: ==, ===, !=, >, <, >=, <=.
- Logical: &&, ||, !.
- Bitwise: &, |, ^, ~, <<, >>, >>>.
Differences:
- Java and C# have similar operator sets.
- JavaScript has a unique === operator for strict equality.
- JavaScript's == operator can lead to unexpected results due to type coercion.
4. Control Flow:
5. Functions:
Java:
1: public int add(int a, int b) {
2: return a + b;
3: }
4:
C#:
1: public int Add(int a, int b) {
2: return a + b;
3: }
4:
JavaScript:
1: function add(a, b) {
2: return a + b;
3: }
4:
Differences
- Java and C# use `public` and `private` keywords for access modifiers.
- JavaScript uses `function` keyword for function declaration.
- JavaScript has a concept of "function" and "method" which are not the same.
- JavaScript has a concept of "this" which is not present in Java or C#.
6. Object-Oriented Programming (OOP):
Java:
- Class definition: class MyClass { ... }
- Inheritance: extends
- Polymorphism: Method overloading and overriding.
C#:
- Class definition: class MyClass { ... }
- Inheritance: class MyClass : BaseClass { ... }
- Polymorphism: Method overloading and overriding.
JavaScript:
- Class definition: class MyClass { ... }
- Inheritance: extends
- Polymorphism: Method overriding.
Differences:
- Java and C# have similar OOP concepts.
- JavaScript's OOP is based on prototypes, which is different from class-based inheritance.
7. Error Handling
8. More JavaScript difference
Java context:
Comments (
)
)
Link to this page:
http://www.vb-net.com/Java/Index06.htm
|
|