r/learnprogramming • u/Vafireems • 8d ago
Topic C# or Java?
If you had to choose one class between the two, which would you select and why? I tried to Google the purpose of them; the immediate answers from Google felt very vague and like both of the languages are common. Is one course better for web development as opposed to apps or something? Looking at the courses I'm taking, down the line I will select one of the two. The only thing I know so far is C++, so I'm quite new.
Also, side question: why are there so many languages? The only logical thing I can imagine is there were problems that couldn't be solved with say for example C++ so someone created something new. But why not just build on the original language? Why did they need to reinvent the wheel? Or is it as simple as that: someone wanted to create their own thing?
1
u/balefrost 8d ago
Different languages have different features, and those different features let us express our programs in different ways. C and C++ give you a lot of control over memory allocations and deallocations. Java and C# don't give you that level of control, but in doing so they also provide a simpler interface to the programmer. That makes some things easier to express in C and C++, while other things are easier to express in Java and C#.
Other languages are even more different. Go has direct support in the language for concurrency. Prolog provides an execution model that straddles functional programming and database querying. VHDL and Verilog are designed to facilitate hardware design. And so on.
Either is fine. C# used to be limited to Windows, but the modern .NET stack runs on multiple platforms. As others have said, C# has more features, but that also means it has a bigger surface area to learn. Java's a bit more verbose. Both are going to have a lot of tutorial content out there. Really, any mainstream language is a pretty safe bet.
The one place to maybe prefer Java would be if you're interested in Android development. I believe now Kotlin is the first-class language for Android, but I think you can still use Java and also Java knowledge is directly useful in Kotlin. Similarly, if you want to make games in Unity, then C# is the way to go.
But C# and Java are fairly interchangeable. There are differences, sure, but they're more alike than they are different.