Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (429)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (466)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Help understanding the significance of using Java  (Read 3332 times)
0 Members and 1 Guest are viewing this topic.
Offline syrinth

Senior Newbie





« Posted 2012-01-25 21:04:09 »

I understand that Java is useful for portable gaming because it can be run on multiple platforms. However, if I'm building a video game with the intention of only having it be on the PC, is there any reason for me to use Java over, say, C++?

From what I understand Java is slower and not as efficient as C++, even if it is easier to use.
Offline ra4king

JGO Kernel


Medals: 322
Projects: 2
Exp: 4 years


I'm the King!


« Reply #1 - Posted 2012-01-25 21:08:37 »

From what I understand Java is slower and not as efficient as C++, even if it is easier to use.
You underestimate the significance of the last point. Java is actually not that much slower than C++. It also takes a LOT of effort to have C++ run faster than Java, or so I've heard. The memory aspect is the only unfortunate thing about Java, but memory being so abundant today it's not that big of an issue.

Online Roquen
« Reply #2 - Posted 2012-01-25 21:12:42 »

If you know neither, then Java is easier to learn.  If you already know C++, then there's no "big" reason to run out and learn Java.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

JGO Kernel


Medals: 284
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #3 - Posted 2012-01-25 21:42:23 »

Well, generally it is usually quite a bit faster to get something working and working well in Java with less hair loss, profanity, etc.

Java is also generally a fair bit slower than C++ - I'd say on average it runs about half the speed without extensive tuning and you particularly notice it in startup times. But then ... the speed and ease of development bit really is extraordinarily significant. Part of the reason it's slower is because it catches things at runtime that take an age to debug in C++.

Of course you could then compile the Java code natively using Excelsior JET and get the best of both worlds if you're that serious about performance.

Cas Smiley

Offline syrinth

Senior Newbie





« Reply #4 - Posted 2012-01-25 21:50:02 »

Well as it stands I know both C++ and Java. I'm looking to start work on some projects *primarily PC based since I don't have a smart phone* and I enjoy Java programming more, but am concerned about whether or not I should program in C++.
Offline ra4king

JGO Kernel


Medals: 322
Projects: 2
Exp: 4 years


I'm the King!


« Reply #5 - Posted 2012-01-25 22:06:32 »

If you enjoy Java and you want to develop some not overly large projects for the PC, then I say you should go with Java Smiley

Offline philfrei
« Reply #6 - Posted 2012-01-25 22:14:35 »

One question that occurs to me is to ask what you are hoping to accomplish? Do you want to sell or market the game in hopes of making money? Is it a learning exercise? Is it something to point to as an accomplishment when applying for employment? Is it just for fun? Also, what are the performance requirements for the game?

The amount of performance one gets from Java is related to the extent to which one writes code the Java way, as opposed to the C++ way or Python way. *Some* of Java's rep for slowness come from C++ programmers writing stylistically dubious Java code and using that as the basis for their comparision.

I recently discovered "Uncle Bob" (Robert C. Martin) and have adopted many of the Agile practices, and find it is cutting down the time spent debugging.


"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Offline princec

JGO Kernel


Medals: 284
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #7 - Posted 2012-01-25 22:16:44 »

It could also be said that some of Java's slowness comes from writing code the Java way instead of the C way... tough cookie to really nail down. But for anything other than AAA titles running cutting edge engines Java does great on the desktop and no obstacle to becoming a multi-millionaire with a game at all.

Cas Smiley

Offline syrinth

Senior Newbie





« Reply #8 - Posted 2012-01-25 22:29:23 »

I graduated with a degree in Game Design, although my school was in hindsight a bit derp and I really don't have much experience actually making games. I want to build a portfolio of "I'm not an idiot please hire me" projects. They're both learning experiences and portfolio fodder.

I think I'll work with Java for now and switch the languages up after.
Offline princec

JGO Kernel


Medals: 284
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #9 - Posted 2012-01-25 22:45:13 »

