Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. C# and Java

C# and Java

Scheduled Pinned Locked Moved The Lounge
csharpjavaquestion
25 Posts 20 Posters 27 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Slow Eddie

    I was wondering, how close are C# and Java, syntax? Would be Java be "easy" to learn if I know C#?

    Archchancellor Ridcully

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #8

    It's been some years, but when I got a (corporate) Java project, I had to go shopping: Eclipse (IDE), Spring (UI), Struts, Apache (Web server), NetBeans, JBoss (app server), etc. before I could write any code. c# (Windows; .NET framework) was "no" shopping.

    "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

    D 1 Reply Last reply
    0
    • S Slow Eddie

      I was wondering, how close are C# and Java, syntax? Would be Java be "easy" to learn if I know C#?

      Archchancellor Ridcully

      D Offline
      D Offline
      Dan Neely
      wrote on last edited by
      #9

      A Brief, Incomplete, and Mostly Wrong History of Programming Languages[^]:

      1996 - James Gosling invents Java. Java is a relatively verbose, garbage collected, class based, statically typed, single dispatch, object oriented language with single implementation inheritance and multiple interface inheritance. Sun loudly heralds Java's novelty. 2001 - Anders Hejlsberg invents C#. C# is a relatively verbose, garbage collected, class based, statically typed, single dispatch, object oriented language with single implementation inheritance and multiple interface inheritance. Microsoft loudly heralds C#'s novelty.

      I boldest the key differences to be aware of. :laugh:

      Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius

      O 1 Reply Last reply
      0
      • D Dan Neely

        A Brief, Incomplete, and Mostly Wrong History of Programming Languages[^]:

        1996 - James Gosling invents Java. Java is a relatively verbose, garbage collected, class based, statically typed, single dispatch, object oriented language with single implementation inheritance and multiple interface inheritance. Sun loudly heralds Java's novelty. 2001 - Anders Hejlsberg invents C#. C# is a relatively verbose, garbage collected, class based, statically typed, single dispatch, object oriented language with single implementation inheritance and multiple interface inheritance. Microsoft loudly heralds C#'s novelty.

        I boldest the key differences to be aware of. :laugh:

        Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius

        O Offline
        O Offline
        obermd
        wrote on last edited by
        #10

        Concurrency control in the net framework is far easier to understand and correctly implement. Java implements this via Dykstra's base implementation. The net framework hides this complexity.

        D 1 Reply Last reply
        0
        • O obermd

          Concurrency control in the net framework is far easier to understand and correctly implement. Java implements this via Dykstra's base implementation. The net framework hides this complexity.

          D Offline
          D Offline
          Dan Neely
          wrote on last edited by
          #11

          ===== The Joke ====>                  You

          Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius

          1 Reply Last reply
          0
          • S Slow Eddie

            I was wondering, how close are C# and Java, syntax? Would be Java be "easy" to learn if I know C#?

            Archchancellor Ridcully

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #12

            Yes, relatively easy. Here are some differences to watch out for: - Generics are different, weaker. The syntax sometimes feels oddly backwards too, eg `public boolean containsAll(Collection c);`. - `foreach` loops don't use the `foreach` keyword, but that takes about 10 seconds to get used to. - Since there are no real delegates, Java tends to use interfaces with a `run` method (or equivalent). That also affects how events work. You can use anonymous classes that implement the relevant interface though, you don't have to create a thousand full classes. - Inner classes by default have a reference to a specific instance of their outer class. To get a "plain old inner class", it needs to be a static inner class, which is not a static class. That sounds more confusing than it is. - Operator overloading doesn't exist. Not even for `String`. Avoid `==` between objects (including `String`, but also `Integer`), unless you really meant to compare for reference-equality. And yes, BigInteger arithmetic is pretty painful in Java .. but also pretty efficient actually. BigIntegers in C# only recently approached how efficient they are in Java. - In terms of the framework, `List` -> `ArrayList`, and `Dictionary` -> `HashMap` (some tutorials may mention `Hashtable`, disregard them). - There are no unsigned integers (except `char` but we don't talk about that), which for the most part doesn't matter (many operations are independent of signedness, and there are special methods such as `Integer.compareUnsigned` to implement the operations that *are* dependent on signedness) except that Java's `byte` is signed and you will probably occasionally forget that and get some bugs due to unintended sign-extension.

            J 1 Reply Last reply
            0
            • S Slow Eddie

              I was wondering, how close are C# and Java, syntax? Would be Java be "easy" to learn if I know C#?

              Archchancellor Ridcully

              S Offline
              S Offline
              Southmountain
              wrote on last edited by
              #13

              it is very close. in the beginning, there is a saying that C# steals Java...

              diligent hands rule....

              T 1 Reply Last reply
              0
              • S Southmountain

                it is very close. in the beginning, there is a saying that C# steals Java...

                diligent hands rule....

                T Offline
                T Offline
                trønderen
                wrote on last edited by
                #14

                Isn't it commonly known that MS and Sun were arguing about MS' right to develop their Java compiler and market it as Java? MS ended up turning their back to Sun/Java, declaring: OK, we'll forget Java and make something better, then! According to my taste, MS succeeded; C# is and improvement over Java in several respects. But I have been working for a number of years in environments where any such opinion was highly non-PC.

                S M 2 Replies Last reply
                0
                • T trønderen

                  Isn't it commonly known that MS and Sun were arguing about MS' right to develop their Java compiler and market it as Java? MS ended up turning their back to Sun/Java, declaring: OK, we'll forget Java and make something better, then! According to my taste, MS succeeded; C# is and improvement over Java in several respects. But I have been working for a number of years in environments where any such opinion was highly non-PC.

                  S Offline
                  S Offline
                  Southmountain
                  wrote on last edited by
                  #15

                  my experience: Java components are good at cross platform because JVM. they can run on Linux and UNIX without recompile. I have a Java component to generate Excel file on UNIX, after I copied it to Linux, it is still working well. amazing to me...

                  diligent hands rule....

                  G 1 Reply Last reply
                  0
                  • S Southmountain

                    my experience: Java components are good at cross platform because JVM. they can run on Linux and UNIX without recompile. I have a Java component to generate Excel file on UNIX, after I copied it to Linux, it is still working well. amazing to me...

                    diligent hands rule....

                    G Offline
                    G Offline
                    GerVenson
                    wrote on last edited by
                    #16

                    I know what you mean. Now with Net5 & Net6 it just amazed me how easy it was to execute the app on linux now that most of the frameworks catched up to net5.

                    sudo apt-get install -y dotnet-runtime-6.0 && \
                    dotnet MYAPP.dll

                    Only thing to get used to that you "run" dlls^^

                    S 1 Reply Last reply
                    0
                    • S Slow Eddie

                      I was wondering, how close are C# and Java, syntax? Would be Java be "easy" to learn if I know C#?

                      Archchancellor Ridcully

                      M Offline
                      M Offline
                      Member 9167057
                      wrote on last edited by
                      #17

                      At the basic level, they're close. Very close. When it comes to finer nuances, C# got ways to write concise code that Java doesn't (top-level statements, switch expressions to name two examples). There's also some nice syntax sugar in C# that Java doesn't have when it comes to OOP. But overall, they're REALLY similar. After all, they all inherit the basic C syntax. I switch between C# (my main development language) and C++ (a project of mine is a user-mode driver the binary requirements for which .NET won't fulfil without bending backwards) and the transition isn't too bad. Syntax-wise, Java fits nicely into the same family.

                      1 Reply Last reply
                      0
                      • L Lost User

                        Yes, relatively easy. Here are some differences to watch out for: - Generics are different, weaker. The syntax sometimes feels oddly backwards too, eg `public boolean containsAll(Collection c);`. - `foreach` loops don't use the `foreach` keyword, but that takes about 10 seconds to get used to. - Since there are no real delegates, Java tends to use interfaces with a `run` method (or equivalent). That also affects how events work. You can use anonymous classes that implement the relevant interface though, you don't have to create a thousand full classes. - Inner classes by default have a reference to a specific instance of their outer class. To get a "plain old inner class", it needs to be a static inner class, which is not a static class. That sounds more confusing than it is. - Operator overloading doesn't exist. Not even for `String`. Avoid `==` between objects (including `String`, but also `Integer`), unless you really meant to compare for reference-equality. And yes, BigInteger arithmetic is pretty painful in Java .. but also pretty efficient actually. BigIntegers in C# only recently approached how efficient they are in Java. - In terms of the framework, `List` -> `ArrayList`, and `Dictionary` -> `HashMap` (some tutorials may mention `Hashtable`, disregard them). - There are no unsigned integers (except `char` but we don't talk about that), which for the most part doesn't matter (many operations are independent of signedness, and there are special methods such as `Integer.compareUnsigned` to implement the operations that *are* dependent on signedness) except that Java's `byte` is signed and you will probably occasionally forget that and get some bugs due to unintended sign-extension.

                        J Offline
                        J Offline
                        John Torjo
                        wrote on last edited by
                        #18

                        Based on the above, can I simply sum this up as: - TLDR: "Java sucks" - Long story: "Java sucks big time"

                        1 Reply Last reply
                        0
                        • S Slow Eddie

                          I was wondering, how close are C# and Java, syntax? Would be Java be "easy" to learn if I know C#?

                          Archchancellor Ridcully

                          P Offline
                          P Offline
                          Paul Sanders the other one
                          wrote on last edited by
                          #19

                          What is the question-behind-the-question, you autocondimentor you?

                          Paul Sanders. If I had more time, I would have written a shorter letter - Blaise Pascal. Some of my best work is in the undo buffer.

                          1 Reply Last reply
                          0
                          • S Slow Eddie

                            I was wondering, how close are C# and Java, syntax? Would be Java be "easy" to learn if I know C#?

                            Archchancellor Ridcully

                            M Offline
                            M Offline
                            maze3
                            wrote on last edited by
                            #20

                            been some time since did Java, 2012. Learned Java at school/uni, first programming job java. then C# 2013, easy enough curve. Now C#/.net 2012 vs Java 2012, a lot of programming similarities. But 2022 c#11/.net core and visual studio 2022, lots of little things, Linq. Java probably got something similar, not sure. Main thing what in Java are you planning on doing, maths, backend, services likly similar cross over. front end/ui stuff, that more JavaFX vs xaml maybe?# Languages similar, frameworks stepper curve

                            1 Reply Last reply
                            0
                            • T trønderen

                              Isn't it commonly known that MS and Sun were arguing about MS' right to develop their Java compiler and market it as Java? MS ended up turning their back to Sun/Java, declaring: OK, we'll forget Java and make something better, then! According to my taste, MS succeeded; C# is and improvement over Java in several respects. But I have been working for a number of years in environments where any such opinion was highly non-PC.

                              M Offline
                              M Offline
                              MSBassSinger
                              wrote on last edited by
                              #21

                              Yep. MS built .NET first around VB, and wanted to bring Java in as one of the languages to compile to MSIL (J++). Since Java was the proprietary property of Sun, Sun sued MS that MS’s cross-licensing with Sun for Java did not allow newer versions of Java to be used, and refused to take MS’ improvements in Java, which MS was glad to share with Sun. Once the courts ruled in Sun’s favor, combined with Sun’s refusal to cross-license any newer versions of Java (which would have benefitted Sun), MS “end of lifed” J++, and created C# (a play on the ++ of C++). After all, the intent of .NET was and is that any language (as syntactic sugar) can be used because it compiled down to language-agnostic MSIL which then gets compiled at runtime, more efficiently and performant than Java. Of course, Sun’s intense hatred of MS led Sun to spend money on lawyers instead of innovation. At the same time, they intentionally made hardware changes in each new update to their computer hardware to prevent MS from running Windows on it. MS had a version of Windows NT compiled for Sun Sparc. But Sun’s irrational hatred of MS led them to make sure they would break Windows NT with each new hardware release. There was a good market for the Sun Sparc workstations and servers where buyers preferred Windows NT over SunOS and Solaris, but Sun would rather go out of business than have a win-win with Microsoft.

                              1 Reply Last reply
                              0
                              • L Lost User

                                It's been some years, but when I got a (corporate) Java project, I had to go shopping: Eclipse (IDE), Spring (UI), Struts, Apache (Web server), NetBeans, JBoss (app server), etc. before I could write any code. c# (Windows; .NET framework) was "no" shopping.

                                "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

                                D Offline
                                D Offline
                                David H Walker
                                wrote on last edited by
                                #22

                                I had a similar experience. I learned Java first, then C#. For a while I was working with both languages. I had a situation occur with a project in each language that required reading and writing XML. I spent two weeks researching (and experimenting with) the multiple libraries for XML processing in Java before I found one that best fit my needs. In C#, there were only two choices (one for processing the entire DOM and one for streaming) and making the choice was obvious. The issue was that there were hundreds of Java libraries from multiple sources but only the Microsoft official libraries for C#. This was over two decades ago. Things have changed. Research is more efficient. Both languages have matured and are more stable.

                                1 Reply Last reply
                                0
                                • G GerVenson

                                  I know what you mean. Now with Net5 & Net6 it just amazed me how easy it was to execute the app on linux now that most of the frameworks catched up to net5.

                                  sudo apt-get install -y dotnet-runtime-6.0 && \
                                  dotnet MYAPP.dll

                                  Only thing to get used to that you "run" dlls^^

                                  S Offline
                                  S Offline
                                  StampedePress
                                  wrote on last edited by
                                  #23

                                  Which one is preferred by *nix folks? Java at least has open versions of JDK. With C# you're a bit stuck in the .Net ecosystem. Not sure if Mono is still a thing anymore. I guess is python to modern take?

                                  G 1 Reply Last reply
                                  0
                                  • S Slow Eddie

                                    I was wondering, how close are C# and Java, syntax? Would be Java be "easy" to learn if I know C#?

                                    Archchancellor Ridcully

                                    S Offline
                                    S Offline
                                    Stephen8601
                                    wrote on last edited by
                                    #24

                                    There are similarities because both C# and Java (and you can throw in C++) are all in the C family

                                    1 Reply Last reply
                                    0
                                    • S StampedePress

                                      Which one is preferred by *nix folks? Java at least has open versions of JDK. With C# you're a bit stuck in the .Net ecosystem. Not sure if Mono is still a thing anymore. I guess is python to modern take?

                                      G Offline
                                      G Offline
                                      GerVenson
                                      wrote on last edited by
                                      #25

                                      What do you mean by that? Dotnet5+ was made completely* open source, you can look at it on github [GitHub - dotnet/runtime: .NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.](https://github.com/dotnet/runtime) Well yes but no, there are some other alternative usages for .net with C# iirc there are JVM-C# version, C#-Embedded and some more. But yes you are more or less fixed to .net, but from my point thats fine. Everything I ever imagined I would like to do, I can with C# (in a reasonable frame). Btw, on another point, mono is the runtime for C# when running on linux nowadays, again: if i remember correctly.

                                      1 Reply Last reply
                                      0
                                      Reply
                                      • Reply as topic
                                      Log in to reply
                                      • Oldest to Newest
                                      • Newest to Oldest
                                      • Most Votes


                                      • Login

                                      • Don't have an account? Register

                                      • Login or register to search.
                                      • First post
                                        Last post
                                      0
                                      • Categories
                                      • Recent
                                      • Tags
                                      • Popular
                                      • World
                                      • Users
                                      • Groups