• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Why don't more game dev's use Java?

Java is slow (it's not native code, but interpreted), its garbage collection is... garbage(pardon the pun) its memory management doesn't work for games.
 

Durante

Member
Java's JIT solved most of the overhead problems.
You know, writing compilers is my job. Trust me when I say that having a JIT compiler does not, in and of itself, "solve most overhead problems". Crucially, JIT compilation does nothing for garbage collection, which is one of the most significant hurdles to consistent realtime performance. Concurrent garbage collection with limited overhead and predictable performance is still an ongoing research topic.

Even if you were going for a garbage-collected dynamic language (perhaps for some parts of your game where performance is not very relevant or can be easily controlled), then why would you chose Java? C# is almost the same thing but with some of the major language-level issues (e.g. stack/heap allocation, boxing/unboxing, operator overloading inconsistencies, etc.) resolved, and other dynamic languages (Lua, Python, Ruby) offer even greater productivity advantages for non-performance-sensitive gameplay code.

Basically, Java is like a highly limited C++ in productivity and features, while being potentially much slower and crucially far less predictable in execution.


It's good for learning
I very strongly disagree with this one. Java teaches people all the wrong things, and it's not particularly good for learning anything.
  • Low-level programming, operating systems, and basic algorithm and memory management knowledge is best taught in C.
  • High-level concepts, advanced algorithms, composition, type systems, and language concepts are best taught in some high-level functional language such as Haskell or OCaml.
  • General programming for larger user-facing programs can be taught in Java if you really have to, but e.g. Python or Ruby are also good choices for this and round out the set of languages much better (e.g. having one statically but not strictly typed, eagerly evaluated compiled language in C, a strictly statically typed lazily evaluated language in Haskell and a dynamically typed, interpreted/JITed language in Ruby).
 

bomblord1

Banned
Oh, come on, guys. Java isn't that bad. It's just not made for games.

Yes, it's garbage collection you can't control, it has no memory management. For some things, this is great. It's not for games.

C# is like a middle ground between C and Java. It's starting to get a lot of use in game development, and I'm happy about it.

You do have some control over the garbage collection but you can't free up individual objects though. I can understand why that would discourage people who are aiming at very specific performance goals though.
 

3DShovel

Member
Oh, come on, guys. Java isn't that bad. It's just not made for games.

Yes, it's garbage collection you can't control, it has no memory management. For some things, this is great. It's not for games.

C# is like a middle ground between C and Java. It's starting to get a lot of use in game development, and I'm happy about it.

Yeah, Java isn't a bad language at all. It's by far the most widely used language in the industry, just not the gaming industry in particular (obviously).
 
Java is a terrible language. For one.

Though that's probably not the reason. One important reason is likely that garbage-collected languages were historically garbage (pardon the pun) for anything which requires consistent realtime performance.

Pretty much all this. C# is better than Java in pretty much every way that actually matters. Nondeterministic garbage collection is not fun when you are trying to meet that "consistent 16 ms" goal.

Java portability is a myth. You are going to build your game for each individual platform anyways, and with good libraries/SDK C++ code is as portable as Java.

Also, Java is slow. You may have benchmarks that have otherwise, but try doing real-time signal processing in it, and you will learn that the hard way. And it consumes gratuitous amounts of RAM, while RAM is a limited resource on game consoles (PS3 has 256 MB, for example).
 

Trouble

Banned
Java is a terrible language. For one.

We're done here.

Oh, come on, guys. Java isn't that bad. It's just not made for games.

Yes, it's garbage collection you can't control, it has no memory management. For some things, this is great. It's not for games.

C# is like a middle ground between C and Java. It's starting to get a lot of use in game development, and I'm happy about it.

What is it made for? It's terrible for all purposes. The JVM is comically inefficient. Interpreted languages end up being faster in the real world and so much easier to manage deployments.
 
Not even taking game development into the equation, Java is a horrible language. I've started and stopped Android development so many times because I quickly got sick of the thick layers of boilerplate and OOP madness.

If you need to use the JVM for whatever reason I'd recommend Scala instead. It's a far more modern language with a very clean syntax that doesn't bombard you with cruft.
 
I like Java but it is on its way out in favor of C#, especially now that Microsoft made .NET open source and released the community edition of visual studio. Even before that, C# had a wide appeal even for developing apps that run on linux and some micro devices.

But even then, some developers need to code to the metal and they will still use C++ or a lower level language. There really isn't much of a use case for Java anymore in gaming.
 
C/C++ is mostly in AAA games because of middleware and yes, massive flexibility with memory and when you are dealing with importance of performance, Very technical games will opt for C/C++.

C# however is very popular when games aren't pushing limits, it's also very popular with indies. The entire XNA project by Microsoft spawned a huge amount of indie games, many of them big hit indie games, today Monogame is keeping it alive.

C# is the most adopted language of choice with Unity and games such as Shadowrun, Wasteland, Hearthstone, Kerbal Space Program, Gone Home, Ori and the Blind Forest, Might & Magic X Legacy, RUST, FRACT, Among the Sleep, Pillars of Eternity, the list goes on and on. None of these are pushing the limits of technology, but all use C#.

Unreal Engine at the moment also has unofficial C# support because C# is such a widely used language nowadays, people want to and love using it. It has good adoption rates.

C# doesn't have manual memory control, it uses a garbage collector, it's miles and miles ahead of Java's but still not ideal when you actually need to control that memory so you won't see C# being used to push very technical games. It's more than capable though and a perfectly suited language for games depending on what you are trying to do.

When you really get technical and the game becomes a huge performance burden you will see C# struggle with its garbage collector, experiencing "hooks"/stutter every now and then in gameplay with a very technical game is because of the garbage collector doing its work when dealing with what you want to hold in memory in the game as well as when putting something in and destroying something else.

Code I wrote few years ago was in C# and it dealt with pretty crazy explosions, dealing with that when it would occur would cause a "hitch" for a frame or so when the garbage collector did its work when things were destroyed in the game from the explosion such as destructibles. No amount of perf passes would solve it, it was solely due to the garbage collector not being efficient enough to deal with it. Nothing a programmer could have control over unless they were using a language like C/C++ that required the programmer to do all the memory management that could make this go away.

C/C++ has always been the industry defacto language due to flexibility + middleware that was natively for C/C++ (although you could prob write binds for other languages, nobody wants to do that if they can just go the native way), C# is pretty much the language that is widely commonly used after C/C++.

This is on my opinion/experience, been programming for 10+ years now every day with C/C++ and C# (I do love C# for what it does, dearly). C# is definitely the most adopted language and useful one other than C/C++ when it comes to games at the moment.

You can opt out of both garbage collection and memory managed pointers in C# using the fixed and unsafe keywords. It's easier not to, and the performance is pretty good any way! Bad C++ can easily be slower than good C#.
Java suffers from supporting legacy code and doing silly things like type erasure...
JITing is pretty good in both languages, and you can do things like pre-JIT using NGEN as well in .Net). Also you can write pure IL in C# using Reflection.Emit. I've written games using C# for both the 360 and PC (actually the same game on both, you could play each other which is why .NET is great) and it was pretty fast!
 
