[java] Java rant

Started by
2 comments, last by vtRequiem 23 years, 10 months ago
Am I the only C/C++ programmer that has a hard time adjusting to moving to Java? I''m currently workin on a tetris applet, cuz that''s what I''m making my programming class do, and things are just movin so slow for me. Now I''m stuck trying to get my key handler to work! I have a few java books, and none of them really have a good example of a key handler in action, which frustrates me even more. Oh well, I think that I can tough this out, but I''ll be glad when this is done so that I can get to work on DirectX and Win32. I just thought that the Java graphics system would be a little simpler, but it''s actually turned out tougher. Anybody else have similar problems? Take care! Req dddDDDdddDDDdddDDDdddDDDddd Big Brother is Watching
dddDDDdddDDDdddDDDdddDDDddd Big Brother is Watching
Advertisement
It''s not that hard, here is a example from my RPG:

public class window extends Window
...
addKeyListener(new KeyEventHandler());
...
final class KeyEventHandler extends KeyAdapter
{

public final void keyPressed(KeyEvent ke)
{


switch(ke.getKeyCode())
{

case KeyEvent.VK_NUMPAD1: GoDPC.moveSouthWest();
break;
case KeyEvent.VK_NUMPAD2: GoDPC.moveSouth();
break;
case KeyEvent.VK_NUMPAD3: GoDPC.moveSouthEast();
break;
case KeyEvent.VK_NUMPAD4: GoDPC.moveWest();
break;
case KeyEvent.VK_NUMPAD5: GoDPC.moveHold();
break;
case KeyEvent.VK_NUMPAD6: GoDPC.moveEast();
break;
case KeyEvent.VK_NUMPAD7: GoDPC.moveNorthWest();
break;
case KeyEvent.VK_NUMPAD8: GoDPC.moveNorth();
break;
case KeyEvent.VK_NUMPAD9: GoDPC.moveNorthEast();
break;
case KeyEvent.VK_ESCAPE: menu.show();
break;
}

//Collision detection/bounding


}
}


I can''t edit it very well right now and it may be missing one brace after a quick view. I think Java''s basic graphics are easy. Firstly you set up a double buffering, then you draw on offscreen and then you paint the buffer. WIth this formula you can do almost any kinds of animations and movements.


Time comes, time goes and I only am.
This a common problem. I''ve never touched C++ {I mostly stick to scripting languages} and don''t really feel like trying after all the complaints I''ve heard.

From those moving from C/C++ to Java:
- Bleh! Where''s the interface.
- A char is two bytes. Sure, whatever you say...
- I can''t dirrectly control pointers? What gives?!

From those moving from Java to C/C++:
- Pointers! Do you think I''m nuts!
- Now, why would I want to have headaches over multi-threading?
- Memory management? You mean it doesn''t just happen?

Personally, I''m sticking with Java. Why? Linux, BeOS, + Multi-threading.
I''ve helped at work a couple of programmers to make the jump from C++ to Java and I can symphatise with you. It is larger step than the language syntax difference makes you believe. Also the graphics part is the most difficult part of the Java library to understand. It has all these oddities (like not being able to create a bitmap via window object if that window object has not been shown yet), but once you understand the underlying architecture it becomes a lot easier and after a couple of years you''ll be using those graphics handling parts like you were born with them imprinted in your mind.

But your frustration is common for every situation where you change your tools (language, libraries, programming IDE etc.). The first miles with the new set of tools are allways uphill battle filled with boobytraps. I myself find it invigorating to once in a while force yourself to relearn almost everything. It really helps you to get a broader perspective on many things and to grow as a programmer. I also did my share of C++/DirectX programming, until I learned OpenGL which seemed a much better choice for 3D API and then I somehow drifted over to Java side because the productivity is so much better with Java and I can live with the performance tradeoff.

In my opinion the libraries that come with Java are of better design than most comparable libraries under C++. The guys that have done those Java libraries have really read their share about programming patterns and such.

So my advice to you would be to just keep going a bit further. Maybe do another small game (it''ll be a lot easier the second time around) and poke around in the new space you are exploring. You never know if you can pick up something new that can be easily used under DirectX/C++. I see all these APIs, languages etc. more or less the same way, they are just tools and the way you do things is mostly independent from them. But still different tools just make you do things a bit differently and that is where the richness of the experience lies.
-Pasi Keranen

This topic is closed to new replies.

Advertisement