Java vs C++

I’ve just been trying to learn to do C++ Win32 programming using Visual C++, and I’ve given up on it because it was co complicated. I read somewhere that learning java beforehand makes learning C++ easier. I’ve looked at the java language and its way easier than Win32 C++ (in my opinion). So I was hoping for my Java skills to be a full path not just a step towards Win32 C++. But there’s a problem. I’ve read in an article that Java is about 20 to 50 times slower than C++. But it also said it keeps getting upgraded to make it faster. Another thing that is bothering me in java is the buttons but im quite sure that you can change them. Another thing is that I’ve never heard of a commercial game that is made from java. So can someone tell me more good points about java and the commercial games that were made by it?

Forget about the performance issue - C++ and Java are near to even in complex projects.

Forget about learning Java to get closer to C++. You will never be able to enjoy C++ if you’ve worked with Java once.

Commercial games with Java … ok, thats difficult. There are only very small-scale examples … you’d be the first…

But if you are dealing with buttons and try to learn a language, you really shouldn’t bother about commercial games. There is still a long way to go and everything can happen on that way.

so what do you think i should do then? Forget about java and learn C++? :frowning:

What’s your goal, and which goal is in reach?

I don’t advice anybody to learn C++ the days. C++ is kind of the COBOL of this millenium. It’s ugly and difficult.

But C++ IS the de facto gaming standard language today for mainstream games. No way around that.
So if you want to write a AAA, mainstream title NOW, use C++. But can you really do that? It’s LONG way from learning a language to writing a AAA game. 5 years?

Much closer would be to write simple (or not so simple) applet games? Learn the principles of OO? Java is good for that.

As I mentioned, learning Java takes you far away from knowing C++. But maybe, in 5 years, C++ is no longer a must. I don’t know wether Java will be the no.1 language that (to be honest, I doubt that), but I’m quite sure the one of the newer languages around (like Java, C#) will be the language of choice.

And - you can use you Java knowledge very good if you don’t do games…

Hey! We’re commercial! 8)

Cas :slight_smile:

Yes, sure, commercial, I know.

I hope it’s no offense grouping AF under ‘small-scale’ - the scale ranges up to SplinterCell, HL2 and such.

(BTW, as soon as I get a new job, I will buy me an AF… :wink: )

My goal is to make a programming language that makes games easily. Like Game Maker, 3D Game Studio, Dark Basic, and Blitz Basic 3D. Would Java be the ‘appropriate’ language to use?

so what do you think i should do then? Forget about java and learn C++?

I suggest to use Java. In contrast to C++ it’s is a real high level language and not an macro assembler hacked for OO. It allows you to do your tasks faster and more robustly. Also its giant library lets you concentrate on your task, so no need to re-invent the wheel all day.
Compared to my C++ experience, Java is a real pleasure. I still don’t understand many things, but the learning curve is much smaller and more fun, also because of the execellent documentation (javadoc rules!).