There are ways to prevent memory allocation problems in Java AFAIK. Pools of reusable objects, for example.

There are some pretty neat gaming-related libraries available in Java. Anybody who would want to develop a 2D game should take a look at Slick, for example.

PS : I tend to agree that Java is a poor language, throught. And getting worse and worse.
 

El Phenicks

Neo Member
You can't manually manage memory but you have some decent control over the garbage collection protocols if you're trying to optimize your code.


I'm sorry to inform you but that simply won't do, using System.gc() will just signal the VM it's ready to collect. That operation runs asynchronously, you may be loading a texture as it's doing that and performance will shatter.

The main reason C++ is the king of video game programming languages is the full control and assurance it gives over memory.

Even Minecraft had performance issues that plagued it for years. It simple isn't a good enough language for critical processing tasks, but for any other task it will do the work just fine.
 

mjontrix

Member
Ask notch I'm sure he'll explain why. No sane person would torture themselves like that.

it's Like using a flathead as a screwdriver For Phillips headscrews
 

Krejlooc

Banned
Java portability is a myth. You are going to build your game for each individual platform anyways, and with good libraries/SDK C++ code is as portable as Java.

Case in point - I've seen SDL 2 applications run on both my phone and PC without changing a line of code, only build options. Would I want to actually deploy such a build? Of course not. But choosing the right libraries can yield similar portability.
 

