Java?

Started by
11 comments, last by agm_ultimatex 13 years, 11 months ago
Well, I've been on and off several programming languages, include Game Maker, C, CPP, Python (I was able to make a script that counts up by perfect squares without using multiplication), and devkitPro (C programming for Wii (I was able to make a simple, but glitchy, PONG game with it using a "high" level library)). Anyways, I have at least some experience in these languages, but I have complaints about each one. Game Maker: I am not a graphical artist at all so I can't really make games that look good. C & CPP: they are really hard to do anything in, much less get windows up (50+ lines of code for a "Hello World"? now come on Win32!) Python: IDLE acts up sometimes and won't let me in, and when it does let me in, the color-coded highlights fail to appear. devkitPro is just another C, so same. But! I realize that most of the complaints could be relieved if I had a major programming skill. Planning! I do not know how to plan a program/game if my life depended on it. I would really like to learn, but I have yet to find a guide to planning software projects, or just general planning. I chose to go to Java next because that's what my uncle does, albeit he does not program games, but for business apps. He really couldn't help me when I wanted to program for other languages, either because he did not have that kind of experience, or the books he had on stuff like C were way outdated and/or couldn't really help me. So if I at least learn the keywords and structure of Java, some experience building my own apps from the ground up, and stuff like that, I could go to him next Thanksgiving, (When everybody comes to eat turkey and stuffing and stuff) and ask him stuff that he would know about. (I also chose Java because I get the feeling GUI based interfaces would be easier than CPP to program.) So as a summary, would someone please direct me to some useful sources to learn how to plan and how to program Java? (I don't have spending money for books, so free info would help more, as long as its good quality) I've tried looking on Google, and I know there are Java tutorials on the Sun website, which I am looking into too. I just want to know if there are any good guides/tutorials/help that would achieve the goal of me learning the topics at hand.
Advertisement
Java is considerably easier to use than c++, but it does have lots of pitfalls. For something better suited to games, why not try C# with XNA? This is actually dedicated to games.

You might be told that java is too slow for games; This is not necessarily true. Java itself is perfectly suited to fast code, and yet every piece of java software I've ever used has been slow.

I suspect this is because the java protects you from low level optimisations too much, and you end up doing things on the assumption that the language will magic away the innefficiency;

microallocating in loops (a call to new String within a double nested loop when processing text. String caches its contents internally which partially deals with this but it isnt magic!)

deep copies (you want to make a hash map from an array so you do a deep copy. You have a 1d array and you want a 2d array, so you do a deep copy. One API wants an ArrayList and API2 wants a Stack, so you do a deep copy.)

not understanding order of complexity ( O(1) means that a million takes the same time as one, not that everything takes a small amount of time. Obviously, O(1) is faster than O(n^2) right? No, you have to benchmark to find out.)

an obsession with immutability (java.awt.Color is immutable. For god's sake, why? Try doing 2d graphics with lots of different colours. You have to write an object table just for colours X_X and then of course you suffer the lookup time on a HashMap. (I had this while writing a nice flashy multicoloured histogram object for a university project. My tight loop for drawing lines had lots of "new awt.Color(r,g,b)" in it, which left a comet trail in the garbage collector.)

Using ArrayList for arrays of built in types (int, float, char). Bad idea. Read about auto boxing to find out why.

So anyway, if you read about, and avoid these things in performance critical code, java is perfectly reasonable for games.
Don't thank me, thank the moon's gravitation pull! Post in My Journal and help me to not procrastinate!
If want to make games I dont think Java is your answer. My suggestion is to go for C#, there you have good APIs, like java has, good editors and for the game part close integration to DirectX. C# is Windows/Xbox only though, but that might not be an issue for you ?
You might also take a look at http://qt.nokia.com/ . Qt is a really good c++ framwork, that also has bindings to python and java :) . Qt It encapsulate that things that makes c++ hard.

enjoy programming :)
While C# and XNA are a good fit, there is no harm going down the Java route. In many ways, C# and Java are very similar. I would think that C# is a superior language, but it is also quite a large one. Java is quite small.

Also, I would take speciesUnknown's advice with this pinch of salt: don't worry about performance, yet.

I wrote a game in Java recently, I went for a very naive implementation and I was very surprised with the speed at which it ran. I was using a Java physics library, which I expected to have trouble with. I allocated many 2D vector instances per frame (remember - make the program work correctly first!) and I found I didn't even need to go back and try optimise them.

Obviously, this depends on the type of game. But when you are learning you are likely to making smaller games for a while, until you get the hang of the language and game programming in general.
Ok well, I am now getting both Java and C# with XNA. I'm going to try them both. I just feel if I had said I was looking into C sharp initially, someone would've pointed me instead to Java or something else. Why is it that (almost) every time I get someone saying to choose another language?

But yeah I agree with bjf in the fact that I don't care about portability right now because I probably won't need to since I have Windows XP. C# seems like a viable option for game and GUI programming.

On the other hand, I agree with rip-off in the fact that my smallish programs won't really stress the limits of the Java language at all.

Anyways, thanks for replying. I appreciate the fact that people respond to stuff of the like I ask.
I use Java for games and I do not recommend it.

Some Java fanboys may be quick to tell you that it is now slow because it has JIT compilation and is not interpreted. This is nonsense and irrelevant.

More important is developer attention & purpose. Sun is not actively supporting Java as a game development tool and puts most of their development resources into server work. As such, while using Java for game dev tools, I've ran into seven year old bugs in Java2D that were known and unfixed.

Linguistically you have the fact that everything goes through the GC. There are no, for example, stack allocated classes. I wrote a video player using FFMPEG once, and it would lurch every several frames because all the temporary classes were being thrown away.

I solved this by "recycling" classes, which worked solidly but fundamentally it working around Java's key feature.

If Java's key features are obstacles you must dance around, its not a horse for your course.

I don't recommended Java for multiplatform gaming. Java lets you "write once run anywhere" on Windows, Mac (with testing) and a variety of server platforms and, with extra platform-specific work, phones that account for half a percent of mobile sales. I suggest a few better options.

Flash will cover Windows & Mac with less fuss and is more appropriate. C# & XNA works across the Microsoft platforms (PC\360\Zune). Objective-C is recommended across the Apple platforms (Mac\Pod\Pad\Phone). If you really want to hit it all and more, go native; you can use C++ or Objective-C and do cross-platform the old fashioned way of keeping platform specific code seperated out.

You might also consider this if you wanna do Java gaming for some other reason.
Quote:Why is it that (almost) every time I get someone saying to choose another language?


Well nobody's ever gonna just agree on everything. You have you make your own decisions here.

Consider, though, that the langauge itself is almost never what you make the choice on. You have to start with your specs, and what platforms you want to use for your project, and decide according to that.

And yes, this can be a per-project decision. You're not getting married to the language so if you're just learning, go nuts. You might use Java for something else and learning it now might be a great idea.
Quote:Original post by rip-off
...
Also, I would take speciesUnknown's advice with this pinch of salt: don't worry about performance, yet.
...
But dont totally ignore it, and ignore anybody who tells you not to think about the issues I mentioned. As I said, java makes you think the JVM is magic. A lot of its fanboys get upset at the suggestion that the JVM cant optimise everything for them and will get angry when they read that sort of thing about microallocation or deep copying.

I should however mention that premature optimisation is nearly always bad. Write code, benchmark code, optimise code, in that order.
Don't thank me, thank the moon's gravitation pull! Post in My Journal and help me to not procrastinate!
Quote:Orignal post by JoeCooper
...
And yes, this can be a per-project decision. You're not getting married to the language
...


For educational purposes, I am going to try both Java and C# XNA.

Also, I heard somewhere that knowing a bunch of languages AND knowing how to program and problem solve in those languages is better than just knowing one language really well. Game Devs like people who can conform to how they program their games.
True?

EDIT: and speciesUnknown, i'll take your word that Java wasn't meant specifically for games.
Quote:Original post by FinalSmash
Java wasn't meant specifically for games.

Is there any relevant language that was specifically designed with game programming in mind? Why would that even matter? You can program games in any general purpose programming language.

This topic is closed to new replies.

Advertisement