Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] benefits of Java question

Started by BradSnobar Mar 28, 2009 at 2:23 PM 13 replies 5.9k views
Original Post
BradSnobar
BradSnobar
I've been wondering about the main benefits of Java over other languages. I'm a C# developer for the most part but I've been finding Java somewhat intriguing for a while. So, I've been wondering what Java is best used for nowadays. What are its strongest benefits? I'm just curious and hopeful that some of the comments here will help me understand more about the Java culture and enlighten me. Afterwards, I want to perhaps make some useful Java applications so if you have some pet projects that you want to share ideas about, then I would be glad to hear about them for some inspiration. Thanks much!
pink_daisy
pink_daisy
advantages:

-platform independent. write once (nearly always) run most anywhere. It's not perfect but it beats the pants off c/c++ portability.
-garbage collection works well *most* of the time. there are small gotcha's but you couldn't pay me enough to go back to managing memory in c/c++. There's a performance penalty for sure, but it's well worth the cost imo.
-array bounds checking. yes there's a performance penalty to have java check array bounds everytime you access an array and yes for me it's well worth the price. Billions of ops per second I can afford to spend a few to get rid of hard-to-track bugs.
-many other nice features: typesafe enums, method chaining, etc.
-multithreaded support is very nice.

disadvantages:

-horrible reputation when it comes to performance. Much of it was rightly earned. In 1996 spending 30mb to fire up and interpret code on a 486/pentium computer with 8/16/32 mb of ram was going to be slow. The JIT and hotspot technologies have helped a bunch over the years. The biggest improvement to java performance is because computers have becomes so much faster. GBs of RAM and ghz processors with multiple cores have largly diminished the performance issues.
-C# is newer and learned from many of java's mistakes. My gut feeling is MS dumps far more man hours into C# than Sun dumps into Java. That's just my opinion.
-some people hate the lack of destructors, no 'explicit' pointers, lack of method pointers, no multiple inheritance, etc.

If you are coming from C# you'll find much the same in Java. There are a few WTF things in Java that C# fixed. You do open up a greater number of platforms though with java which is nice. Then again MS still controls about 85% of the OS market, but I remember when it used to be 95% though 5 years ago. If google makes an OS i'm sure java will be quick to the party and C# will not. If everyone likes windows 7 and MS regains 90%+ market share C# becomes a better choice and java less so. The future is impossible to predict.

The fanbois will tell you that Java is as fast as c/c++ and the haters will tell you java is as slow as dirt. Unfortunately they are looking at the wrong metric. There *is* a cost for the nice features in Java. the GC eats CPU cycles and there's no way around that. The runtime array bounds checking eats CPU cycles and there's no way around that. In compiled languages the "price" of compilation is paid by the dev at compile time, in Java that "price" is paid by the end user when the program starts up.

The question isn't whether it's slower -- because it is -- (how much is another issue) but whether sacrificing some speed for the GC+runtime checking is a good tradoff. In economics we call it a cost/benefit analysis.

Of course end users don't really care if you wrote the game in C#, Java, C/C++, or assembly. They only care that it runs bugfree and at an acceptable speed. Even the users get the benefits of CG/runtime checks because it will help coders right code faster and with fewer bugs. Even though the user is paying a performance penalty for using java, they still get the benefits of getting a game with fewer bugs and a faster development lifecycle.

On balance if you are already familiar with C# then it's probably the way to go. Unless you have some horrible beef with MS or think that the iphone is going to supplant windows then there's not much of a reason to jump ship. Personally I like java, but it's very possible that Java missed its opportunity to ge a good gaming platform. I could be wrong. Time will tell.

I will say this though. C/C++ are old. Very old. C dates back to the late 60s and C++ the late 70s. The stroustrup C++ book sitting on my shelf is probably older than most people who use these forums. Sure there are people even today who will expouse how great Fortran and Cobol are but they are living in the past. We had to use Fortran in college i'd rather poke my eyes out then go back to that. The same holds true for C/C++. Sure they might be the pre eminent languages for game programming -- today. Eventually that will change. It won't change today. Not next week, or even next year, but eventually it will. I'm sure someone out there is still using his 386 and will tell anyone who will listen as to why it's so much better than a new quadcore machine, but i'll stick with modern hardware thanks.

I worked at a windows programmer years ago. I used to work at MS, and there's no way you can convince me to go "back" to c/c++ programming. If you want to get a job at a game company then you will need to know your c/c++, but if you are doing it as a hobby or running your own company then I would certainly use a more modern language.

~don
www.ChippedDagger.com"They that can give up essential liberty to obtain temporary safety deserve neither." -- Benjamin Franklin"If opportunity doesn't knock, build a door." -- Milton Berle
lephyrius
lephyrius
Advantage:
Java:s strongest benefit is that it is portable to like any platform and it scales really well.(think supercomputers and servers) Also the extremely large standard library that has alot of things. There are a lot of java programmers out there also so it is easy to get help.

Disadvantage:
I feel it is a lot of code I need to write in order to get something done and most of the time I feel the standard library to be overly designed and complicated. I also miss a lot of things from C++ like destructors/templates(not the crippled generics)/const/delete. Yes you heard it right I miss delete because most of the time I get problems with the garbage collection under my rendering of the scene.
OrangyTang
OrangyTang
If you're explicitly comparing C# to Java then the obvious advantage is the sheer number of mature, stable libraries available - C# is getting there (especially as lots of major open source Java libraries are being ported over to C#) but Java having existed for a good deal longer means there's lots of libraries for almost everything under the sun.
BradSnobar
BradSnobar
Thanks very much for the replies! They were very informative and helpful!
Xyle
Xyle
Just had to add, my main reason for going to Java from Visual Basic, Dark Basic, Blitz3d was 100% due to deployment. I love Java Applets!
SteveTaylor
SteveTaylor
Quote:
There *is* a cost for the nice features in Java. the GC eats CPU cycles and there's no way around that.
I agree, but also consider that reference counting - a very common practice in C++ - eats up cycles.

