Java: Where To Next?


JamineBourne

Still Fresh
Joined
Jun 29, 2007
Messages
12
After having a core functionality and understanding in general "programming", where do I go to next to work my way up to writing programs for the Pandora?

About a year ago I posted a topic asking where to begin on learning how to program and I got a plethora of suggestions as to which language I should choose and what tutorial I should use, which I am grateful for. In the end I had decided to go with Java though, and I have learned a bunch of stuff since then and written a couple of programs and games for my usage.

My question is, where do I go from there? I don't understand exacly what is going on in a couple of the threads that talk about SDL, or what a "library's" purpose is, and a couple of other things, and I would appreciate it if somebody could point me in the right direction.



NOTE: I came across this thread: http://www.gp32x.de/board/index.php?showt...312&hl=java and a quote from Xerxes Ranby at the bottom:

"OpenJDK6 is now ported to ARM processors!
This means that all j2se Java applications used on desktop computers can run on Pandora!"

Does that mean I can write a simple "Hello World" program, stick it in a .jar, load it to the Pandora and run it, or what do I have to do in between?
 
Last edited by a moderator:
SDL is a C library that is generally used as a wrapper for OpenGL, SDL is handy at handling the window and events.

Java syntax is very similar to C, if you want to start coding fast applications on the Pandora, start learning some C!

http://www.cprogramming.com/tutorial.html

You could even give the Lazy Foo tutorials a shot, they're great for SDL, but without much prior C knowledge (or C++ as the tutorials use this) you will have trouble.

http://lazyfoo.net/SDL_tutorials/

I don't know the answer to your Java question, but an educated guess would be yes.
 
Well, SDL and OpenGL are the libraries that your programs will need to call on to get access to hardware-type things in the Pandora, like the joydiscs, the graphics accelerator, and things like window management.

Java does technically have OpenGL and SDL bindings, but I think C++ is much better supported.
So, try to learn some C++:

www.cplusplus.com is probably a good place to start
You'll need a C++ compiler, Dev-C++ [Dev-Cpp, maybe] is the best for Windows, or the default g++ for linux
If you already have Java experience, C++ is pretty easy to pick up. The syntax is similar, but it uses objects less and you have to manage memory on your own.

Then look for SDL and OpenGL plugins or whatever they're called for Dev-Cpp and learn to do some SDL stuff. SDL makes it very easy to set up basic input and graphics, and you can use it to set up OpenGL without a lot of window management code.

As for the Java thing, yes, jars should be portable between ARM and x86 as long as you have the JVM configured properly on the Pandora.
 
Don't mess with C, at least not yet. Stay away from C++ if at all possible. Even though Java is a pretty bad language itself, C++ is even worse.

I don't know if the pandora will include j2se by default, but users will be able to install it.
 
lulzfish said:
You'll need a C++ compiler, Dev-C++ [Dev-Cpp, maybe] is the best for Windows, or the default g++ for linux
If you already have Java experience, C++ is pretty easy to pick up. The syntax is similar, but it uses objects less and you have to manage memory on your own.
Dev C++ is an IDE that uses MinGW, a port of GCC, it hasn't bean updated since 2005. If you must use an IDE go with something newer, such as code::blocks. though personally I find programming in a text editor(Vim) to be substantially easier.
 
Last edited by a moderator:
sindbad said:
Don't mess with C, at least not yet. Stay away from C++ if at all possible. Even though Java is a pretty bad language itself, C++ is even worse.

I don't know if the pandora will include j2se by default, but users will be able to install it.
What do you mean, C++ is even worse? C++ is beautiful.

Either way, its the only real way to go, if you're planning on coding for the Pandora.
 
Last edited by a moderator:
Hessiess said:
Dev C++ is an IDE that uses MinGW, a port of GCC, it hasn't bean updated since 2005. If you must use an IDE go with something newer, such as code::blocks. though personally I find programming in a text editor(Vim) to be substantially easier.
I used to think so too.. I'm one of the last of the old school text editor for code lot. But now that Galactic Artifact is up to 12,500 lines of code, going back to a text editor is causing my brain to melt.

Code::Blocks is actually pretty good, once it's configured properly.