Stumpokapow

listen to the mad man
Javascript != Java

Same company though.

Not the same company, no. JavaScript was originally developed by Netscape, and is today formalized as ECMAScript and pushed forward by a variety of companies. Java was developed by Sun (today Oracle). The reason for the naming confusion is a dumb marketing decision at early days, nothing to do with the language.
 

Akai__

Member
I very strongly disagree with this one. Java teaches people all the wrong things, and it's not particularly good for learning anything.
  • Low-level programming, operating systems, and basic algorithm and memory management knowledge is best taught in C.
  • High-level concepts, advanced algorithms, composition, type systems, and language concepts are best taught in some high-level functional language such as Haskell or OCaml.
  • General programming for larger user-facing programs can be taught in Java if you really have to, but e.g. Python or Ruby are also good choices for this and round out the set of languages much better (e.g. having one statically but not strictly typed, eagerly evaluated compiled language in C, a strictly statically typed lazily evaluated language in Haskell and a dynamically typed, interpreted/JITed language in Ruby).

Wished you were in charge at my university. All we do is coding in Haskell, Python, Java, Assembler and just a very very tiny bit of C languages.
 
  • Lack of memory management
  • Uncontrollable garbage collection that takes a shitload of resources to run
  • Inability to code for performance
  • Can't access template types in runtime
  • No inherent unsigned datatypes
  • No inherent compound datatypes
  • No Const keyword
  • Can't have arrays larger than the size of an int (which also means it can't memory map files larger than 2GB)
  • Considerably less secure and more exploitable by the end-user
  • Bad at catching and throwing exceptions
  • Can't typecast certain types to other types (int to long, for example)
  • Functions of the same name, but different parameters, will destroy each other
  • Doesn't handle static class members properly
  • You generally end up with tons of unnecessary (except in Java) code duplication
  • Constructors can't call other constructors
  • You can't create lists literally (1,2,3,4) you have to create them manually (1) (2) (3).

I haven't used it in probably 6 years, so some newer versions may have addressed some of the above.
 

bomblord1

Banned
You know, writing compilers is my job. Trust me when I say that having a JIT compiler does not, in and of itself, "solve most overhead problems". Crucially, JIT compilation does nothing for garbage collection, which is one of the most significant hurdles to consistent realtime performance. Concurrent garbage collection with limited overhead and predictable performance is still an ongoing research topic.

Even if you were going for a garbage-collected dynamic language (perhaps for some parts of your game where performance is not very relevant or can be easily controlled), then why would you chose Java? C# is almost the same thing but with some of the major language-level issues (e.g. stack/heap allocation, boxing/unboxing, operator overloading inconsistencies, etc.) resolved, and other dynamic languages (Lua, Python, Ruby) offer even greater productivity advantages for non-performance-sensitive gameplay code.

Basically, Java is like a highly limited C++ in productivity and features, while being potentially much slower and crucially far less predictable in execution.


I very strongly disagree with this one. Java teaches people all the wrong things, and it's not particularly good for learning anything.
  • Low-level programming, operating systems, and basic algorithm and memory management knowledge is best taught in C.
  • High-level concepts, advanced algorithms, composition, type systems, and language concepts are best taught in some high-level functional language such as Haskell or OCaml.
  • General programming for larger user-facing programs can be taught in Java if you really have to, but e.g. Python or Ruby are also good choices for this and round out the set of languages much better (e.g. having one statically but not strictly typed, eagerly evaluated compiled language in C, a strictly statically typed lazily evaluated language in Haskell and a dynamically typed, interpreted/JITed language in Ruby).

Could you point me to some information on this because everything I have read says Java programs run just as fast as comparable C# programs
 

