Coming from C#, is Java a cure to some of my ills?

I mostly use C#, but I'm looking to maybe give Java a spin. I use all three major platforms (Windows, MacOS X, and Linux) on a daily basis, and create a lot of tools to help me with various tasks. Some examples would be a specialized version of grep that has extra features. A webcam monitor to keep an eye on some of my snake enclosures. A web scraper that pulls information for my job from several pages and displays a summary. Many others as well; some cli and some gui. Some I share with other people and some I don't, the people use various OS.

Sometimes things just don't work like they're supposed to. My OSX machine won't, no matter how hard I try, run .Net directly via mono. I end up setting up bash scripts. On Linux I run into issues with the trust store throwing a tantrum at https sites, or having issues with library .dlls that I use regularly. On my Windows machine everything works more or less properly, which it should. When it comes to UI it's a total crap shoot if Winforms will run on any platform that isn't Windows. Mono sometimes work fine, sometimes creates new bugs out of thing air, sometimes doesn't work at all. Same for WPF. I don't really want to use a fallback like GTK#, as that's more and more crap I have to install (and expect my users to install).

Would Java be a better choice for my situation? I keep hearing that Java is king of multiplatform development. I'm a little biased against it because it stumped me when I was first learning, and thus left a bad taste in my mouth, but I'm thinking about giving it another try. Managing .net/mono versions is a pain and it'd be nice if I could just install Java and be done on each platform.

Does Java make bundling extra libraries easy for distribution? Is the UI system decent over platforms?

Edit: After looking it over I think I'm going to give Java a pass. It may make some aspects easier, but there's just so much missing that I'm used to in .Net that I'm not going to bother. I'm not going to list them off because I don't want to turn this in a Java bash any more than this edit already has, but it just doesn't seem worth the hassle.

Posted Mar 1, 2016, 9:20 PM UTC · edited

712
Manitcor•

Java will seem like the cure to some ills and will create all new problems for you to scream about.

Finally there is no language that is truly cross-platform. there is always some details that need to be handled for on just this OS or just that OS. However if cross platform is your primary goal I would say Java is a bit further along there. Just don't expect plug and play for anything but the most simple applications.

4
code_nomadOP•

Java will seem like the cure to some ills and will create all new problems for you to scream about.

What are common points of pain for Java hobbyists? My job isn't programming, I just program for fun and to create tools that make my life and the lives of my coworkers easier, so enterprise-level things don't concern me, just day-to-day pain.

1
Manitcor•

For desktop applications UI I would say, WPF sucks but it is not nearly as difficult to work with as the options under Java. You will also find some fundamental differences between how projects are organized and deployed as well as how configuration is managed. None of these are bad more than they have their own unique pains like C#'s features do.

Aside from that once you get past the front end things get very similar in many ways though Java devs tend to prefer different patterns than you often see in .NET land. You might not use enterprise code but if you adopt a 3rd party lib expect factory and builder to the popular patterns unless it is a newer framework.

1
Northeastpaw•

Java does generally abide by its "write once, run anywhere" mantra. As long as you stay away from JNI/JNA or Runtime.exec() then your code should work across platforms.

The reasons you're running into issues with C# is that until recently it just wasn't meant to run on anything but Windows. Mono tried to bridge the gap but could only do so much. Now that .NET core was open sourced and Xamarin was bought out by Microsoft then maybe .NET on Windows platforms will be a bigger thing, but for now that's a few years away.

When it comes to GUI work on Java, you do have some options. JavaFX is the latest attempt by Oracle to do a bundled toolkit. You also have Swing which, while ugly as sin, is functional. And then there's stuff like SWT.

3
Lord_NShYH•

Mono is on the way out. Before re-writing your code base, try the .NET Core native assemblies for Mac OS X and Linux.

2
code_nomadOP•

The what now? This is the first I've heard of this.

1
Lord_NShYH•

https://dotnet.github.io/

Also, you might like Visual Studio Code:

https://code.visualstudio.com/

1
code_nomadOP•

This doesn't looks like it's really ready for primetime.

I use VSCode for some things. I mostly use Xamarin Studio/monodevelop.

1
Lord_NShYH•

.NET Core is certainly ready for prime time. I'm using it to power an online iGaming (regulated real-money) platform handling millions of transactions in each market it is deployed in.

2
laazik•

VisualStudip Community is definitely one of the things that should not be overlooked. Matter of preference, but IMHO one of the things MS has actually got very right. Using intellij for my daily paid work doing java dev and it's usability is not really comparable.

1
[deleted]•

[deleted]

1
redrainyskiesCodes java but drinks arabica•

Java works nicely on different platforms. While it is true that no language is 100% cross-platform, in my experience Java smooths the differences nicely. I haven't had any headaches beyond trivial stuff (like handling new lines, directory separators... things that should be straightforward for a moderately experienced programmer). I haven't noticed any issues with swing GUIs between Windows and Linux (haven't tried Mac).

Java versions still give some trouble to handle, but you can have several of them installed at the same time. Which one will run is defined by the PATH, JAVA_HOME and JRE_HOME environment variables, and while those are usually set at the system level, you know you can override that setting in a console or in a shell script for a particular program. All of them are backwards compatible, but if you compile binaries with a newer version make sure to set the source level and binary format (command line options to the compiler, usually exposed as drop-down lists in an IDE's config) so that it works with older VMs. Even IDEs have options to manage several VMs installed at the same time.

Bundling libraries isn't that complicated. Just make sure all your .jar archives are in your program's directory and that they are all specified in the Java classpath (whether as an environment variable or as a command line option to the interpreter). Might get a little bit more complicated if any of them contain native code (DLLs or .so; google about JNI if you run into issues) but that's not a common case.

The bad taste you had in your mouth is probably due to the fact that Java is debug oriented: the compiler will complain about anything that doesn't smell good to it even if it is, and several classes throw exceptions paranoidly. IMHO this is actually a good thing if you know why - the platform is taking care of you by providing early notice instead of letting things fail unexpectedly at a random time in the future. C# was a bad experience to me in the sense that it takes just a minute to write a complex program but ages to debug it. Especially not having to declare exceptions means you can see a program crash and end abruptly just because you tried to open a file that was not found or a network timeout occurred.

Of course there are no pros without cons. What I don't like about Java is memory management, as it requires contiguous space specified in the interpreter's command line. Your application won't be able to use more than that even if a lot of memory is available in the OS. In high-end, server-side computing environments I've also had issues as GC takes a lot of time, adding meaningful latency to my programs. But that will only happen if you handle millions of users who send thousands of HTTP requests per second.

1