Ah, if you want hiring in the games industry, you are probably better off in C++.

Cas Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline lhkbob

JGO Knight


Medals: 32



« Reply #10 - Posted 2012-01-25 23:03:25 »

If you're going to use hardware acceleration, the graphics card will be your biggest bottleneck and the speed differences between Java and C++ will mostly disappear.

Offline Cero
« Reply #11 - Posted 2012-01-25 23:06:33 »

From what I understand Java is slower and not as efficient as C++

See guys... people think this, and they will never stop
even though Java, Server JVM, has been faster than C++ for some time now.

"Java is slow" will never stop =)

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 613
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #12 - Posted 2012-01-25 23:08:34 »

Just like Cas said, most of the time Java is quite a bit slower than C/C++ (in the 20%-50% range).

Only in a very limited number of cases, Java is faster.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline princec

JGO Kernel


Medals: 284
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #13 - Posted 2012-01-25 23:12:46 »

A lot of it is down to how Java uses memory rather than the code quality emitted by the latest Hotspot compilers. This can be worked around with them fancy mapped objects but it's not trivial.

Also, the CPU is now more likely to be the bottleneck on modern desktops, as GPUs have gotten monster powerful. You have to be something of a wizard to overwhelm GPUs these days. Or pathologically determined.

But still: Excelsior JET. Whooooooosh!

Cas Smiley

Offline theagentd
« Reply #14 - Posted 2012-01-26 04:30:00 »

A lot of it is down to how Java uses memory rather than the code quality emitted by the latest Hotspot compilers. This can be worked around with them fancy mapped objects but it's not trivial.

Also, the CPU is now more likely to be the bottleneck on modern desktops, as GPUs have gotten monster powerful. You have to be something of a wizard to overwhelm GPUs these days. Or pathologically determined.

But still: Excelsior JET. Whooooooosh!

Cas Smiley
The CPU should never be the bottleneck in a decent new game. Almost all heavy computations can be done on the GPU, and the things that can't can be threaded on the CPU. Look at Battlefield 3, they did it right.

I have this awesome argument: If you choose C/C++ over Java because you need the speed of it, you're doing something wrong. You should have enough performance in Java that anything that you can program by alone (in contrast to a game company, I mean) should not need such insane performance. And if you actually happen to need more performance, you'd be forced to try out faster more advanced algorithms to get it running instead of just relying on the language being faster.

Myomyomyo.
Offline lhkbob

JGO Knight


Medals: 32



« Reply #15 - Posted 2012-01-26 04:44:55 »

A lot of it is down to how Java uses memory rather than the code quality emitted by the latest Hotspot compilers. This can be worked around with them fancy mapped objects but it's not trivial.

Also, the CPU is now more likely to be the bottleneck on modern desktops, as GPUs have gotten monster powerful. You have to be something of a wizard to overwhelm GPUs these days. Or pathologically determined.

A lot of my point about GPUs being the bottleneck was that pushing the expensive operations to the GPU free up the CPU to do other things while the GPU is busy.  Of course you need to use multithreading to truly take advantage of this.  Also, when doing graphics work, you're almost always doing "mapped" objects since vertex attribute data is usually packed into buffers or arrays, so you don't run into the memory cache problems of java.

Offline kaffiene
« Reply #16 - Posted 2012-01-26 04:49:45 »

Just like Cas said, most of the time Java is quite a bit slower than C/C++ (in the 20%-50% range).

Only in a very limited number of cases, Java is faster.