Elsolar

Member
Lots of exaggeration in this thread. Basically, Java isn't used much for games programming because there are better alternatives for the Windows platform, which is what 99% of games are made for. For graphically-intensive AAA games C++ is the language of choice because of its speed and flexibility. For smaller, indie games C# is a very popular alternative because of its ease of use, simplicity, and integration with DirectX. If more gamers used Linux or Mac, we'd probably see more games written in Java and OpenGL. With things the way they are, however, C++ and C# with DirectX are going to remain the languages of choice for the foreseeable future.
 
You can opt out of both garbage collection and memory managed pointers in C# using the fixed and unsafe keywords. It's easier not to, and the performance is pretty good any way! Bad C++ can easily be slower than good C#.
Java suffers from supporting legacy code and doing silly things like type erasure...
JITing is pretty good in both languages, and you can do things like pre-JIT using NGEN as well in .Net). Also you can write pure IL in C# using Reflection.Emit. I've written games using C# for both the 360 and PC (actually the same game on both, you could play each other which is why .NET is great) and it was pretty fast!

Yeah that is true, I was busy adding a footnote regarding exactly that and I refreshed this thread and saw your reply. You're correct.
 
I don't even know how bad it is because it's the only language I use. ¯_(ツ)_/¯
Do they still teach Java as the primary programming language at high schools and universities? I'd wager the only reason most schools even touch Java is because of its unfortunate ubiquity in industry.
 

Trouble

Banned
  • Lack of memory management
  • Uncontrollable garbage collection that takes a shitload of resources to run
  • Inability to code for performance
  • Can't access template types in runtime
  • No inherent unsigned datatypes
  • No inherent compound datatypes
  • No Const keyword
  • Can't have arrays larger than the size of an int (which also means it can't memory map files larger than 2GB)
  • Considerably less secure and more exploitable by the end-user
  • Bad at catching and throwing exceptions
  • Can't typecast certain types to other types (int to long, for example)
  • Functions of the same name, but different parameters, will destroy each other
  • Doesn't handle static class members properly
  • You generally end up with tons of unnecessary (except in Java) code duplication
  • Constructors can't call other constructors
  • You can't create lists literally (1,2,3,4) you have to create them manually (1) (2) (3).

I haven't used it in probably 6 years, so some newer versions may have addressed some of the above.

No operator overloading. Except the String object is overloaded because the language designers didn't even follow their own rules.
 

Earendil

Member
There's no such thing as a bad programing language, just bad uses of programming languages. Every language has its good points and bad points. (this from someone who has used about 20 languages since 1993)

Using the wrong language in the wrong situation is like using a wrench as a hammer.
 

bomblord1

Banned
Do they still teach Java as the primary programming language at high schools and universities? I'd wager the only reason most schools even touch Java is because of its unfortunate ubiquity in industry.

I have a teacher who preaches it. He's has a doctorate in computer science and has written several papers on it. I think he is part of the reason it's one of the major languages taught here.
 

Kamion

Member
I hate that so much programming nowadays is in Java (not in games). The language is just horrible.

I'd just prefer C# and Objective-C (I develop for Apple platforms a lot and have been too lazy to learn Swift yet) any day.
 

DSix

Banned
Don't worry OP, C# is fairly easy to learn for Java users. You could grab XNA/Monogame and start making games right away. No need to shackle yourself to JVM.
 

bomblord1

Banned
I'm sorry to inform you but that simply won't do, using System.gc() will just signal the VM it's ready to collect. That operation runs asynchronously, you may be loading a texture as it's doing that and performance will shatter.

The main reason C++ is the king of video game programming languages is the full control and assurance it gives over memory.

Even Minecraft had performance issues that plagued it for years. It simple isn't a good enough language for critical processing tasks, but for any other task it will do the work just fine.

Did you read the link?
 

El Phenicks

Neo Member
Did you read the link?

The question is : did you read the link ?