Back to the original topic: +9000 to the Lazy Foo SDL suggestion. It's a great start to SDL programming from scratch. He has tutorials where you can learn to program SDL graphics from scratch, without any preexisting knowledge (or even software!). I've been a Java programmer for the past.. wow... 11 years, and while the transition back to C and C++ can be damned frustrating at times, I am learning new stuff as I work through it.

OpenGL is superior to SDL, but it takes a bit more knowledge to get working. A university level Mathematics course on Linear Algebra wouldn't hurt either. I'm waiting to have a Pandora on hand before I dive into that pool, especially since we only appear to have OpenGL ES.

If C or C++ is giving you a heartache, try to whittle down your code to the broken bit and post it here. Even the snarkiest devs (and there are several on the various IRC channels) are helpful when there's some code to look at. This forum has been super helpful to me as well, everyone here is 10x more polite than IRC.

Good Luck!
 
Last edited by a moderator:
Butterman said:
What do you mean, C++ is even worse? C++ is beautiful.
C++ is a hair-losing proposition for those of us coming from Java. If you pick up a decent Java book, and open it to the first chapter, you'll find a good section on "Here are the things that C++ did batshit crazy, and here's what we're doing differently to keep you from going a crazy yourself". On paper C++ is great, but in implementation there are these little niggling exceptions that say "Wait, no, you can't do it that way", that wouldn't bother a C++ programmer.

For me the biggest mental hurdle has been pointers and the non-simplicity of passing objects by reference. In Java, EVERY non-primitive is an object passed by reference. By default in C++, objects are copied when passed to a function. It means a lot of time is spent dereferencing and re-referencing things passed between classes. If you happen to forget this while programming, all of a sudden stuff goes missing, or worse, there's two copies of an object and it no longer behaves as you expect.

Then there's a lot of dumb things. Like "You can't create more than 380 pthreads without detaching them", something that isn't documented anywhere (easily) and took me a couple of hours to track down and figure out. Stuff that's likely obvious to you now that you've gone through the pre-requisite struggle of learning C++ in the first place.

In brief, I spend a lot more time searching through Google looking for posts of other frustrated C++ codes, or going on to IRC to find answers to problems, rather than picking up a book and finding the answer I'm looking for. IMHO, C++ makes programming harder than it needs to be. It's possible that people who learned to code in a C++ environment and don't know any better might not see it that way... :)
 
Last edited by a moderator:
C++ is not beautiful. If the only thing you've seen, maybe. Smalltalk, it's cousin Objective-C, D, Python, Ruby, even JavaScript are beautiful to many people. But not C++.

Bottom line, stick with java and it'll all just work.
 
Trevor Bradley said:
Hessiess said:
Dev C++ is an IDE that uses MinGW, a port of GCC, it hasn't bean updated since 2005. If you must use an IDE go with something newer, such as code::blocks. though personally I find programming in a text editor(Vim) to be substantially easier.
I used to think so too.. I'm one of the last of the old school text editor for code lot. But now that Galactic Artifact is up to 12,500 lines of code, going back to a text editor is causing my brain to melt.

Code::Blocks is actually pretty good, once it's configured properly.


Using an IDE with a large project would be easier, seeing as that's what they are intended for, but as I tend to work on smaller projects, the vast arrays of features in IDE's just get in the way and become annoying. That, and ive grown to like modal editors :D.

QUOTE

OpenGL is superior to SDL, but it takes a bit more knowledge to get working. A university level Mathematics course on Linear Algebra wouldn't hurt either. I'm waiting to have a Pandora on hand before I dive into that pool, especially since we only appear to have OpenGL ES.


Don't forget that SDL can be used to set up OpenGL windows, get user input and play sound, Though it's blitting functions are rather outdated, lacking support for scaling, rotation and alpha transparency. Which means that applications using them are tied to a specific resolution(non-resizeable window), which(amongst other things) also means that they don't work with a tiling window manager.
 