That doesn't match my experience at all.  I've written OpenGL code in C++ and Java and got the same performance (obviously, that's because the gfx is the bottlekneck, but that *is* the case for a lot of games.

Additionally, I've done a lot of benchmarking of looping structures and calculations I was making and I found Java to be 80-105% the speed of the equivalent (optimised) C++ out of Visual C++ 2005.

The *one* case I found that Java ran really slowly compared to C++ was a memory thrashing test where I was doing allocation of randomly sized arrays in a loop (of course, a Java array is actually quite a lot more than a C++ array - a byte buffer would probably have been a fairer comparison)

I would agree that Java utilises memory worse than C/C++.  

Offline pitbuller
« Reply #17 - Posted 2012-01-26 09:29:17 »

Just use JNI for the last bottleneck parts that have to be calculated at cpu side.

If you pick full c++ get a good book that you can read allways when you wait that your project is compiling. I mean books.
Offline cylab

JGO Knight


Medals: 34



« Reply #18 - Posted 2012-01-26 09:45:04 »

I want to build a portfolio of "I'm not an idiot please hire me" projects. They're both learning experiences and portfolio fodder.

If you want to build up a portfolie as a game designer, you might be better off with some modding projects or Unity (which allows for C# scripting, so not so much different than Java).

Mathias - I Know What [you] Did Last Summer!
Offline princec

JGO Kernel


Medals: 284
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #19 - Posted 2012-01-26 10:17:33 »

The slow bits in Java - which are the CPU bottlenecks - are the bits where you go traversing hundreds of thousands of little objects scattered all over memory in order to pack a simple bytebuffer with, say, 30,000 vertices. In C++ the hundreds of thousands of little objects would generally easily fit into a design using value classes embedded in each other, probably with various unions, and the whole thing would basically be a contiguous block of memory you'd traverse from start to finish, achieving pretty phenomenal performance.

In Java land, you will generally have followed the path of least resistance, and allocated a bunch of little objects all referencing each other in a nice easy to understand OOP design, which will then gradually get scattered all over memory and effectively accessed in an almost completely random manner after a very short while, leading to almost pathologically crap cache usage and slowing the CPU down to about a tenth of its potential speed. No amount of threading saves you from the horrors of the knackered cache - in fact it makes it worse.

And thusly, I conclude that despite only drawing 4000 sprites, I am actually CPU limited unless I rewrite everything from the ground up to use mapped objects in ByteBuffers. YMMV but you need to know this right at the start of your design. Unfortunately my stuff evolved from just over 10 years ago when the graphics card was indeed the bottleneck and it didn't make any difference.

Cas Smiley

Offline Orangy Tang

JGO Kernel


Medals: 51
Projects: 11


Monkey for a head


« Reply #20 - Posted 2012-01-26 19:28:54 »

Ah, if you want hiring in the games industry, you are probably better off in C++.

Cas Smiley

Not too sure about that. Depends - syrinth are you looking for a job as a game designer or a programmer? If programmer then it depends on what area you're thinking (C++ - consoles, Java - android, ObjectiveC - iPhone). If designer then you might be better learning something like Lua which is more widely used for level scripting by designers (maybe try love2d?)

Or just make stuff in whatever language you want. It's all programming at the end of the day. I was hired to write C++ code when I only had a Java portfolio so it's not as critical as you'd think.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline sproingie

JGO Kernel


Medals: 200



« Reply #21 - Posted 2012-01-26 21:43:08 »

There's an interesting blog about high performance Java here: http://mechanical-sympathy.blogspot.com/
Offline gouessej

« In padded room »



TUER


« Reply #22 - Posted 2012-01-26 21:53:41 »

From what I understand Java is slower and not as efficient as C++, even if it is easier to use.
Actually, Java can even be faster than C and C++, it's not new, it was already the case in 2004. Forgetting your prejudices would be better.

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 613
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #23 - Posted 2012-01-26 21:55:13 »

From what I understand Java is slower and not as efficient as C++, even if it is easier to use.
Actually, Java can even be faster than C and C++, it's not new, it was already the case in 2004. Forgetting your prejudices would be better.
Java certainly can be faster than C/C++, it's just not that often the case. Typical performance is 80% of 'native' code, which is mainly caused by the lack of structs, as Cas said.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline pitbuller
« Reply #24 - Posted 2012-01-26 22:19:36 »

It would be fun to organize something like ludum dare but for bench marking. For given short time period and semi complex numerical or algorithmical problem. Programming language choise would be free. Fastest code would win but it should also produce correct results. That would measure performance * productivity.
Online Roquen
« Reply #25 - Posted 2012-01-26 22:26:39 »

If you want java to win then don't choose a numeric problem and make sure that it's pointer intensive and that nobody working on the C++ side has the slightest clue about cache oblivious data structures, temporal hints...actually it would be best if they were clueless about how hardware works.  But seriously kids, which is faster is a pretty pointless argument most of the time for our purposes here.

(EDIT: as a reminder...I hate C++)
Offline philfrei
« Reply #26 - Posted 2012-01-27 00:34:48 »

I'm reading through an interesting book: "Write Great Code: Volume 2: thinking Low-Level, writing High-Level" by Randall Hyde. It's more for compiler-based languages like C & Pascal, but there are occasional references to Java.

One interesting point they make over and over is that using a compiler doesn't guarantee the highest level of performance (even though compilers and presumably the JVM as well are continuing to improve). So if there is a stat that Java produces code that is 80% of native, what % does the compiler produce, compared to writing in assembly directly rather than using a compiler-based higher level language?

It seems at the end of the day, there is a big variance in coding depending upon knowledge of underlying machine, and whether one comes up with algorithms that take advantage. My knowledge there is kind of weak. It's been a long time since I wrangled with 8080, Z-80, PDP-11, that kind of stuff, so this is a refresher, to say the least.

@sproingie - I appreciate the blog reference to "Mechanical Sympathy: Hardware and Software working together". This looks like a bunch of great info right on this topic.

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Offline JL235

JGO Coder


Medals: 10



« Reply #27 - Posted 2012-01-27 12:43:53 »

It could also be said that some of Java's slowness comes from writing code the Java way instead of the C way...
I would second this.

I've seen examples of Java code, where it tries to be as OO as possible. I've seen multiple examples were a developer will iterate over the pixels in an image, and turned each pixel into a brand new Color object. Removing that single piece of object creation, and instead working on the pixel as an integer, usually gives the biggest speed up.

But I have rarely encountered big speed issues with Java. When I have, it's normally that I'm doing a lot of work, rather then Java being slow. Most of the issues I have encountered are around garbage collection; again the idea that it's ok to constantly create and then let go of millions of objects (such as lots of bullets or heavily adding/removing items from a HashMap or LinkedList). However once you know about this, it is pretty easy to fix (an hour or two work at most). You can use one of the many open source (and well written) collections available online to lower the GC on collections; and by making the other objects (such as bullets) re-usable.

Overall, getting good performance out of Java is pretty easy. I work a lot in JavaScript, and I spend far more time finding ways to speed that up then I ever did with Java.

Online Damocles
« Reply #28 - Posted 2012-01-27 14:16:57 »

The less "take you by the hand" you want, the lower you go in languages.
Java is in the end a Virtual Machine, giving you a framework and also limits wich dont exist when writing low-level C code.

Its also a matter of taste and productivity if you like a ready-to-go gameengine like unity, or (total opposite) love hacking in assembler.
Java lets you do a lot, but still remains some boundaries, wich some devs dont want.

Regarding Speed: CPU related performance problems are rather a conceptual error, than related to the used language.
The developer want to do something not very applicable for a (realtime) game, and should rather rethink his approch to the procedure, than why the languagemight slow something down.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (80 views)
2014-04-15 18:08:23

BurntPizza (72 views)
2014-04-15 03:46:01

UprightPath (83 views)
2014-04-14 17:39:50

UprightPath (67 views)
2014-04-14 17:35:47

Porlus (83 views)
2014-04-14 15:48:38

tom_mai78101 (107 views)
2014-04-10 04:04:31

BurntPizza (167 views)
2014-04-08 23:06:04

tom_mai78101 (263 views)
2014-04-05 13:34:39

trollwarrior1 (213 views)
2014-04-04 12:06:45

CJLetsGame (222 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!