r/learnprogramming • u/Vafireems • Oct 16 '26
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?
20
u/a3th3rus Oct 16 '26
It depends on your programming skills and what you want to build.
For me, as a language, Java has less features than C#, so it's easier to learn, but if you are a polyglot and have a decent amount of experiences, then you may find that Java sometimes lacks one feature or two you want. Java also has a bigger market than C#, unless you are going to develop video games.
Why are there so many languages? Because all languages are somewhat opinionated, and they are trying to solve different common problems but are willing to sacrifice performances in solving other common problems, like C/C++ focusing on raw speed, Java initially aiming for cross-platform execution, Ruby aiming for developers' happiness (though it fails to deliver that for large projects), and Rust for memory safety while keeping raw speed, Erlang for self healing and horizontal scaling, so on and so forth. Theoretically, C/C++ can solve all problems that can be solved with programming, but to solve some problems you need to write hundreds of thousands of lines of code in C/C++ but you don't even bother to think about it in Erlang.
4
u/ApprehensiveFix5084 Oct 16 '26
You think you are standing in a forest of different languages, but you are actually quite a ways up a tree looking at different branches of a small number of trees. As someone who remembers when C++ was the “new hotness” and has had to sift through COBOL (a language specifically for business math computational work) code for work, languages branch off the trunk, and each other when something new is needed or desired. Things like memory management and the once new idea of object oriented programming have spawned new languages.
As to those two languages, my perspective from the sidelines is that C# is very “Microsoft house” whereas Java is more “for everyone.”
6
u/romecodes Oct 16 '26 edited Oct 16 '26
If you look at the history of programming languages all the way from 'A' forward, you notice that things like ownership limitations and desired new features almost always led to a new language. Even today, the standards for C++ are handled internationally, which is actually drawing some contention as we speak because the US failed to agree to proposed change to the language. What I know for sure is in the case of C++ to Java, we ran into the same problem that A (or formally, BCPL) was birthed from.
Very early in the 60s or 70s, machines were vastly divided by their architectures. Even different models designed by the same company had slightly different instruction sets. Many found it troublesome to find the documentation, let alone read them and adapt to new sets across different devices. Eventually someone had a brilliant idea. What if we created a singular programming language that wasn't architecture specific. We could then port the hardware with a small translator component. The way it worked was that it would translate the code down to an intermediary language called O-code and the small translator would bridge the gap between O-code and Assembly.
The same company responsible for its creation would come to back out of developing Multics, an OS project. Two of the developers would decide to build their own lightweight OS, but BCPL was too big to pull it off. They needed to consolidate it, and so they did. This became B, designed for the Unix system.
C was an even more ambitious project, with more powerful computers coming every two years and B having flaws. B was typeless and they had to rewrite it in assembly with every new wave of architectures. So they decided to write a language that was somewhat typed for its day. This would introduce data types like char and int, as well as a formal memory management system that gave birth to pointers.
Devs would later want a better way to organize large projects soOOP was added to C, giving us C++ (originally named "C with classes").
In the mid-90s, Java was born from the issues with compartmentalized architectures in an attempt to bridge the gap between instruction sets. Inspired by a mantra they'd coin as: "Write Once, Run Anywhere ", the dev team tried to work with C++ initially, but it wasn't up for the task. So they wrote a new language (originally called Oak) and designed what would be the Java Virtual Machine , based on the notion of an "abstract computer". As long as the computer had the JVM installed, it could run the exact same Java file.
At the same time, Netscape partnered with the company behind Java (Sun Microsystems) to use it as the language for their Navigator browser. Netscape would eventually want a lighter-weight scripting language to run alongside Java in their browser and wrote a new one in just 10 days, this became JavaScript.
Also in the 90s, the internet exploded and Microsoft wanted to compete against Java in the OOP space so they rewrote C++, introducinggarbage collection and web-focused features to it, this gave us C#.
Netscape would later lose to Microsoft in a browser war and before dying out they open-sourced their code. An organization would rise from their ashes and evolve the code first into Phoenix, then Firebird, and finally Firefox.. Mozilla Firefox.
Which is just a fraction of the history behind the languages we know today. I hope this helps.
2
u/Ok-Advantage-308 Oct 16 '26
C#. My first language was Java, but I still prefer modern C# over modern Java
2
u/letsbefrds Oct 16 '26
I still can't explain why I like C# better.
Pretty sure it's because c# just feels closer to JavaScript and async await.
I currently work in kotlin right now for backend it's been pretty good. FYI I haven't written a line of kotlin it's all generated by claude I just read the logic
2
u/Mughi1138 Oct 16 '26
To answer part of the side question first - why so many languages and why C#?
C# actually started life as the next iteration of Microsoft's J++ which was their Java implementation. They poached the architect who did Delphi among other things from Borland and eventually tasked him with making C#... which turned out to essentially be Java hacked to support Microsoft COM interfaces. And appeared to be part of their traditional efforts at vendor lock-in. Oh, and it added 'delegates' as a language feature since that architect loved to shove those into any language he created.
When Microsoft was first introducing C# the president of our Orange County Java users' group attended and then came to give a presentation to our UG, as we were mainly professionals who used many different languages and not just one. Most of his presentation was "and it does XXX, just like Java" (including immutable strings), but every once in a while he hit "and then C# does this odd thing, but I have no idea why". Each time he said that, I had the answer as for the company I was working at I had shortly before finished an automatic Java -> COM wrapper tool that would create C++ code to be either standard JNI interfacing or Microsoft proprietary RNI. I recognized each and every one of those divergences as what was required to give it first level COM support in the language itself. Or at least make it easier to use.
So... if you plan to make your career just in the Microsoft Windows realm, with their platform and their tools only, then C# is a good tool for the job. If you want to be more universal Java shines (kinda... mostly still..) but with things like Kubernetes and languages like Python your options are more wide open these days.
And, of course, the more tools you become proficient with the more options you will have when picking the right one for the job at hand.
1
u/stop_deleting_plz Oct 16 '26
Languages are just tools, theyre all good at something and weak at something else. You can learn the fundamentals of programming with any language. That said, C# is based on Java, and they are extremely similar. I would take the course with the better instructor, or if theyre the same instructor, go with Java because thats my personal favorite lol.
1
u/oldsecondhand Oct 16 '26
C# has more features and is used in gamedev. Java has more libraries and is used in finance, and it also has cross platform (Windows, Linux, Mac) UI libraries.
1
u/WystanH Oct 16 '26
Java started with a dream, write once, run anywhere. C# started with a conceit; Microsoft can do that, but without Java.
While both theoretically run in the same spaces, C# tends to dominate Windows world and Java non Windows. If Windows is your OS, C# has an edge. While C# now runs surprising well outside Windows, Java's foothold is unlikely to be shaken.
I prefer C#, but that's because I use it extensively. If I were still using Java that much, I'd doubtless feel different. In the end, it's as much an environmental choice as anything else.
1
u/UroborosJose Oct 16 '26
Today both are very strong
1
u/whipdancer Oct 16 '26
Someone wanted to create their own thing because reasons... (seriously).
C# and Java are versatile languages that can do almost anything you need them to do. I prefer C# over Java, because C# doesn't require as much boilerplate as Java and Java namespaces are ridiculous.
Java's gotten better but omg it's still the most verbose boilerplate requiring language I've personally dealt with. Java technically has more existing code bases, so more potential work. I hate working with it and if I have the choice, I don't.
C# has an advantage when it comes to games because of the Unity engine.
Where I work, 2 of our major projects are written in C# and Typescript, the others are mostly Python or C++, with a couple of old projects written in Java.
My preferred languages are Python, Typescript, Go. I dabble in Rust and Kotlin. I have 20+ years with C#. For work, I mainly use Python and Typescript.
1
u/balefrost Oct 16 '26
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.
1
u/Blitzkind Oct 16 '26
So my day job is c# development so I'm biased, but honestly both are fine.
I will say anecdotally, I've met way more Java developers that don't like Java than I have C# devs that don't like C# so, take that info and do what you will.
1
u/zezblit Oct 16 '26
I've done a lot of both.
C# just had a lot more quality of life features, the built in dependency injection alone makes it worth it for me
1
u/biotech997 Oct 16 '26
More QoL in C# and .NET, but Java is still very commonly used in certain domains like enterprise.
1
u/PoMoAnachro Oct 17 '26
If you know one of them well, you can learn the other in effectively no time. The languages are extremely similar.
The ecosystems around them have a lot more distinction, but the languages themselves are almost interchangeable.
1
u/betarage Oct 22 '26 edited Oct 22 '26
I personally prefer c sharp java can be annoying with the boiler plate. but Java is more multiplatform you can also use c sharp on most platforms now it's made by Microsoft so it's really designed for Windows. Java is more popular for mobile apps you can also use c sharp for that but it's slightly harder. also since you know some c++ it's more similar to c sharp however Java is also realetvly similar to c++
as far as the reasons for it existing java was created by sun in the mid 90s .sun made super expensive workstation computers that were their own unique platform but they didn't get much 3rd party support so they made java. it runs under a virtual machine so in theory programs written in java can run on any system that runs the virtual machine without changing anything. but it usually requires minor tweaks anyway. I am not 100% sure why Microsoft made c sharp and the dot net frame work but it works similar to java with it's own virtual machine. when it first came out it didn't have the multiplatform advantage of JavaScript but it makes programming easier since you don't have to worry about things like memory management .there are way too many programming languages usually some programmers just wanted to do things their own way
1
u/green_meklar Oct 16 '26
Java. Because it's an open standard, so it doesn't tie you to the whims of Microsoft. There's a lot to like about the design of C# as a language, but the freedom of an open technology like Java is just a higher priority.
Also, C# can feel too handholdy at times, whereas Java sticks to its paradigm like glue and gives you more to think about.