Java OOP, idiotic C#
1. Dirty C# language.
C# is mot idiotic languages I'm faced in my life, because absolutely different core OOP conception mixed, for example in VB.NET there are:
- "+" operation - in VB.NET concatenation string doing with operator "&", accumulation digital value doing with operator "+", adding even handler doing with operator "AddHandler". In idiotic C# language all of them operation doing with the same character "+". This is most idiotic concept I have ever encountered in all my life.
- ":" operation - even more idiotic. There are two opposite operation in OOP - Inheritance and Implementation, in VB.NET there are two keyword what allow you construct new object with the same opposite rules - Inherits or Implements. In first one we can add additional signatures to new Interface or Object, in second one we fill code to existing signatures. What common in this operation? Nothing !!! But both of these two opposite operation you can make in C# with the same char ":".
- Also idiotic C# inserted automatic conversion (for example to type Long) to unexpected places, that never doing more serious languages. see more details in this topic Java Datatypes
What result of this (and other) idiotic ambiguous mixing? Result is very simple - C# can not converted to any first class languages in the world. This is not a unexpected result os mistake og fucking Microsoft company. This is policy of Microsoft to language with one way converting. Ypu already can convert VB.NET to C#, because VB.NET is strong language, but never converting C# to VB automatically (plus case insensitive prevent you doing that). So, this policy allow Microsoft to kill simple understandable language and create trash language, what allow MS increase indefinitely in program, increase various mistake, and as a result increase price of C# software comparing to VB.NET software and as a result increase price to support software on Microsoft platform, increase cost of ownership software on Microsoft platform, increase capitalisation and investment to Microsoft software, increase the value of company public shares and value of Microsoft stock.
In fact, fucking Microsoft company, try kill VB.NET and try to promote idiotic C# with only one goal - own financial advantage. This what all programmers in world must understand clearly abut Microsoft and C#.
2. Dirty C# operator ":"
And firstly about dirty C# operator ":"
Clear Separation Java takes a much more explicit and less ambiguous approach to distinguishing between inheritance and interface implementation:
- extends Keyword: Java uses the extends keyword to indicate class inheritance.
- implements Keyword: Java uses the implements keyword to indicate interface implementation.
1: public class MyDerivedClass extends MyBaseClass {
2: // ...
3: }
1: public class MyClass implements MyInterface {
2: // ...
3: }
3. C# OOP vs Java OOP.
Similarity:
- OOP: Both Java and C# are class-based, object-oriented languages. They share many of the same OOP principles, such as encapsulation, inheritance, and polymorphism.
- Event Handling: Both Java and C# use an event-driven programming model. However, C# has a more streamlined event handling mechanism, with built-in support for delegates and events.
Differences:
- Multiple Inheritance: C# supports multiple inheritance, while Java only supports single inheritance.
- Structs: C# supports structs, which are value types that can be used to create lightweight objects. Java does not have structs.
- Properties: C# has built-in support for properties, which are a way to encapsulate access to an object's data. They look like fields from the outside but can have custom logic (getters/setters) behind the scenes. Java does not have direct property support, but you achieve similar results using getter and setter methods.
- Delegates: C# has built-in support for delegates, which are type-safe function pointers. They allow you to treat methods as first-class objects, passing them around and invoking them. Java doesn't have delegates in the same way, but you can use interfaces and anonymous inner classes to achieve similar functionality.
- LINQ: C# has Language Integrated Query (LINQ), a powerful feature for querying and manipulating data collections. It's deeply integrated into the language. Java doesn't have a direct equivalent, but you can use libraries like Streams API to achieve similar results.
- Garbage Collection: C# has automatic garbage collection, but it is not as efficient as Java's garbage collection.
- Generics: Both C# and Java have generics, allowing you to write code that works with different types without having to rewrite it for each type. However, C#'s generics are more powerful, with features like variance and constraints. Java's generics are more limited due to type erasure.
- Asynchronous Programming: C# has built-in support for asynchronous programming with async and await keywords, making it easier to write non-blocking code. Java has features like CompletableFuture for asynchronous operations, but it's not as deeply integrated into the language.
- Memory Management: Both languages have automatic garbage collection, but C#'s garbage collector is generally considered less efficient than Java's.
4. @Override and other Attributes in Java
In Java, the @Override annotation is a compiler directive that indicates that a method is intended to override a method from a superclass. It's a way to ensure that you're intentionally overriding a method and not accidentally creating a new one with the same name.
Key Features of @Override:
- Compiler Enforcement: The Java compiler uses the @Override annotation to check if the method you're trying to override actually exists in the superclass. If the method signature doesn't match, the compiler will throw an error.
- Readability: It makes your code more readable by explicitly stating that a method is overriding a superclass method.
- Prevention of Accidental Overloading: It helps prevent accidental overloading, where you might unintentionally create a new method with the same name in the subclass instead of overriding the superclass method.
1: class Animal {
2: public void makeSound() {
3: System.out.println("Generic animal sound");
4: }
5: }
6:
7: class Dog extends Animal {
8: @Override
9: public void makeSound() {
10: System.out.println("Woof!");
11: }
12: }
13:
14: public class Main {
15: public static void main(String[] args) {
16: Dog myDog = new Dog();
17: myDog.makeSound(); // Output: Woof!
18: }
19: }
In this example, the Dog class overrides the makeSound() method from the Animal superclass. The @Override annotation ensures that the method signature matches the superclass method.
Other Attributes in Java
Besides @Override, Java offers other attributes that are crucial for OOP:
- final: This keyword, when applied to a class, method, or variable, indicates that it cannot be further subclassed, overridden, or modified. It's useful for creating immutable classes or methods that should not be changed.
- static: This keyword means that the member belongs to the class itself, rather than to a specific instance of the class. Static members are shared among all instances of the class.
- public, protected, private: These access modifiers control the visibility of class members. public means the member is accessible from anywhere, protected means it's accessible within the same package or subclass, and private means it's only accessible within the class.
- abstract: This keyword is used to create abstract classes or methods. An abstract class cannot be instantiated, and an abstract method has no implementation. Subclasses must provide implementations for abstract methods.
Similar Attributes in C#
- virtual: The virtual keyword is used to define virtual methods.
- override: The override keyword is used to override virtual methods.
- sealed: The sealed keyword is used to prevent further inheritance.
- static: The static keyword is used to define static members.
- public, protected, private: Access modifiers are used to control the visibility of class members.
- abstract: The abstract keyword is used to define abstract classes or methods.
Similar Attributes in JavaScript
- class: JavaScript uses the class keyword to define classes.
- extends: The extends keyword is used for inheritance.
- super: The super keyword is used to call the superclass constructor or method.
- static: The static keyword is used to define static members.
- #: Private class members are defined using the # symbol.
- get, set: Getters and setters are used to define properties.
Comparison:
- Inheritance: Both JavaScript and C# use the extends keyword for inheritance, similar to Java's extends.
- Overriding: Both JavaScript and C# use the override keyword to override methods, similar to Java's @Override.
- Access Modifiers: Both JavaScript and C# have access modifiers (public, protected, private), similar to Java's access modifiers.
- Static Members: Both JavaScript and C# use the static keyword to define static members, similar to Java's static.
- Abstract Classes: Both JavaScript and C# have abstract classes, similar to Java's abstract.
- Sealed Classes: C# has sealed classes, similar to Java's final.
5. JavaScript vs. Java
- OOP: JavaScript's OOP is based on prototypes, while C#'s is class-based. They share many of the same OOP principles, such as encapsulation, inheritance, and polymorphism. However, JavaScript is a dynamically typed language, while Java and C# are statically typed.
- Event Handling: JavaScript's event handling is more flexible, using the DOM and event bubbling. However, C# has a more streamlined event handling mechanism, with built-in support for delegates and events. JavaScript's event handling is more flexible than Java's or C#'s.
- Typing: JavaScript is dynamically typed, while C# is statically typed.
- Android WebViews: JavaScript is used in Android WebViews to create web-based user interfaces.
- React Native: React Native is a JavaScript framework for creating native mobile apps. It's not directly related to Java or C#.
- Web Development: JavaScript is primarily used for web development, while C# is primarily used for .NET development.
- Android Development: C# is not a primary language for Android development, but you can use it to create Android apps using Xamarin.
- Android UI: C# is used to create Android user interfaces. JavaScript is used to create web-based user interfaces.
- Android SDK: The Android SDK is written in Java.
- Android Studio: Android Studio is the official IDE for Android development. It's primarily designed for Java and Kotlin.
- Android Jetpack: Android Jetpack is a set of libraries that help you write Android code. It's written in Java and Kotlin.
- Android Architecture Components: Android Architecture Components are a set of libraries that help you structure your code. They're written in Java and Kotlin.
- Android NDK: The Android NDK is a set of tools that allow you to write C/C++ code for Android. It's not directly related to Java or C#.
Key Differences:
- Multiple Inheritance: C# supports multiple inheritance, while Java only supports single inheritance.
- Structs: C# supports structs, which are value types that can be used to create lightweight objects. Java does not have structs.
6. C# vs. Java
- OOP: Both Java and C# are class-based, object-oriented languages. They share many of the same OOP principles, such as encapsulation, inheritance, and polymorphism.
- Event Handling: Both Java and C# use an event-driven programming model. However, C# has a more streamlined event handling mechanism, with built-in support for delegates and events.
Key Differences:
- Multiple Inheritance: C# supports multiple inheritance, while Java only supports single inheritance.
- Structs: C# supports structs, which are value types that can be used to create lightweight objects. Java does not have structs.
- Properties: C# has built-in support for properties, which are a way to access object attributes and methods. Java does not have built-in support for properties.
- Delegates: C# has built-in support for delegates, which are a way to pass methods as arguments to other methods. Java does not have built-in support for delegates.
- LINQ: C# has built-in support for LINQ, which is a way to query and manipulate data. Java does not have built-in support for LINQ.
- Garbage Collection: C# has automatic garbage collection, but it is not as efficient as Java's garbage collection.
Summary, Java
- Weaknesses: Verbose syntax, some boilerplate
- Limited Language Features: Compared to C#, Java has fewer built-in features like properties, delegates, and LINQ.
- Boilerplate Code: Java can be verbose, requiring more code to achieve the same results as C# or JavaScript.
- Verbosity: Java's syntax can be verbose, requiring more code to achieve the same results as C# or JavaScript.
- Memory Management: While Java has automatic garbage collection, it can sometimes be less efficient than C#'s garbage collection.
- Performance: Java code can be slower than C# code, especially when it comes to memory management.
- Learning Curve: Java can have a steeper learning curve than C# or JavaScript
- Android Development: Java is the primary language for Android development. C# is not a primary language for Android development, but you can use it to create Android apps using Xamarin.
- Android SDK: The Android SDK is written in Java.
- Android Studio: Android Studio is the official IDE for Android development. It's primarily designed for Java and Kotlin.
- Android Jetpack: Android Jetpack is a set of libraries that help you write Android code. It's written in Java and Kotlin.
- Android Architecture Components: Android Architecture Components are a set of libraries that help you structure your code. They're written in Java and Kotlin.
- Android NDK: The Android NDK is a set of tools that allow you to write C/C++ code for Android. It's not directly related to Java or C#.
7. Interfaces
Java and C#: Both Java and C# are statically-typed languages with a strong emphasis on compile-time type checking. Interfaces in these languages are primarily about defining contracts that classes must adhere to.
JavaScript: JavaScript is dynamically-typed, meaning type checking happens at runtime. Interfaces in JavaScript are more about duck typing (if it walks like a duck and quacks like a duck, it's a duck) and less about strict contracts.
Interface Definition Syntax:
- Java:
- Interface methods are implicitly public and abstract.
- Interfaces can only contain method signatures (no method bodies).
- C#:
- Interface methods are implicitly public and abstract.
- Interfaces can only contain method signatures (no method bodies).
- JavaScript:
- JavaScript doesn't have a dedicated interface keyword.
- Interfaces are typically defined implicitly through the use of duck typing.
- You can use JSDoc to define interfaces.
1: public interface MyInterface {
2: void myMethod();
3: int myOtherMethod(String str);
4: }
1: public interface IMyInterface {
2: void MyMethod();
3: int MyOtherMethod(string str);
4: }
1: /** * @interface MyInterface * @property {string} name - The name of the person. * @property {number} age - The age of the person. */
2: class Person {
3: constructor(name, age) {
4: this.name = name;
5: this.age = age;
6: }
7: }
Interface Implementation:
- Java:
- C#:
- JavaScript:
1: public class MyClass implements MyInterface {
2: @Override
3: public void myMethod() {
4: System.out.println("MyClass.myMethod()");
5: }
6:
7: @Override
8: public int myOtherMethod(String str) {
9: return str.length();
10: }
11: }
1: public class MyClass: IMyInterface {
2: public void MyMethod() {
3: Console.WriteLine("MyClass.MyMethod()");
4: }
5:
6: public int MyOtherMethod(string str) {
7: return str.Length;
8: }
9: }
JavaScript doesn't have a formal implements keyword.
Instead, it relies on duck typing. If an object has the methods and properties expected by an interface, it's considered to implement that interface.
1: class MyClass {
2: constructor(name, age) {
3: this.name = name;
4: this.age = age;
5: }
6: myMethod() {
7: console.log("MyClass.myMethod()");
8: }
9: myOtherMethod(str) {
10: return str.length;
11: }
12: }
4. Interface Differences :
- Static vs. Dynamic Typing: Java and C# are statically typed, while JavaScript is dynamically typed. This is a fundamental difference that shapes how interfaces are used.
- Explicit vs. Implicit: Java and C# require explicit interface implementation using the implements keyword (Java) or the colon : operator (C#). JavaScript relies on duck typing, meaning that if an object has the expected methods and properties, it's considered to implement the interface, regardless of whether it explicitly declares that it does so.
- Contracts: Java and C# interfaces are primarily about defining contracts that classes must adhere to. These contracts are enforced at compile time. JavaScript interfaces are more about defining expectations or conventions. These expectations are checked at runtime.
- Method Bodies: Java and C# interfaces cannot contain method bodies. They only define method signatures. JavaScript interfaces can contain method bodies.
- Formal Definition: Java and C# have a formal interface keyword and a well-defined syntax for creating and implementing interfaces. JavaScript does not have a formal interface keyword. Interfaces are typically defined implicitly through the use of duck typing.
- Compile-Time vs. Runtime: Java and C# interfaces are checked at compile time. JavaScript interfaces are checked at runtime.
- Enforcement: Java and C# interfaces are enforced by the compiler. JavaScript interfaces are enforced by the runtime.
- Duck Typing: JavaScript relies on duck typing, which means that if an object has the expected methods and properties, it's considered to implement the interface, regardless of whether it explicitly declares that it does so. Java and C# do not rely on duck typing.
- JSDoc: JavaScript uses JSDoc to define interfaces. Java and C# do not use JSDoc to define interfaces.
- Inheritance: Java and C# interfaces can inherit from other interfaces. JavaScript interfaces cannot inherit from other interfaces.
- Multiple Inheritance: Java and C# interfaces can inherit from multiple interfaces. JavaScript interfaces cannot inherit from multiple interfaces.
- Default Methods: Java interfaces can have default methods. C# interfaces can have default methods. JavaScript interfaces cannot have default methods.
- Static Methods: Java interfaces can have static methods. C# interfaces can have static methods. JavaScript interfaces cannot have static methods.
Java context:
- (2025) Android mosaic #AndroidMosaic #Java
- (2025) My Java plugin for WebStorm #Java
- (2024) My Android Java Voip Messenger #Java #Android
- (2024) My Android Java apps for SelfTesting JS skills #Java #Android
- (2021) Retrofit test with interceptor, clear communication and show data to TextView #Android #Java #DevEnvironment
- (2016) Java useful links #Java
- (2016) Java Datatypes #Java
- (2016) Java OOP, idiotic C# #Java
- (2016) Java Generic, Constraints, Narrowing and Widening conversions #Java
- (2016) Java control flow #Java
- (2016) Java syntax #Java
- (2016) Java arrow functions, delegates #Java
- (2016) Java string manipulation #Java
- (2016) Java Array #Java
- (2016) Java Async programming #Java
- (2016) Java Null #Java
- (2016) Java This #Java
- (2016) Java List, Map, Set #Java
- (2016) Java Yield #Java
- (2015) Wowza missing FAQ. #Video #Java #Servers
- (2012) Подготовка к работе Eclipse. #Java
- (2012) JAVA-клиенты Windows Communication Foundation. #Java #WebServiceClient
- (2011) JAVA welcome #Java
- (2011) Установка и настройка Tomcat. #Java

|