Explicit Garbage Collection
Another way applications can interact with garbage collection is by invoking full garbage collections explicitly by calling System.gc(). This can force a major collection to be done when it may not be necessary (i.e., when a minor collection would suffice), and so in general should be avoided. The performance impact of explicit garbage collections can be measured by disabling them using the flag -XX:+DisableExplicitGC, which causes the VM to ignore calls to System.gc().

One of the most commonly encountered uses of explicit garbage collection occurs with RMI's distributed garbage collection (DGC). Applications using RMI refer to objects in other virtual machines. Garbage cannot be collected in these distributed applications without occasionally collection the local heap, so RMI forces full collections periodically. The frequency of these collections can be controlled with properties. For example,

java -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 ...
specifies explicit collection once per hour instead of the default rate of once per minute. However, this may also cause some objects to take much longer to be reclaimed. These properties can be set as high as Long.MAX_VALUE to make the time between explicit collections effectively infinite, if there is no desire for an upper bound on the timeliness of DGC activity.

There's no way to generically set the VM parameters so they magically run everywhere the same. That's wishful thinking.
 

bomblord1

Banned
Isn't Java vulnerable?

Isn't Windows vulerable?

The question is : did you read the link ?

Yes?

This shows that negligible speed issues when developing on small systems may become principal bottlenecks when scaling up to large systems. However, small improvements in reducing such a bottleneck can produce large gains in performance. For a sufficiently large system it becomes well worthwhile to select the right garbage collector and to tune it if necessary.

5. Available Collectors
The discussion to this point has been about the serial collector. The Java HotSpot VM includes three different collectors, each with different performance characteristics.

Selecting a Collector
Unless your application has rather strict pause time requirements, first run your application and allow the VM to select a collector. If necessary, adjust the heap size to improve performance. If the performance still does not meet your goals, then use the following guidelines as a starting point for selecting a collector.

You can fine tune garbage collecting timing, size, and type to help mitigate performance issues in specific situations. I'm aware it's not the same as or as efficient as manual memory management but you do have control on when and how it executes and can use that to fine tune it.
 

pants

Member
Java isnt a bad language for webapps and cross platform development, get off it. It's not suited to video games though, mostly because you can only make suggestions re garbage collection and cant specify it absolutely to the JVM
 
I have a teacher who preaches it. He's has a doctorate in computer science and has written several papers on it. I think he is part of the reason it's one of the major languages taught here.

I am not going to call your teacher out for being an idiot. But does he have actual real world experience in large IT infrastructures?

I deal in data warehousing. Hadoop is a damn nightmare to deal with every time there are Java updates. Not only is it a nightmare. Having it play nicely with any of my older systems is borderline dark sorcery.
 

Zane

Member
I can't be the only one here who prefers C over C++. I write all my games in it. OOP is the devil
 

Krejlooc

Banned
No operator overloading. Except the String object is overloaded because the language designers didn't even follow their own rules.

There are also minor quibbles with java that just rub me wrong. Like 2d arrays being an array of arrays rather than one sequential block of memory.
 

bomblord1

Banned
I am not going to call your teacher out for being an idiot. But does he have actual real world experience in large IT infrastructures?

I deal in data warehousing. Hadoop is a damn nightmare to deal with every time there are Java updates. Not only is it a nightmare. Having it play nicely with any of my older systems is borderline dark sorcery.

I have no clue. He's an awesome guy and I generally like to assume he knows what he's talking about but it might just come down to confirmational bias. I've never had an issue with Java but as you said I've never used any large scale IT infrastructure that involves it.
 

Ciastek3214

Junior Member
I can't be the only one here who prefers C over C++. I write all my games in it. OOP is the devil

Me, although I've been only teaching myself programming on a non-regular basis for 2 years. OOP concept itself doesn't seem like much of an improvement over usual C. That and the C++ syntax is just unfriendly.
 
Do they still teach Java as the primary programming language at high schools and universities? I'd wager the only reason most schools even touch Java is because of its unfortunate ubiquity in industry.

When I was at uni 12 yrs ago the primary backbone language of software engineering course was C++.

My introduction to Java took place in a second year module and I avoided it like the plague after that. Horrible language.
 
Top Bottom