I'm a big fan of Java simply because it's head and shoulders above anything I used before it, but if you're accustomed to C# you're going to feel a bit naked with less language features and less than ideal generics. One of the design philosophies behind C# is that a language with more features allows you to do more with less lines of code. The line has to be drawn somewhere, though, and I don't have enough experience with C# to know how far either side of that line it is. I'd say Java is a bit short of it, but it may be closer (ie. better balanced) than C#.

Quote:
Yes you heard it right I miss delete because most of the time I get problems with the garbage collection under my rendering of the scene.
If you're referring to jittery rendering, see if there's a regular pattern to the jitter (eg. 1.5 Hz). It could be a beat caused by the game timer not matching the screen refresh rate.
Stani R
Stani R
There are actually many threads in these forums comparing Java with various other languages. It comes up every so often, so search around and you'll find more info.

With C# you get the nice advantage of using DirectX. If all you care about is making games for Windows, that's all you need. Java games with OpenGL can be made to run with minimal effort on Linux and Mac, as well.

About the whole "is Java slower" thing: Sun likes to present it as a philosophical issue. Java code gets compiled at run time based on analyzing how the code performs and optimizing it. Since this information is not available at compile time for C/C++ programs, compiled Java code could therefore _theoretically_ be faster due to various optimizations. I haven't looked at any benchmarks so I'm not sure if this holds true in practice or not. What is true is that you pay a small but significant memory overhead for the VM, which also takes some time to load and get warmed up.

Development time is also an issue. Java applications can be written much faster and are easier to debug. It's not as concise as Python and such but still presents a nice trade-off between being fast to develop and being close to the metal. It shouldn't be much different from C# in this aspect though.

Applets are a nice feature, but I find that it can be difficult to get them to perform reliably when reloading without quitting the browser.

Java is also dominant in mobile games, so if you ever want to write a game for your phone you will likely want to pick up Java.

Other common uses include enterprise applications as well as web applications (JSP / Servlets). I actually prefer Servlets over PHP as they help me separate the MVC parts better.
SteveTaylor
SteveTaylor
While we're talking about applets, I think they're a great idea gone horribly wrong. There's one simple reason why Adobe Flash content is far more prevalent: It doesn't popup in your system tray advertising itself. Applets also advertise Java while loading, which has been enough to put off many developers, but the animation can be overridden, which isn't widely known.
ssjx
ssjx
Totally agree with what Xyle said. Applets to me are one of the best things about Java and the main reason I am doing more Java games now.
---
Visit ssjx.co.uk for Java, Windows and Cybiko games, programs and source code!
ninten
ninten
Java Webstart is fine too. I advice you to use IzPack for bigger games. The applets have been improved recently in the latest updates of Java 1.6, they are more reliable now. JavaFX is really promising, you can use JMC to display videos quite easily for example.
http://tuer.sourceforge.net/tuer.jnlp (game installation)http://tuer.sourceforge.net/experimental/tuer.jnlp (experimental version)http://tuer.sourceforge.net/download.php (source code)
Drathis
Drathis
Webstart is awesome. When you want to distribute your game, you can just give a link to the user. User might be asked a security question, and then the game starts. Of course the game still has to download, but no more choosing a download location, unzipping the game and firing up the .exe file. Even if you use some platform dependent libraries, you can configure it in the webstart, so your user doesn't have to think about it. The user can even create a desktop icon for your game from the link, and they will always be playing the most up to date version.

The bad thing is that Java has to be configured properly, and many times it just isn't. The browser might not automatically open the webstart file with java, and user might have to manually do that. Java might not be even installed. And why does sun feel the need to constantly remind that Java is running and it is the greatest thing in the world. Sometimes I just think that Sun doesn't even want Java to succeed in other places than enterprise software.
lithos
lithos
If Java wasn't so apathetic about the Home user and Games when they first brought java to the household. I doubt flash would have half the following it would now. For all we know flash would have been made with Java if their first home offerings weren't so pathetic.

It wasn't till what 1.5 that they thought it would be a good idea to show users update nags, later? Silly, but that's milk spilt way in the past and well past sour.

_______________

As for developing in Java, It's a language that tends to be fun to program in because it was made for the programmers instead of for the computers(more so than other languages). Java is also designed so that programmers are strongly encouraged to use the same type of styles/design methods(You WILL be OO and in similar styles to every other java program).

In the end for the kind of things a vast majority people will work on their own code will be a bottleneck instead of the language or hardware they use. So it would be silly to work on a language you don't like or one you'd rather not use.
Zahlman
Zahlman
Honestly, if you're coming from C#, you're not going to see very much potential in Java. :) It's been around longer, which means it's better supported in some ways. You could just as easily be a C++ programmer wondering about C (although C# wasn't directly created as a successor to Java, and C#'s creator vehemently denies that Java has anything to do with his design, the similarities and differences are fairly analogous.)
Antheus
Antheus
Quote:
Original post by Zahlman
You could just as easily be a C++ programmer wondering about C (although C# wasn't directly created as a successor to Java, and C#'s creator vehemently denies that Java has anything to do with his design, the similarities and differences are fairly analogous.)


The C# + .Net combo to me, on first look, reminds me much more of Delphi than of Java. If nothing else, then delegates, properties and UI builder design, which are fundamental, are essentially 1:1 of how Delphi (language + default RAD) have always worked.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.