Java For The Win?

DY357LXDY357LX Playing since day 1. Still can't Comm.England Join Date: 2002-10-27 Member: 1651Members, Constellation
<div class="IPBDescription">Or Is It Limited In Functionality?</div> I've been learning Java on my I.T course over the past 4/5 days
(all of it I have cruised through and stayed a good 4 steps ahead
of the pack so I can chill out at the end of the weeks) and the only
thing that has really grabbed my attention.... is the Java Programming.

Thankfully, my tutor is pretty clever and he knows what he's doing.
So i'm not stuck reading stupidly complex books.
He does seem very pro Java and doesn't seem to like me asking questions
about C++. (I keep accidently calling "Methods", "Functions" and that
seems to grate on him alittle.)

I asked weather an applet that sets the X and Y co-ordinates of the
mouse pointer was possible but he wasn't sure and said that Java was
very high on keeping things "Secure". And lets be honest, messing with
a users mouse is hardly secure <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html/emoticons/smile-fix.gif' border='0' style='vertical-align:middle' alt='smile-fix.gif' /><!--endemo-->

So anyway, I want to know if any of you lot can point me in the direction of
some nice nub-friendly tutorials (I have several sites book-marked already)
especially those that point to playing with the mouse positions.

Here's what I managed today: java guru's can copy and paste this
into their own .java file and then compile it. It's, as far as I know, errorless.

<!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->// Project Name : HelloJava 4

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class HelloJava4
{
public static void main( String [] args )
{
 JFrame frame = new JFrame( "HelloJava4" );
 frame.getContentPane().add( new HelloComponent4("Look at me, i'm colour blind!" ));
 frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
 frame.setSize (300, 300);
 frame.setVisible ( true );
}
}


class HelloComponent4 extends JComponent
implements MouseMotionListener, ActionListener, Runnable

{
 String theMessage;
 int messageX = 40, messageY = 95;  //coordinates of msg
 
 JButton theButton;
 
 int colorIndex;  //current index into some colours
 static Color[] someColors =
  {
   Color.black, Color.red, Color.green, Color.blue, Color.cyan, Color.magenta
  };
 
  boolean blinkState;
 
  public HelloComponent4( String message )
   {
    theMessage = message;
    theButton = new JButton("Change Colour");
    setLayout( new FlowLayout() );
    add( theButton );
    theButton.addActionListener( this );
    addMouseMotionListener( this );
    Thread t = new Thread ( this );
    t.start();
   }
   
   public void paintComponent( Graphics g )
   {
    g.setColor(blinkState ? getBackground() : currentColor() );
    g.drawString(theMessage, messageX, messageY);
   }
   
   public void mouseDragged(MouseEvent e)
   {
    messageX = e.getX();
    messageY = e.getY();
    repaint();
   }
   
   public void mouseMoved(MouseEvent e) { }
   
   public void actionPerformed( ActionEvent e)
   {
    if (e.getSource() == theButton )
    changeColor();
   }
   
   synchronized private void changeColor()
   {
    if (++colorIndex == someColors.length)
     colorIndex = 0;
     setForeground( currentColor() );
     repaint();
   }
   
   synchronized private Color currentColor( )
   {
    return someColors[colorIndex];
   }
   
   public void run( )
   {
    try
     {
     
      while(true) {
      blinkState = !blinkState;
      repaint();
      Thread.sleep(300);
          }
         
      }catch (InterruptedException ie) { }
   }
}
<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->