Last edited by a moderator:
Hessiess said:
Don't forget that SDL can be used to set up OpenGL windows, get user input and play sound, Though it's blitting functions are rather outdated, lacking support for scaling, rotation and alpha transparency. Which means that applications using them are tied to a specific resolution(non-resizeable window), which(amongst other things) also means that they don't work with a tiling window manager.
Yup, I'm *very* aware of this. I am a bit spooked by the OpenGL vs OpenGL ES thing though. I'm torn between putting my project aside for a couple of weeks and learning OpenGL ES or waiting to have a Pandora on hand to see how much optimization I need and then doing the conversion then. I'm so far along in my programming that the pain involved is going to be the same either way.

SDL is a wonderful bridge to get into graphics programming though, and isn't a bad choice for programs where fps isn't a big requirement.
 
Last edited by a moderator:
Trevor Bradley said:
Hessiess said:
Don't forget that SDL can be used to set up OpenGL windows, get user input and play sound, Though it's blitting functions are rather outdated, lacking support for scaling, rotation and alpha transparency. Which means that applications using them are tied to a specific resolution(non-resizeable window), which(amongst other things) also means that they don't work with a tiling window manager.
Yup, I'm *very* aware of this. I am a bit spooked by the OpenGL vs OpenGL ES thing though. I'm torn between putting my project aside for a couple of weeks and learning OpenGL ES or waiting to have a Pandora on hand to see how much optimization I need and then doing the conversion then. I'm so far along in my programming that the pain involved is going to be the same either way.

SDL is a wonderful bridge to get into graphics programming though, and isn't a bad choice for programs where fps isn't a big requirement.


Sorry for going off topic, You could use Quad-Ren as an example of using OpenGL with SDL, as the source code is very heavily commented and should be easy to understand, Quad-Ren is actually designed to be an abstraction layer over OpenGL, that provides an API fermilier to SDL(etc) users. The next version will also be able to draw 2D polygon meshes, instead of just textured quads, and will probably be released next weekend.
 
Last edited by a moderator:
Trevor Bradley said:
Yup, I'm *very* aware of this. I am a bit spooked by the OpenGL vs OpenGL ES thing though. I'm torn between putting my project aside for a couple of weeks and learning OpenGL ES or waiting to have a Pandora on hand to see how much optimization I need and then doing the conversion then. I'm so far along in my programming that the pain involved is going to be the same either way.
bit of advice if this is your initiation in gl:

if you decide to go with gl es1.x you'll also get desktop gl as a bonus as these two are very similar, gl es1.x being a streamlined version (bar shaders) of the desktop api we all love. in comparison, with es2 you'll get a steeper learning curve, but es2 is the one future-proof (entirely-shaders), all fat trimmed api of them all (gl2/3, es1 and es2), and basically represent an all-business-no-sweet-talk -kind of philosophy. learning considerations aside, if you don't plan to do legacy gl work (down-ports, etc), es2 is clearly the api of choice for the pandora.
 
Last edited by a moderator:
I'm with Trevor Bradley and sindbad. C/C++ are certainly not "pretty". I mean sure, if you've been beaten or whipped your whole life, you might acquire a taste for it, but... meh.


I started with HTML, so XHTML/XML are completely intuitive to me. I picked up javascript and loved it - but lately javascript's syntax has been morphing in odd ways, and what used to work no longer does in new browsers.

I learned another scripting language that was basically VB with javascript syntax, and it had SDL bindings, so I learned SDL with javascript syntax. Then I toyed around with rendering engines for a while, and did all the usual stuff(map editor, platformer, start of an RTS, space invaders, etc.). Unfortunately, the RTS pathfinding was way too slow in a scripting language, so I decided I had to learn something faster - java.

At first I disliked java(WAAAAY too much typing), but I eventually got over it. I really didn't like Throw/Catch/Finally, but it was important to learn them, as it seems that half the JCL throws exceptions of some sort - usually poorly documented ones with vague or multiple causes.

"IOException" - what is that? File missing? Filesystem corrupted? File already locked? File can't be read/written at the same time? Meh. exit(1);

But for creating stuff for my GP2X, I needed to learn C, so I started learning that. Only took me a couple days to discover C has even more typing, and nomatter what I do, the compiler spits out 300 errors. :lol: Too much odd syntax.

