r/learnprogramming • u/Vafireems • 4h 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?
4
u/romecodes 3h ago edited 3h ago
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 so OOP 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++, introducing garbage 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.
4
u/Mughi1138 3h ago
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.
Key point for the newbies out there (like the OP). Java was a very well thought out and designed language with a robust set of libraries and built on top of strong CompSci research of the time. JavaScript was a quick one-man hack of things to get something working in browsers by a company who made browsers, but had... um... issues (they were never able to publish a DTD for what their browser supported among other things, and don't get me started on their code quality or QA practices). Anyway Netscape came up with this light weight in-browser interpreted scripting language and named it "JavaScript" to cash in on the Java hype that Sun had built up around themselves and their product.
2
u/letsbefrds 4h ago
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
1
u/rupertavery64 3h ago
To me the .NET ecosystem and C# language are just better.
True generics, LINQ, extension methods and of course async await was in there since c# 5.0 / .NET 4.5
Package management isn't terrible either
2
u/ApprehensiveFix5084 4h ago
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.”
4
u/Mughi1138 3h ago
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.
4
u/FunkyDoktor 3h ago
You’re describing C# 20 years ago. It’s been cross-platform for a while and works great outside of the Windows realm.
0
u/Mughi1138 2h ago
It works "ok" outside of the Windows realm. Not great. Though it is better than it was just a few years ago where if you were not on the one main distros you had to even compile the compiler yourself.
It's not nearly as cross platform as some other things, and is it up to good support on more than two CPU architectures yet? I've not checked that in the last year or so.
But, yes, I've worked with professional shipping C# code, and at companies supporting many different systems. In certain areas you only get a small subset of C# that you can use. At my current day job some projects are in C#, but others (including mine) are in different languages... and not for want of a prior CTO not making an effort to unify.
So again, it really comes down to proper tool for the current tasks at hand.
2
1
u/romecodes 2h ago edited 2h ago
Love the personal history in this response. You definitely have some skin in the game.
I only started diving into comp sci five years ago. Spent a bit more than a year learning on my own before getting an A.S. in community and transferring to a university for the B.S. The mountain of information out there on the subject is intense and I don't think students today are leaving, degree in-hand, with enough to get the job done.
I felt sorry for myself starting in my mid-20s. Now I realize just how lucky I really was. It takes a passion, drive, and commitment that I don't think most kids between 18 to 25 are prepared to invest.
If it weren't for spending my early adulthood getting the mistakes out of my system and being consistently snapped back to reality, I wouldn't have gotten ahead.
The curriculums aren't thorough enough or up-to-date. Professors are still trying to decide where version control should fit in the sequence. And, they're honestly just passing students through the pipeline without evaluating their job readiness. The entire pipeline is all over the place. Theory is taught so spread out and the necessary information to connect ideas between courses aren't even present. They're only getting surface level knowledge.
I had to stay proactive and ahead to give myself the room to dive deeper on my own and make those connections. That isn't taught in grade school. I almost feel bad for the people I've sat next to. And even worse, I feel bad for myself because uneducated degree-holders only saturate the labor market.
Which only looks good economically on paper until the unemployment numbers come in.
2
u/Mughi1138 2h ago
Things go up and down. At one point it was the job that everyone who wanted to make money was looking at. Before that it was the job for people who loved computers... thus there was a several year window where when we were doing hiring having a college degree was actually a negative sign (we never cut people for that, but there was a strong correlation between people who started on their own and people who could get the work done we needed).
The #1 thing that still holds true is that people who *only* rely on what is taught in coursework in college are not the strongest candidates. Theory is good to have, but experience allows one to point out that, for example, big-O comparisons only hold up for large enough values of N. In this specific case here is that N big enough?
Also even if schools tried to pop out graduates with 'job readiness', then they'd never be able to get the job done for most hiring companies. What is 'job ready' this quarter can be completely different from last. And I'm definitely using different languages now then when I started at my current company. The point of college is not to cram your brain full of facts and details, but to train your brain *how* to learn so that you can keep learning as you go through your career.
1
3
u/green_meklar 3h ago
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.
1
u/Ok-Advantage-308 3h ago
C#. My first language was Java, but I still prefer modern C# over modern Java
1
u/stop_deleting_plz 3h ago
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 1h ago
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
0
u/EnderAvni 4h ago
There are lots of historical reasons for new languages popping up. A very recent success story is Rust, which was largely because of its memory safety in comparison to C/C++. I'm not sure about Python (CPython), but maybe its creator was like "why do we need to be so verbose with our types and such? Maybe we should make a language that reads like English anyone can pick up."
At their core, most languages are VERY similar, you just have to get used to the "framework" and common libraries surrounding that language, which are arguably harder (eg. Pytorch x Python) to pick up.
Both Java and C# are used heavily for backend web development. C# is used largely with Microsoft's tooling (.NET, Entity Framework, etc.) because those APIs are really convenient to use as a developer. Java has springboot analogously.
C# is also used in Native Windows App development because of WPF/WinUI/WinForms which are all frameworks to help you make windows apps which have really nice APIs for C# again.
It really doesn't matter what you end up using at the end of the day, and your skills will be very transferrable regardless of what you do.
3
u/a3th3rus 4h ago
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.