This all applies to “typical” applications.
So now it depends on what game you want to do. If you take a look at Alien-Flux ( http://www.puppygames.net/ ) you’ll see it’s well possible to do fast action games with cool graphic and sound effects in Java (with OpenGL).

For a “typical” game (not Doom3), like 3d/isometric real-time strategy games, there are two critical topics to consider.

  1. The graphics output. Luckily today you can deligate most of the “pixel transfer” to OpenGL, so that you “just” need to know how to use the OpenGL API in the right way. To master this isn’t easy at all, but it doesn’t matter if you call the API from within Java or C++. Much more important is to reduce the amount of data which is sent to OpenGL. This mainly depends on clever choice of algorithms and data structures. I bet somebody who knows how to program Java in the right way can do this task nearly as efficient (90-95%?) in Java compared to C++.

  2. Simulation/AI. Again the clever choice of algorithms and data structures is the absolute main point. Practically nobody programs a full price game’s AI in a low level language like Assembler anymore (*), although from a “CPU cycle per second” view this would be faster. The right algorithms are the joker, while the choice of programmings language is minor (so use the one which helps you most: Java). Many of today’s full price games use interpreter languages inside their C++ to do the AI tasks, because so the developers reach their goals more efficiently (on the same time they laugh at Java because it’s a interpreter language?). A few commercial games (like Sturmovic) used Java for their KI and other parts (the graphics engine has been in C++ - but this has been before Jogl’s been there).
    For many real-time strategy games the simulation/AI does take more CPU time than the graphics system. A ratio “AI to gfx” of 2:1 isn’t unusual.

Well, I’d say games which rely on CPU brute force (Doom3 because the CPU has to help the graphics card a very lot, etc) will be faster in C++ compared to Java.
However many other games could well be done in Java, if your target PC isn’t an old 300 MHz without a 3d card. :slight_smile: The Sims, Zoo Tycoon, Monkey Island 3, Runaway: A Road Adventure, and probably most of the other adventures, role playing games, and many real-time strategy games.

(*) The exception being the fantastic Roller Coaster Tycoon game from scottish braveheart Chris Sawyer. This game has been programmed entirely in Assembler, and it’s for sure the fastest isometric strategy game I’ve ever seen. And it flies on a 200 Mhz PC with no 3d card. Ha! :slight_smile:

What I mean as commercial games is like Starcraft, Counter Strike, and StarTrek Elite force. The games that you can find in your local gaming store. :stuck_out_tongue:

So it may be better for me to stay with java then, for now anyway.

P.S. whats OO? and whats JavaDoc? (Pardon my n00bness :stuck_out_tongue: )

[quote]P.S. whats OO? and whats JavaDoc? (Pardon my n00bness :stuck_out_tongue: )
[/quote]
OO is short for “Object Orientated” programming. For example the difference between C and C++ is the OO part of C++.

Javadoc is a tool of the Java SDK and is used to generate nice HTML output of your codes’s documentation which should use the Javadoc commands in its class and method comments.
http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javadoc.html
If you watch the Java API documentation, for example here: file://localhost/i:/Sprachen/Java/Jdk1.4.2/api/overview-summary.html all this is being produced with Javadoc from the original Java API sourcecode.
So: no seperate source code and documentation anymore, but both in one, so it’s always up to date etc.

The last years we’ve used Doxygen for our C++ applications, which is a kind of “Javadoc for C++”.

You obviously wont find too much C++ love around here. It is a big bulky language, no doubt, but it’s not exactly horrendous and definitely still has its place. (But don’t be surprised to see languages like python, C# and of course Java continue to eat C++'s marketshare).

What are you using to learn C++, I mean book/class/website wise? That can make all the difference. C++ definitely gets very complex as you go, but shouldn't be too bad to begin with. Maybe your approach needs reconsidering.

As for the 20-50 times slower, maybe in 1996 it was (if it was ever that slow). Java has come a loooong ways in speed, it’s far closer to C++ nowadays.

Most of the larger scale java programs seem alittle slower than C++. Like NetBeans and Alien Flux (But that game rocks!). And as for the clever Algorithms wouldnt it be the same speed increase if used for c++? So is making an interpreter in Java that makes games suitable? Or is using c++ better?

I will say that Java is much easier to learn algorithms/data structures with. The Java2D also helps start you out with graphics. The nicest thing is you don’t have to worry about the Win32 API.

C++ is a very powerful language, but as my Professor says, “C++ is a huge language. Most of the ‘C++ Gurus’ only touch a small part of it and are afraid to explore any farther.” And yes, I did learn C++ before I learned Java. The transition was easy. Going back to C++ when school started, on the other hand, wasn’t quite as easy. Damn pointers…

The speeds of C++ and Java are very comparable. And Cas can correct me if I’m wrong, but AlienFlux was compiled to native code using JET, right? So then the fact that it’s written in Java should not make any noticable difference.

An interpreter for games in java is possible, particularly because Java has a built in regular expressions class. However, what I would advise is to learn the theories and use Java as a tool to use what you have learned. When you’re ready for a game interpreter, then pick a language that is good for parsing.

[quote]And as for the clever Algorithms wouldnt it be the same speed increase if used for c++?
[/quote]
Sure; however what I tried to say was that to select the correct algorithms and data structures is by far more important than the programming language you use to implement it.
With C you can be faster than with C++ because you’ve got more direct control of what the compiler produces. Same applies to assembler.
Still, hardly anybody uses plain C or assembler for a game’s simulation/KI part anymore (has been different 10 years ago), because 1.) if you got the algorithms right, the very minimal spead increase you could gain with a more “low level language” isn’t worth the hassle (and compared to Java C++ is more low level). And 2.) you’ll reach your goals faster and more efficient with a high level language. Time/effort is a very big factor in (games) industry.

[quote]So is making an interpreter in Java that makes games suitable? Or is using c++ better?
[/quote]
Using an interpreter in an interpreter language is more straightforward. :slight_smile:
There are several easy to use script approaches for games with nice interpreter languages. A previous poster mentioned regular expessions (in Java since … Java 1.3 or 1.4 ?) which indeed is a big pro for parsing scripts and implementing an own simple script engine.
The point is: since many C++ games run their AI in an interpreted way anyway, interpreter languages are used actually in many games.

Yes, AF is available as a Jet-compiled EXE… I’d be interested to know which bit of AF is “slower than C++” though seeing as there’s nothing to compare it to… that and the fact the bottleneck is in the graphics card fill rate and bus bandwidth… (run task manager and note the CPU usage)

Cas :slight_smile:

I personally never got good results with JET, but esp. AF runs absolutely smooth even from a WebStart launch and I guess the CPU is nearly idle. So I don’t think there would be any benefit for C++ here.

Ah, many of today games a GPU bound.

Even our 3D flight sim runs with 50% CPU on a decent machine with some 10s of enemies in the air. Not CPU bound. So faster code wouldn’t help neither.

[quote]Most of the larger scale java programs seem alittle slower than C++. Like NetBeans
[/quote]
NetBeans is slow, but NetBeans uses Swing extensively. That’s more a Swing problem than a Java problem. Look at Eclipse, written in Java, just as big (if not bigger) as NetBeans, and is blazing fast.

Speed is not always attributable to the language or environment. Poorly written code or code that makes certain compromises could be slow, regardless of what language it’s written in.

How very true! However, you have to apply your second comment to the first to be fair - you can write blazingly fast Swing interfaces, the real problem with NetBeans is the way they’ve used Swing. :wink:

I back that up - I worked on a big Swing app with lots of zooming, transparency, animation and interaction - more than just buttons.
Performance hasn’t been an issue.