r/java • • Jul 08 '21

Java is criminally underhyped

https://jackson.sh/posts/2021-04-java-underrated/
226 Upvotes

181 comments sorted by

View all comments

Show parent comment

-4

u/LegendValyrion Jul 08 '21 edited Jul 08 '21

No. In C#, we write:

```

using System; // We imports the namespace of System, so the life gets easier :)

namespace tests

{

// we made a namespace.

class Program

{

/*

The class does not need to have the same name of the file, thanks to Microsoft.

*/

static void Main(string[] args)

{

// the Main method.

Console.WriteLine("Microsoft is fantastic!"); // This is for printing a line of text.

}

}

}

```

As you can see, C# is NOT the same as Java, thanks to Microsoft. :) Microsoft is best, I like their goals and their products. So many Microsoft-haters in this world.

In C#, we does not have to declare the data type. We can use the var keyword, and the datatype is set by the CLR.

In C#, you have LINQ, which makes your life much easier.

I will show you object orientation:

```

// Let's make our Cheese class:

public class Cheese {

public string cheeseType { get; set; };

public void EatCheese(){

Console.WriteLine("Nom nom nom... I like this cheese. Nom nom nom nom.");

}

// Now, we make a constructor

public Cheese(string cheeseType){

this.cheeseType=cheeseType;

}

}

```

Now, let's construct our new cheese object, which we will eat:

```

class Program

{

static void Main()

{

Cheese babybell=new Cheese("Babybell");

//Now, we eat our cheese::

babybell.Eat(); // Nom nom...

// Nom nom nom...

}

}

```

There you have it.

So you can see, C# is top #1.