I went back to javascript; but none of my old projects worked! Turns out eval() broke in FF3, so when dealing with scope issues you have to use these weird work-arounds which actually create copies of objects, which vastly slows the scripts down. Meh. <_<

Went back to C for a few days. Still had trouble getting simple stuff to compile. Started looking up assembly. Turns out I find assembly less aggravating than C, and since assembly has very simple syntax, it's very easy to pick up - even though I don't understand what it's doing or how to make programs out of it. :lol: But I did find FASM vastly simpler than C. It follows the rule: "Everything you need is in the source file.", which means you don't need a thousand -D[PATH]'s tacked onto the end of a compile call. You can actually stick some code into a file and compile it, rather than spending days trying to get a toolchain set up for the first time, and ultimately failing. :)

So now here I am. I know Java, could probably learn C#/mono easily, and have a mental block against C/C++. My advice to you is, unless you need C/C++ for a job, just stick with nicer languages.

Your programs will run faster in Java/C#, as you're dealing with a familiar language. Less dev time, less bugs, less code to write, more time to optimize. :)

Bugs per 1000 lines? Probably around 3(java) or 15000(C/C++). :lol:

Anyway, sorry for the rant - but I think everyone here will agree that your most familiar language is the best one to do a project in - even the C coders. ;)

Smiley spam!
 
If you learn C/C++ first, other (procedural/OO) languages are easy to learn. However moving from most other languages to C/C++ can be quite a workload. IMO C is good for low-level stuff, but I wouldn't write frameworks or such on it. C++ can be quite clear and beautiful if used correctly. I have to say though, that most C++ I see is either some C/C++ hybrid abomination, or plain abused C++. I like python, I like java and I like C++. They all have their pros and cons, but each does something better than the other two. So far I haven't needed a fourth language (I know others, but I mainly use these three).
 
I came through school programming in C: I loved it.

Returning to the field a few years ago, I picked up Java. I have to ask: why go back to unmanaged memory and pointers? Java is a lot nicer IMO. Not to mention the fabulous (intimidating at first, but fabulous) standard libraries (collections, etc.). People still trot out the old "Java is slow" argument from time to time. But the latest JVM's from Sun are really quite amazingly optimized: slow code is much more likely due to problematic algorithms than to JVM overhead. Do I sound like a fan?

I've been scratching at C++ for PandoraPanic. Ugh. No doubt my code would make a "real" C++ coder cringe. But ugh. I thought about buying a book & trying to learn C++ properly, but I'm not so sure that's a worthwhile endeavour for me.

I'm thinking seriously about making the jump to Python for future Pandora-centered efforts. I've heard great things about Pygame (I believe it's an SDL library). Ruby is fun to program and Python seems to run in the same class.

Python will be S-L-O-W compared to C++ or Java. BUT! For most applications it won't matter. The baseline Pandora is pretty fast and future hardware will only be faster. Yes, if you're shooting for highly detailed images and mega-fps (e.g., first person shoot-em-ups), I imagine Python is utterly inappropriate. For most other things, it'll probably be fine. And if worst comes to worst, you can always isolate the slow part of your program, re-write in C, and call out to it. Or rewrite the whole thing if necessary -- after you've worked out all the hard problems in the more expressive language.

Machine time is cheap (basically free) these days. Programmer time (your time) is precious and limited. Java, and much more Python, aim to take the burden off you, enabling you to express your algorithms more quickly while they do the dirty work of implementation. As Kramy pointed out above: the more intuitive, less syntax-error-prone grammar of modern interpreted languages is a serious boon to new software development.

--Todd
 
todd said:
I came through school programming in C: I loved it.
I learned C (and, to some extent, C++) before any programming courses. The main proramming language at my university is C++, so I have learned that quite well.

todd said:
Returning to the field a few years ago, I picked up Java. I have to ask: why go back to unmanaged memory and pointers? Java is a lot nicer IMO. Not to mention the fabulous (intimidating at first, but fabulous) standard libraries (collections, etc.). People still trot out the old "Java is slow" argument from time to time. But the latest JVM's from Sun are really quite amazingly optimized: slow code is much more likely due to problematic algorithms than to JVM overhead. Do I sound like a fan?


No, you sound like an informed individual :). It's true, that java isn't nearly as slow as it used to be. However the garbage collection still has many problems with memory-intensive applications. Java can be programmed memory-smart, but at the cost of that trademark clearness. Sometimes it's just easier for everyone that you have destructors and a delete command as opposed to "I do it when I get around to it" garbage collector and finalizers.