Tomorrow (or Monday) i'll be writing a "magic 8 ball" applet.
At the moment I like C++ more than I like Java, but thats
probably because I have a slightly better understaning of it.
(Only slightly, i'm still learning.)

Comments

  • moultanomoultano Creator of ns_shiva. Join Date: 2002-12-14 Member: 10806Members, NS1 Playtester, Contributor, Constellation, NS2 Playtester, Squad Five Blue, Reinforced - Shadow, WC 2013 - Gold, NS2 Community Developer, Pistachionauts
    In case you haven't found it already, this thing is what makes programming in java enjoyable.
    <a href='http://java.sun.com/j2se/1.4.2/docs/api/' target='_blank'>http://java.sun.com/j2se/1.4.2/docs/api/</a>

    Most of the time, my thoughts on java can be summed up in this great quotation.
    "Liking java because it works on all systems is like liking anal sex because it works on all genders."
  • SandstormSandstorm Join Date: 2003-09-25 Member: 21205Members
    I remember using a Java version of Netscape on OS/2. It was so much faster than the 16-bit Windows version, and it felt just like a native OS/2 application. This was around late '95 or so.

    If OS/2 had actually survived, I suspect Java would have been way more popular than it is now.
  • DY357LXDY357LX Playing since day 1. Still can&#39;t Comm. England Join Date: 2002-10-27 Member: 1651Members, Constellation
    <!--QuoteBegin-moultano+Mar 3 2005, 07:44 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (moultano @ Mar 3 2005, 07:44 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> In case you haven't found it already, this thing is what makes programming in java enjoyable.
    <a href='http://java.sun.com/j2se/1.4.2/docs/api/' target='_blank'>http://java.sun.com/j2se/1.4.2/docs/api/</a>

    Most of the time, my thoughts on java can be summed up in this great quotation.
    "Liking java because it works on all systems is like liking anal sex because it works on all genders." <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd-->
    LMAO
    i'll show my tutor that tomorrow because he's pointed
    out the "it works on all OS's" part several times.
  • CabooseCaboose title = name(self, handle) Join Date: 2003-02-15 Member: 13597Members, Constellation
    Yea, but only some peolple like anal sex <!--emo&:D--><img src='http://www.unknownworlds.com/forums/html/emoticons/biggrin-fix.gif' border='0' style='vertical-align:middle' alt='biggrin-fix.gif' /><!--endemo-->

    And my god, I love that API, so handy.
  • DOOManiacDOOManiac Worst. Critic. Ever. Join Date: 2002-04-17 Member: 462Members, NS1 Playtester
    There is no one language that you can say "this is the one true and noble language and there should be no others!" Otherwise, we wouldn't have the THOUSANDS of programming languages that we do. :P

    Java, just like any other language, is just another tool in the programmer's toolbox. It definately has its place. You wouldn't use an axe to drive a nail (although it would certainly work), nor would you use a hammer to cut down a tree. And of course, everyone has their favorite tool in the toolbox, such is human nature.

    Java's main strong point is running on multiple platforms (which nowadays can include PDAs, cell phones, wristwatches, or even your TV). Another very thing it has going for it, that I sometimes really, really miss with other languages, is the Javadoc documentation system. Also Java is completely and truely 100% object oriented. It's not optional like it is in almost every other OOP-capable language I've worked with, its required. Sometimes this is a very good thing, however it occassionally is a nusiance.

    So how do I feel about it? It used to be really, really crappy, but its gotten a lot better within the past 4 years, and nowadays it has firmly claimed its space in the grand scheme of things. While I'd rather use C++, PHP, or even VB.net (again, depending on the application), at least its better than Pascal, COBOL, LISP, ADA, FORTRAN, etc. :P
  • Nemesis_ZeroNemesis_Zero Old European Join Date: 2002-01-25 Member: 75Members, Retired Developer, NS1 Playtester, Constellation
    So, if I catch your meaning, you'd prefer Java to inserting the binary code manually, although not very much? ;P
  • GeminosityGeminosity :3 Join Date: 2003-09-08 Member: 20667Members
    Has Java even remotely got near the speed necessary to make a modern game with yet or is it still chugging along thanks to the whole api machine translation thingy which I forgot the proper term for like a year ago :s
  • TychoCelchuuuTychoCelchuuu Anememone Join Date: 2002-03-23 Member: 345Members
    <!--QuoteBegin-Geminosity+Mar 3 2005, 06:05 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Geminosity @ Mar 3 2005, 06:05 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> Has Java even remotely got near the speed necessary to make a modern game with yet or is it still chugging along thanks to the whole api machine translation thingy which I forgot the proper term for like a year ago :s <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd-->
    Yes.

    That is, you can make modern games in Java. Nobody does. But you can.
  • NEO_PhyteNEO_Phyte We need shirtgons&#33; Join Date: 2003-12-16 Member: 24453Members, Constellation
    <!--QuoteBegin-TychoCelchuuu+Mar 3 2005, 08:33 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (TychoCelchuuu @ Mar 3 2005, 08:33 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> <!--QuoteBegin-Geminosity+Mar 3 2005, 06:05 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Geminosity @ Mar 3 2005, 06:05 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> Has Java even remotely got near the speed necessary to make a modern game with yet or is it still chugging along thanks to the whole api machine translation thingy which I forgot the proper term for like a year ago :s <!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd-->
    Yes.

    That is, you can make modern games in Java. Nobody does. But you can. <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd-->
    im pretty sure someone here made a java-based multiplayer FPS.

    not sure if the language was java though...
  • DOOManiacDOOManiac Worst. Critic. Ever. Join Date: 2002-04-17 Member: 462Members, NS1 Playtester
    edited March 2005
    <!--QuoteBegin-Geminosity+Mar 3 2005, 08:05 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Geminosity @ Mar 3 2005, 08:05 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> Has Java even remotely got near the speed necessary to make a modern game with yet or is it still chugging along thanks to the whole api machine translation thingy which I forgot the proper term for like a year ago :s <!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd-->
    Once again this falls under the category of 'the right tool for the right job'.

    For a modern 3D game that requires squeezing every tiny bit of performance out of 3D cards, only a fool would even consider Java for the task. By the very core design of the language, it will never ever be ideal for this task.

    However, if you're writing a 2.5D (DOOM, Duke3D) or sprite based game for say a cell phone, Java is ideal. You can be sure it is going to work on everybody's phone that supports Java. And you can code fast. I have a friend at school who wrote a Wolf3D equivilant (minus sound, but that's easy too) engine that runs at 10-15fps w/o any optimizations over the weekend.

    However, when it comes to game development languages aren't all-or-nothing. Many games will use C++ for the core engine, but another language for other areas. Many games, especially RPGs, will use Python, Java, or even Pascal for their cutscene/dialog scripting. Vampire: The Masquerade (the first one, Redemption) used Java I believe, whereas Bloodlines uses Python. Unreal engine uses their own language, called UnrealScript, which is very Java-like.


    I hope I'm not coming off as a know-it-all or anything. Someone else give a dissenting opinion :P
  • CabooseCaboose title = name(self, handle) Join Date: 2003-02-15 Member: 13597Members, Constellation
    The language could be used for high end game programing, if the code was compiled into machine code insted of byte code couldn't it. I mean, things like borlands jbuilder of visual J# compile java into native binaries, why not?

    Or am I completly wrong here?
  • DOOManiacDOOManiac Worst. Critic. Ever. Join Date: 2002-04-17 Member: 462Members, NS1 Playtester
    Perhaps, but it still wouldn't be the ideal choice. Due to the very high level OOP encapsulation and etc. Java has a lot of overhead (at least for a 3d engine).

    You can do full polygonal 3d engines in java. you can do shaders and whatever if you set your heart to it. and you could even write your own Java compiler that compiled it to x86 Win32/Linux code if you really really wanted. However it still wouldn't be as optimized for the task as C++, and you'd spend a lot of dev time (and hence, money) in the process. But again, remember, I'm only talking about bleeding-edge technology in this case. DOOM3, Source, UnrealEngine3 type stuff.
  • NarfwakNarfwak Join Date: 2002-11-02 Member: 5258Members, Super Administrators, Forum Admins, NS1 Playtester, Playtest Lead, Forum Moderators, Constellation, NS2 Playtester, Squad Five Blue, Reinforced - Supporter, Reinforced - Silver, Reinforced - Gold, Reinforced - Diamond, Reinforced - Shadow, Subnautica PT Lead, NS2 Community Developer
    At least your Intro to Programming class isn't in Scheme.

    God, I hate this department.
  • ZeroByteZeroByte Join Date: 2002-11-01 Member: 3057Members
    <!--QuoteBegin-TychoCelchuuu+Mar 4 2005, 10:33 AM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (TychoCelchuuu @ Mar 4 2005, 10:33 AM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> <!--QuoteBegin-Geminosity+Mar 3 2005, 06:05 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Geminosity @ Mar 3 2005, 06:05 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> Has Java even remotely got near the speed necessary to make a modern game with yet or is it still chugging along thanks to the whole api machine translation thingy which I forgot the proper term for like a year ago :s <!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd-->
    Yes.

    That is, you can make modern games in Java. Nobody does. But you can. <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd-->
    Puzzle Pirates is programmed in Java and it could be considered as a modern game.

    I haven't really touched Java in a year or so. My impressions of it when I was using it though was that it's really great for learning OOP concepts, since as DOOMeh said, OOP isn't really optional in Java.
  • SoulSkorpionSoulSkorpion Join Date: 2002-04-12 Member: 423Members
    Part of Java's overhead comes from the way it does certain OO things. In the interests of making life easier for <s>mediocre</s> programmers it makes certain decisions about how to accomplish things rather than let the programmer decide, and doesn't let you have any say in the matter.

    For example, the elements of the language that support polymorphic inheritence are <i>always</i> enabled. Method are <i>always</i> called dynamically, regardless of whether or not they really need to be (the C++ equivalent would add the <span style='font-family:Courier'>virtual</span> keyword to every single member function indisicriminately). In addition, objects are <i>always</i> referred to by reference variables to facilitate dynamic type identification (whereas in C++ you can have objects on the stack, just like ordinary variables).

    You may have guessed, but I don't like Java. To me, the language itself seems to be just a dialect of C++ (but with half the vocabulary), designed for people who find choice confusing and distracting. It's not good practise to write code in which the modules are too heavily dependent on <i>each other</i>, never mind platform or API, besides the fact that Java isn't the only language which can do <a href='http://www.libsdl.org/' target='_blank'>platform independence</a>.

    Of course this is all entirely pointless, since in the real world one uses not even necessarily the right tool for the job, but whatever tool one's boss tells them to use.
  • antichristantichrist Join Date: 2003-05-27 Member: 16769Members
    Will someone please think of the children!! use C#!! <!--emo&;)--><img src='http://www.unknownworlds.com/forums/html/emoticons/wink-fix.gif' border='0' style='vertical-align:middle' alt='wink-fix.gif' /><!--endemo-->
  • GwahirGwahir Join Date: 2002-04-24 Member: 513Members, Constellation
    if I had to choose between C# and Java, I'd choose C#, definitely. It at least gives you the option of going into unsafe mode and have that power if you want it.
  • moultanomoultano Creator of ns_shiva. Join Date: 2002-12-14 Member: 10806Members, NS1 Playtester, Contributor, Constellation, NS2 Playtester, Squad Five Blue, Reinforced - Shadow, WC 2013 - Gold, NS2 Community Developer, Pistachionauts
    <!--QuoteBegin-SoulSkorpion+Mar 4 2005, 03:36 AM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (SoulSkorpion @ Mar 4 2005, 03:36 AM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> Part of Java's overhead comes from the way it does certain OO things. In the interests of making life easier for <s>mediocre</s> programmers it makes certain decisions about how to accomplish things rather than let the programmer decide, and doesn't let you have any say in the matter.

    For example, the elements of the language that support polymorphic inheritence are <i>always</i> enabled. Method are <i>always</i> called dynamically, regardless of whether or not they really need to be (the C++ equivalent would add the <span style='font-family:Courier'>virtual</span> keyword to every single member function indisicriminately). In addition, objects are <i>always</i> referred to by reference variables to facilitate dynamic type identification (whereas in C++ you can have objects on the stack, just like ordinary variables).

    You may have guessed, but I don't like Java. To me, the language itself seems to be just a dialect of C++ (but with half the vocabulary), designed for people who find choice confusing and distracting. It's not good practise to write code in which the modules are too heavily dependent on <i>each other</i>, never mind platform or API, besides the fact that Java isn't the only language which can do <a href='http://www.libsdl.org/' target='_blank'>platform independence</a>.

    Of course this is all entirely pointless, since in the real world one uses not even necessarily the right tool for the job, but whatever tool one's boss tells them to use. <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd-->
    Personally, I think most of the things Java removes from C++ are just bad programming practices. Granted, I would like to be able to make convenient bit masks without having to deal with character sets, but C++ lets you do some really heinous ****. I cut my teeth on C, and every time I see an object on the stack, or an object as a return value, some part of me dies. If it can't fit into %eax its not a return value dammit!

    For me, if I'm doing io or anything that requires touching raw bytes, I use pure ansi C. If the code is more data structure driven and won't have to do much io, I use java. The biggest thing Java has over C++ is decent type checking. Its not ML, but it cuts down on programming time quite a bit, particularly if you are coding while tired.
    (btw, if you ever have a chance to learn SML of NJ, check it out. Functional programming is a **** to wrap your head around if you aren't soaked in recursion, but its a wonderful feeling barely having to test your code, because you can look at it, and it proves its own correctness in front of you.)
Sign In or Register to comment.