todd said:
I've been scratching at C++ for PandoraPanic. Ugh. No doubt my code would make a "real" C++ coder cringe. But ugh. I thought about buying a book & trying to learn C++ properly, but I'm not so sure that's a worthwhile endeavour for me.
Be careful which book you buy if you do though. There's a lot of crap on the marketplace :). I'd recommend the book written by C++ specialists in my university, but unfortunately it's only in finnish.

todd said:
I'm thinking seriously about making the jump to Python for future Pandora-centered efforts. I've heard great things about Pygame (I believe it's an SDL library). Ruby is fun to program and Python seems to run in the same class.
I can seriously recommend getting to know python and pygame. At the least it's super-fast for prototyping and fun to program. If your app isn't that heavy on the python code side (many libraries have C backends, which make them very fast), you can create usable stuff in no time.

todd said:
Python will be S-L-O-W compared to C++ or Java. BUT! For most applications it won't matter. The baseline Pandora is pretty fast and future hardware will only be faster. Yes, if you're shooting for highly detailed images and mega-fps (e.g., first person shoot-em-ups), I imagine Python is utterly inappropriate. For most other things, it'll probably be fine. And if worst comes to worst, you can always isolate the slow part of your program, re-write in C, and call out to it. Or rewrite the whole thing if necessary -- after you've worked out all the hard problems in the more expressive language.
As I stated before, many python libraries, such as pygame, have C backends. This makes them very fast. As long as you keep your python-side algorithms smart, you should be able to get good performance. On top of all this there are things like pyrex, which allow you to code the more intensive parts of your program in a pythonish language while getting a lot better performance (so most of the time you really don't even need to touch C). These coupled with pythons friendly syntax and great libraries are things that make python the programming language of my choice in most cases.

todd said:
Machine time is cheap (basically free) these days. Programmer time (your time) is precious and limited. Java, and much more Python, aim to take the burden off you, enabling you to express your algorithms more quickly while they do the dirty work of implementation. As Kramy pointed out above: the more intuitive, less syntax-error-prone grammar of modern interpreted languages is a serious boon to new software development.

--Todd
You're absolutely right. On desktop computers everything except the high-end stuff (games, image/video/sound manipulation, modeling etc) works ok pretty much regardless of your setup. Because of this most things don't need to be optimized to work on a majority of computers. However with a device like pandora you may get noticably better results by sacrificing your time for that last squeeze of machine time.

Optimization should be done only if it is absolutely necessary and won't make the code more difficult to read, maintain or understand. Optimization should only sacrifice those if there is no other way in the known or unknown universe to get an important feature to work. If this is the case, the optimized code should be commented so well, that a random programmer could tell the reason for any given statement and modify the algorithm without breaking it. Sorry for the rant, I got kinda lost there :)
 
Last edited by a moderator:
todd said:
People still trot out the old "Java is slow" argument from time to time. But the latest JVM's from Sun are really quite amazingly optimized: slow code is much more likely due to problematic algorithms than to JVM overhead.
I'm a Java developer by trade, and I definitely agree with you that JVM performance isn't typically much of an issue these days. In large part, this is due to the continual improvement of the JIT. While the JIT is maintined on x86 and SPARC, I'm not sure if there is a version targeting ARM which means we may only have an interpreted JVM for the Pandora.

Java's garbage collection model can of course, be both a blessing and a curse. 20 second pauses for a full mark-sweep collection are not a good thing in a web application. I've found that while you can gain some significant improvement through tuning the VM parameters, garbage collection certainly doesn't save you from your own mistakes(not that you stated or even implied that it does, but people often end up thinking garbage collection means you don't have to worry about memory management).

I have recently started getting up to speed in C++ in anticipation of doing some development for the Pandora. I haven't seen anything yet that seems too ugly to me, but then again, I used to do quite a bit of development in C
 
Last edited by a moderator:
Back
Top