PDA

View Full Version : Tic Tac Toe java app




the_insider
May 5, 2006, 02:37 AM
Im taking a high school course in computer science, and one of my many projects is to program a simple tic tac toe program. It involves two players, who can play against each other, no A.I. or anything like that. I dont have alot of time left, and my current program just keeps spitting errors at me, so i was wondering if someone could write me a simple tic tac toe program in java just to help me get through my senior year. Lots of IB's to study for and lots of exams to pass over the next 2 weeks. Any help would be greatly appreciated.



bousozoku
May 5, 2006, 03:09 AM
We could help you fix the errors but it's dishonest to have someone else do your work for you.

jtalerico
May 5, 2006, 06:40 AM
Does this have to have a GUI? Or can it just be console?

Here are a few hints.
Use 2D array.. int[][] board = new int[3][3];
Then have a set method that takes in public void set(pos1, pos2, int)
Check to see if the incoming positions are valid
make sure the the int is not > 2. (you are storing 1 or 2 for X or O)
Now do a toString method that will print everything and if it is a 1 it will be X if it is a two it will be a O..

that would just be your Game class, you will also have a player class, but that should be a very easy class to write.

-joe

savar
May 5, 2006, 08:20 AM
Im taking a high school course in computer science, and one of my many projects is to program a simple tic tac toe program. It involves two players, who can play against each other, no A.I. or anything like that. I dont have alot of time left, and my current program just keeps spitting errors at me, so i was wondering if someone could write me a simple tic tac toe program in java just to help me get through my senior year. Lots of IB's to study for and lots of exams to pass over the next 2 weeks. Any help would be greatly appreciated.

F.C

What are you offering in return?

jtalerico
May 5, 2006, 09:36 AM
What are you offering in return?

A high five?? What are you expecting from this kid? :rolleyes:

savar
May 5, 2006, 12:28 PM
A high five?? What are you expecting from this kid? :rolleyes:

I would accept payment in the form of money, power, or fame.

Cheers

PS J/k I only take money

jtalerico
May 5, 2006, 12:29 PM
I basically told him how to do it. If he still cannot figure it out. Then he better pay you.

stadidas
May 5, 2006, 06:03 PM
I did a similar thing a few weeks ago, I'm in my first year of University. It didn't take long to do, it's really very simple.

Wes
May 6, 2006, 02:23 AM
If no GUI is required it's a pretty easy project. As a previous poster said use a 2d array of characters.

Then have an isWinner(char) method which goes across all rows and columns checking for a winner.

http://www.doc.ic.ac.uk/~sue/121/all-6up.pdf

Look on page 60 of the notes to get a lot of help about how to implement it.

Basically you need to do this sort of thing:

Init code
Loop while there is not a winnner {
print the board
read in move
while (entered move is not valid) {
read in another move
}
plot move on board
check for winner
}
print the board
print congratulatory message to correct player


edit: added printing the board haha

janey
May 7, 2006, 01:38 AM
I dont have alot of time left, and my current program just keeps spitting errors at me, so i was wondering if someone could write me a simple tic tac toe program in java...
academic dishonesty has worse-off consequences compared to turning in an assignment full of errors. Colleges really do not like accepting students with a past history of academic dishonesty, and teachers/professors don't write letters of recommendation for you if they know you cheat.

The hints given by other people in this thread are very good advice, I had a similar assignment (2 player tictactoe over a network) last semester and what Wes and jtalerico are pretty much similar to what I did.

You could of course post the errors and whatever you have so far in this post, and maybe we could help you fix it.

ReanimationLP
May 7, 2006, 04:38 AM
I would accept payment in the form of money, power, or fame.

Cheers

PS J/k I only take money

But you'd think Master Shake would want all 3 at the same time. :D

Seriously though, dont cheat. It could come back to haunt you down the road.

I dont recommend taking little snippets from others and gluing them together. You really never know when this kind of stuff can come back to bite you in your butt.

savar
May 7, 2006, 01:28 PM
But you'd think Master Shake would want all 3 at the same time. :D

Seriously though, dont cheat. It could come back to haunt you down the road.

I dont recommend taking little snippets from others and gluing them together. You really never know when this kind of stuff can come back to bite you in your butt.

Yeah, its only fair to add that there ARE programs which compare code and can measure various similarity metrics. It was developed primarily at Berkeley and is IN USE at most medium and large schools, and people do get caught plagarizing.

So if you turn in code you copied from somewhere else thinking, how would they ever know, you could get busted really easily. And changing names of variables and methods won't get you off the hook either.

weg
May 7, 2006, 02:59 PM
i was wondering if someone could write me a simple tic tac toe program in java just to help me get through my senior year.

Yeah.. I was wondering if somebody could write me a few papers and a thesis, just to help me to get my PhD... :eek:

jtalerico
May 7, 2006, 06:46 PM
Sure when do you need it by?

the_insider
May 10, 2006, 06:05 AM
alright. sorry i havnt checked this tread yet. ive been writing the program on JCreator, and i couldnt upload a .java file, so i copied it into word.. It would be nice to get some people to double check my program and correct any errors you can find.

thanks alot for all the help

jtalerico
May 10, 2006, 06:12 AM
alright. sorry i havnt checked this tread yet. ive been writing the program on JCreator, and i couldnt upload a .java file, so i copied it into word.. It would be nice to get some people to double check my program and correct any errors you can find.

thanks alot for all the help

Errors out on me... Right off bat. First number i click it errors, then i get a system.out.println...

000001000

If i click 9 I get...
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 9
at TicTacToe$MoveHandler.actionPerformed(TicTacToe.java:84)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
at java.awt.Component.processMouseEvent(Component.java:5488)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1774)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

jtalerico
May 10, 2006, 06:14 AM
Also forgot to mention that comments would be nice.

Wes
May 10, 2006, 06:16 AM
Also forgot to mention that comments would be nice.

I see a comment (line 27)...

//######

Makes perfect sense to me...

jtalerico
May 10, 2006, 06:20 AM
Sorry for posting like 10 times in the matter of minutes.. But look at your code and ask yourself. Does an array start from 0-8 or is it 1-9?

Also it seems that you did not take any of the advice we gave you. 2D array should look like int[][]

jtalerico
May 10, 2006, 06:20 AM
I see a comment (line 27)...

//######

Makes perfect sense to me...

Oh, i missed that... NOWWWW i understand... :rolleyes:

:) :) :)

Wes
May 10, 2006, 06:27 AM
For OP:

I could give the code a look on Saturday but I have final exams tomorrow and the day after so I can't look at in the interim.

the_insider
May 10, 2006, 06:35 AM
ok the //##### is a note to myself, where i have to work. What im trying to do there is store the moves, so that the game will know when one of the players have won.

and the //****

is where ive got another prob.. when i do get the program running, if i click on one box, it will change to an X, or an O, and if i click the same box, il get a pop up to tell the player that you have to click on another box. but after that instead of an X again, it will be an O or vice versa.
does that make any sense?

jtalerico
May 10, 2006, 06:43 AM
insider
Save yourself the headaces, rewrite the code with a 2D array. It will make things a lot easier on you...

static int[][] moves = new int[3][3];

the_insider
May 10, 2006, 06:44 AM
here i fixed the an error, it should run fine now.

jtalerico
May 10, 2006, 06:58 AM
To find a winner you want to go through the array and check if instance [0] is x [1] is x [2] is x. assuming your array is somehow setup like this...

0 1 2
3 4 5
6 7 8

reason wny 2D arrays are so much better is because you can break it up...

[0][0] [0][1] [0][2]
[1][0] [1][1] [1][2]
[2][0] [2][1] [2][2]

Your array is really setup like this...

[0][1][2][3][4][5][6][7][8]

That is why doing a 2D array would be better for like error checking because you could just do 3 for looks to check it out...

jtalerico
May 10, 2006, 08:33 AM
I realize this code could be sketchy... But you could modify it to work for you. I have it currently working and checking the top row to see if they are all the same...

static int[][] MoveHistory = new int[3][3];


static class MoveHandler implements ActionListener //######
{
public void actionPerformed(ActionEvent event)

{
String whichButton;
whichButton = event.getActionCommand();

if (whichButton.equals("1"))
{ one.setText(player);
if (player.equals ("x")) MoveHistory[0][0] = 1;
else MoveHistory[0][0] = 2;
}
this.check();
if (whichButton.equals("2"))
{ two.setText(player);
if (player.equals ("x")) MoveHistory[0][1] = 1;
else MoveHistory[0][1] = 2;
}
this.check();
if (whichButton.equals("3"))
{ three.setText(player);
if (player.equals ("x")) MoveHistory[0][2] = 1;
else MoveHistory[0][2] = 2;
}
this.check();
if (whichButton.equals("4"))
{ four.setText(player);
if (player.equals ("x")) MoveHistory[1][0] = 1;
else MoveHistory[1][0] = 2;
}
this.check();
if (whichButton.equals("5"))
{ five.setText(player);
if (player.equals ("x")) MoveHistory[1][1] = 1;
else MoveHistory[1][1] = 2;
}
this.check();
if (whichButton.equals("6"))
{ six.setText(player);
if (player.equals ("x")) MoveHistory[1][2] = 1;
else MoveHistory[1][2] = 2;
}
this.check();
if (whichButton.equals("7"))
{ seven.setText(player);
if (player.equals ("x")) MoveHistory[2][0] = 1;
else MoveHistory[2][0] = 2;
}
this.check();
if (whichButton.equals("8"))
{ eight.setText(player);
if (player.equals ("x")) MoveHistory[2][1] = 1;
else MoveHistory[2][1] = 2;
}
this.check();
if (whichButton.equals("9"))
{ nine.setText(player);
if (player.equals ("x")) MoveHistory[2][2] = 1;
else MoveHistory[2][2] = 2;
}
this.check();

nine.setText(player);

if (whichButton.equals("x"))
{ JOptionPane.showMessageDialog( null, "click again"); // ****
}
if (whichButton.equals("o"))
{ JOptionPane.showMessageDialog( null, "click again");
}




if (player == "o" )
player = "x";
else player = "o";
int x=0;
for (int a=0;a<3;a++)
System.out.print(MoveHistory[a][x]);
System.out.println();
x++;

}
public void check(){
for(int i=0; i<3; i++){
if(MoveHistory[i][0]==MoveHistory[i][1] && MoveHistory[i][1]==MoveHistory[i][2]){
if(MoveHistory[i][0] == 1){
JOptionPane.showMessageDialog(null, "X Wins");
break;
}
if(MoveHistory[i][0] == 2){
JOptionPane.showMessageDialog(null, "O Wins");
break;
}
}
}
}
}

the_insider
May 10, 2006, 09:22 AM
many thanks jtalerico. im working on it now

jtalerico
May 10, 2006, 09:29 AM
many thanks jtalerico. im working on it now

Sure thing. I might also suggest that you add a JMenuBar that has a newGame() method attached to it, and a exit() method.

MacMan93
May 10, 2006, 11:19 PM
This might be a little complex for your needs but look in:
yuor HD/Developer/Examples/Java/Applets/TicTacToe/

It uses graphical X and O's but I guess it should help you out a little. :)

the_insider
May 15, 2006, 04:07 AM
I managed to setup the check for rows, columns, and diagonals. I was wondering if anyone wanted to give me a few pointers, of what i could continue to add to this program.. maybe some simple GUI, or some A.I.. any ideas?

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

public class TicTacToe
{


static JFrame calcFrame;
static Container calcPane;
static MoveHandler operation;
static ClearHandler clearOperation;
static JButton one;
static JButton two;
static JButton three;
static JButton four;
static JButton five;
static JButton six;
static JButton seven;
static JButton eight;
static JButton nine;
static String player = "x";
static int[][] MoveHistory = new int[3][3];


static class MoveHandler implements ActionListener //######
{
public void actionPerformed(ActionEvent event)

{
String whichButton;
whichButton = event.getActionCommand();

if (whichButton.equals("1"))
{ one.setText(player);
if (player.equals ("x")) MoveHistory[0][0] = 1;
else MoveHistory[0][0] = 2;
}
this.check();
if (whichButton.equals("2"))
{ two.setText(player);
if (player.equals ("x")) MoveHistory[0][1] = 1;
else MoveHistory[0][1] = 2;
}
this.check();
if (whichButton.equals("3"))
{ three.setText(player);
if (player.equals ("x")) MoveHistory[0][2] = 1;
else MoveHistory[0][2] = 2;
}
this.check();
if (whichButton.equals("4"))
{ four.setText(player);
if (player.equals ("x")) MoveHistory[1][0] = 1;
else MoveHistory[1][0] = 2;
}
this.check();
if (whichButton.equals("5"))
{ five.setText(player);
if (player.equals ("x")) MoveHistory[1][1] = 1;
else MoveHistory[1][1] = 2;
}
this.check();
if (whichButton.equals("6"))
{ six.setText(player);
if (player.equals ("x")) MoveHistory[1][2] = 1;
else MoveHistory[1][2] = 2;
}
this.check();
if (whichButton.equals("7"))
{ seven.setText(player);
if (player.equals ("x")) MoveHistory[2][0] = 1;
else MoveHistory[2][0] = 2;
}
this.check();
if (whichButton.equals("8"))
{ eight.setText(player);
if (player.equals ("x")) MoveHistory[2][1] = 1;
else MoveHistory[2][1] = 2;
}
this.check();
if (whichButton.equals("9"))
{ nine.setText(player);
if (player.equals ("x")) MoveHistory[2][2] = 1;
else MoveHistory[2][2] = 2;
}
this.check();

nine.setText(player);

if (whichButton.equals("x"))
{ JOptionPane.showMessageDialog( null, "click again"); // ****
}
if (whichButton.equals("o"))
{ JOptionPane.showMessageDialog( null, "click again");
}




if (player == "o" )
player = "x";
else player = "o";
int x=0;
for (int a=0;a<3;a++)
System.out.print(MoveHistory[a][x]);
System.out.println();
x++;

}
public void check(){
for(int i=0; i<3; i++){
if(MoveHistory[i][0]==MoveHistory[i][1] && MoveHistory[i][1]==MoveHistory[i][2]){
if(MoveHistory[i][0] == 1){
JOptionPane.showMessageDialog(null, "X Wins");
break;
}
if(MoveHistory[i][0] == 2){
JOptionPane.showMessageDialog(null, "O Wins");
break;
}
}
}
}
}

static class ClearHandler implements ActionListener
{
public void actionPerformed(ActionEvent event)

{


}
}




public static void main(String[] args)
{
operation = new MoveHandler();
clearOperation = new ClearHandler();

one = new JButton("1");
two = new JButton("2");
three = new JButton("3");
four = new JButton("4");
five = new JButton("5");
six = new JButton("6");
seven = new JButton("7");
eight = new JButton("8");
nine = new JButton("9");

one.addActionListener(operation);
two.addActionListener(operation);
three.addActionListener(operation);
four.addActionListener(operation);
five.addActionListener(operation);
six.addActionListener(operation);
seven.addActionListener(operation);
eight.addActionListener(operation);
nine.addActionListener(operation);

calcFrame = new JFrame();
calcFrame.setSize(300,300);
calcFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
calcPane = calcFrame.getContentPane();
calcPane.setLayout (new GridLayout (3,3));
calcPane.add(one);
calcPane.add(two);
calcPane.add(three);
calcPane.add(four);
calcPane.add(five);
calcPane.add(six);
calcPane.add(seven);
calcPane.add(eight);
calcPane.add(nine);
calcFrame.setVisible(true);

}

}

Wes
May 15, 2006, 05:37 AM
Well it would be nice if it actually worked and didn't place a piece in the bottom right every time...

1. Make your check method a boolean so you can set a while loop to allow the game to play while there isn't a winner.

2. Your piece playing method was massive so I improved the algorithm. You want to take a number, one to nine, and then get two coordinates out of it. See attachment for chart.

For reference % is modulus (remainder) in java.




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

public class TicTacToe {
static JFrame calcFrame;
static Container calcPane;
static MoveHandler operation;
static JButton one;
static JButton two;
static JButton three;
static JButton four;
static JButton five;
static JButton six;
static JButton seven;
static JButton eight;
static JButton nine;
static String player = "x";
static int[][] MoveHistory = new int[3][3];
static JButton[] buttonarray;

public static void main(String[] args) {
operation = new MoveHandler();

buttonarray = new JButton[9];
one = new JButton("1");
two = new JButton("2");
three = new JButton("3");
four = new JButton("4");
five = new JButton("5");
six = new JButton("6");
seven = new JButton("7");
eight = new JButton("8");
nine = new JButton("9");

one.addActionListener(operation);
two.addActionListener(operation);
three.addActionListener(operation);
four.addActionListener(operation);
five.addActionListener(operation);
six.addActionListener(operation);
seven.addActionListener(operation);
eight.addActionListener(operation);
nine.addActionListener(operation);

buttonarray[0] = one;
buttonarray[1] = two;
buttonarray[2] = three;
buttonarray[3] = four;
buttonarray[4] = five;
buttonarray[5] = six;
buttonarray[6] = seven;
buttonarray[7] = eight;
buttonarray[8] = nine;

calcFrame = new JFrame();
calcFrame.setSize(300,300);
calcFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
calcPane = calcFrame.getContentPane();
calcPane.setLayout (new GridLayout (3,3));
calcPane.add(one);
calcPane.add(two);
calcPane.add(three);
calcPane.add(four);
calcPane.add(five);
calcPane.add(six);
calcPane.add(seven);
calcPane.add(eight);
calcPane.add(nine);
calcFrame.setVisible(true);
}



static class MoveHandler implements ActionListener {
public void actionPerformed(ActionEvent event) {
String whichButton;
whichButton = event.getActionCommand();
int pos = Integer.parseInt(whichButton)-1;
int x = pos/3;
int y = pos%3;
System.out.println(x + ", " + y);
if (player.equals ("x")) {
MoveHistory[x][y] = 1;
buttonarray[pos].setText("x");
player = "o";
} else {
MoveHistory[x][y] = 2;
buttonarray[pos].setText("o");
player = "x";
}
this.check();
}


public void check(){
for(int i=0; i<3; i++){
if(MoveHistory[i][0]==MoveHistory[i][1] && MoveHistory[i][1]==MoveHistory[i][2]){
if(MoveHistory[i][0] == 1){
JOptionPane.showMessageDialog(null, "X Wins");
break;
}
if(MoveHistory[i][0] == 2){
JOptionPane.showMessageDialog(null, "O Wins");
break;
}
}
}

}

}


}

Palad1
May 15, 2006, 07:02 AM
AS a rule of thumb, create an actionListener for each button, then refactor some code. Sharing actionlisteners gets ugly real fast.

From memory:
myButton.addActionListener(new ActionAdapter(){
public void actionPerformed(ActionEvent event){
myButton.setEnabled(false);
try{
DoStuff();
}finally{
myButton.setEnabled(true);
}
}
});

mbabauer
May 24, 2006, 10:28 PM
and the //****

is where ive got another prob..
You should REALLY consider commenting your code better. Read up on the usage of JavaDoc.

when i do get the program running, if i click on one box, it will change to an X, or an O, and if i click the same box, il get a pop up to tell the player that you have to click on another box. but after that instead of an X again, it will be an O or vice versa.
does that make any sense?

This makes sense as much as I can make sense of anyones totally uncomment brain dump. Without giving myself a migrain, I would have to say whatever code you have checking the move's validity is not halting the processing of the move. It seems to me that what you probably want to do instead is check for a valid move, throw an exception of some sort if its not, and catch it were you are doing the click, making sure you do not flip whatever bit that indicates who's move it is.

My next advice...get a decent IDE like Eclipse (man, I must have said this in 4 or 5 posts tonight). I can't STRESS enough how important a good IDE with a good debugger is. You can get Eclipse at www.eclipse.org.

Last, I can say that I am a Sun Certified Developer, and have been coding Java since 1.02 beta was released. My first experience with Java was in a collage class in 1995, and even the professor didn't know anything about this new language. Most of the class went like "Ok, how many thinks it works this way...ok, let try it...". So, bottom line is I have *some* experience, and I can say that several people have practically handed you the pseudo code for this...2-D array, my friend! It makes logical sense, makes the checks easier, and you don't have to keep track of anyone's moves since you have an array full of them.

Good luck

P.S. - Dont cheat. Cheaters suck, and in the end, who are you really hurting?

jtalerico
May 25, 2006, 07:44 AM
mbabauer -

Good call! You prefer IDEs? I do too, but it has been a recent topic/discussion on slashdot that CS people should not start off with IDE's but just have a text editor and then compile. What are you feelings on that? (I guess I could start a new thread, but it seems it could go here.

mbabauer
May 25, 2006, 12:50 PM
I do too, but it has been a recent topic/discussion on slashdot that CS people should not start off with IDE's but just have a text editor and then compile. What are you feelings on that?

I think the people who think that way either dont code for a living or are too "idealistic".

Lets put it another way...say you got interested in wood working and wanted to build a small table. Should you be forced to cut down a tree, plane and saw by hand, etc? Well, you could if you wanted to be all "hard-core" like the Yankee Workshop guy, but most wood workers would suggest you get some tools. A table saw, planer, etc.

The bottom line is this. When anyone is starting out, the point of all these tasks is to learn the concepts of programming, not the language. In my own teachings (I have done some on the side), I find the students get way too hung up on the symantics. I try to tell them to "Visualize the problem, and what steps to take to solve them", but instead I get questions about IOExceptions and classpaths.

It is totally up to you, really. I know developers that STILL to this day use only a text editor and a compiler. I also know people that cant do anything without an IDE. If you forgo all the bells and whistles of the IDE, like the GUI builders and wizzards, then really all you are left with is a decent text editor, which is really how I use an IDE anyway. What it DOES give you is things like a debugger (IMHO the most important thing a flegling developer should learn) and niceties like "Auto-complete" and syntax checking.

jeremy.king
May 25, 2006, 01:18 PM
I think the people who think that way either dont code for a living or are too "idealistic".

Lets put it another way...say you got interested in wood working and wanted to build a small table. Should you be forced to cut down a tree, plane and saw by hand, etc? Well, you could if you wanted to be all "hard-core" like the Yankee Workshop guy, but most wood workers would suggest you get some tools. A table saw, planer, etc.

The bottom line is this. When anyone is starting out, the point of all these tasks is to learn the concepts of programming, not the language. In my own teachings (I have done some on the side), I find the students get way too hung up on the symantics. I try to tell them to "Visualize the problem, and what steps to take to solve them", but instead I get questions about IOExceptions and classpaths.

It is totally up to you, really. I know developers that STILL to this day use only a text editor and a compiler. I also know people that cant do anything without an IDE. If you forgo all the bells and whistles of the IDE, like the GUI builders and wizzards, then really all you are left with is a decent text editor, which is really how I use an IDE anyway. What it DOES give you is things like a debugger (IMHO the most important thing a flegling developer should learn) and niceties like "Auto-complete" and syntax checking.

I disagree wholeheartedly. Learning the ins and outs of the Java environment is imperative to become a good Java programmer. Using your own experience, did you start with an IDE? Um I highly doubt it, since they really didn't even exist then.

Telling a beginner to use an IDE is like telling a 3rd grade math student to use a calculator instead of a pencil and paper - then later on in life they rely on the calculator and have no idea how to truly solve a math problem problem. Granted, I wouldn't consider writing a swing based tic tac toe app as a beginning task. A similar example is people who rely on a Word processor to teach them grammar or spelling - it seems just wrong. Or better yet, ever watch a young cashier try to make change without a register...Its funny...I digress...

It is my strong opinion that a java programmer must learn the basic concepts of javac, java, jdb, jar, javadoc, and other commands - not to mention the role of bytecode and the concept of a VM. Only after having a solid understanding of the role of those commands would I recommed and IDE so they can realize (and appreciate) how the IDE can make these tasks easier. But starting with an IDE will only lead to a more shallow understanding of Java (or any other language).

I do agree that if you can't solve problems in a systematic way, you won't get far programming in any language. Adding a dimension such as an IDE too early in the process of learning will simply cause distractions from truly learning the art of programming.

All that said, if you are just trying to get through an elective course and don't care to do programming ever again, go ahead...use an IDE.

Jedi128
May 25, 2006, 03:30 PM
This Tic Tac Toe thing must really be popular becuase for my post AP test time in my high school programming class we tried to build one of these apps (or applets) for fun. Mine ultimately does not work, but I tried to do a pure app and not an applet, which I think is harder. I have never used any of the swing or java.awt or java.awt.event stuff before so this was quite a challenge, especially being short on time. I just thought it was funny that I got the same project at the end of the year...

0s and 1s
May 25, 2006, 06:04 PM
Ah......memories.... :(

I remember doing this when I was a CS major.

Good luck. My TTT prog ended up looking like a Connect Four gameboard, but I somehow figured it out on the day it was due.....without any help!!! :cool:

mbabauer
May 25, 2006, 07:18 PM
I disagree wholeheartedly. Learning the ins and outs of the Java environment is imperative to become a good Java programmer. Using your own experience, did you start with an IDE? Um I highly doubt it, since they really didn't even exist then.

How is mistyping method and class names learning the Java language? I am by no means advocating the use of an GUI builder or auto-code generation tools like XDoclet and such. I am speaking directly to the ability to hit Ctrl-space and have a list of methods or class names pop up, or mousing over some code and getting a decent JavaDoc popup that explains what its trying to do.

Telling a beginner to use an IDE is like telling a 3rd grade math student to use a calculator instead of a pencil and paper - then later on in life they rely on the calculator and have no idea how to truly solve a math problem problem. Granted, I wouldn't consider writing a swing based tic tac toe app as a beginning task. A similar example is people who rely on a Word processor to teach them grammar or spelling - it seems just wrong. Or better yet, ever watch a young cashier try to make change without a register...Its funny...I digress...


I agree, but disagree. Again, I am not advocating the "Use a tool to write the code for you method", as you would see in something like Sun Forte or even MS Visual Basic (Drag-n-code), I am simply saying Notepad is NOT the way to go. What better way to learn that your code is screwed up than to have the editor underline it in red and an error at the bottom saying "ERROR: Cannot cast a int as a float"? Also, the context of the statement was for those learning to program, not those learning to be straight-up Java developers. My the time I took my first Java course, I had almost 2 years of coding in C and C++ under my belt. I had written an assembler and a C-- compiler, and was in a class called "Operating Systems", which surprisingly enough had us writting an OS from some crazy virtual machine. At this point, I knew what a linked list was, or that most languages referenced arrays from 0. I had the basics pretty much under my belt.


It is my strong opinion that a java programmer must learn the basic concepts of javac, java, jdb, jar, javadoc, and other commands - not to mention the role of bytecode and the concept of a VM. Only after having a solid understanding of the role of those commands would I recommed and IDE so they can realize (and appreciate) how the IDE can make these tasks easier. But starting with an IDE will only lead to a more shallow understanding of Java (or any other language).


Again, I have first-hand experience teaching people who have NEVER developed a single line of code in their lives, and I have seen first hand these people struggle with crap like classpaths and JAR files and symantic crap that really, in all honesty, has little to nothing to do with actual software development and more to do with the coding styles of the language developers. I have also seen how, when given just a rudimentary demo of an IDE (Basics, again not talking code generation and such), and taught just a tad bit of how to run a debugger, these people start to figure out problems on their own.

Using your argument, one would then be lead to thing that people should start coding in Assembler. Or, better yet, how about just handing them a Hex editor and make them write in machine code. At some point you have to abstract the languange for the user, let them figure out the logical thinking part, then throw the details back in. If they decide Java is the bee's knees, then let them take the Sun Certified Programmer test, which will sure enough test them on the usage of JAR files, class loaders, etc, etc.

Frankly, if one was going to take the approach of "learn the hard way", I would recommend starting in C, then work to C++, then Java. Thats what I did, and have come to know truely what a NullPointerException really is.


I do agree that if you can't solve problems in a systematic way, you won't get far programming in any language. Adding a dimension such as an IDE too early in the process of learning will simply cause distractions from truly learning the art of programming.


Some of the problems I mention COULD be solved by 4th and 5th generation languages that are not so reliant on the symantecs being right.


All that said, if you are just trying to get through an elective course and don't care to do programming ever again, go ahead...use an IDE.

One of the other things an IDE helps instill is a sense of "style". Style is one of my pet-pieves. I can't stand to see code where someone uses tabs in one place, spaces over there, etc. It would also help encourage good self documenting code, since it lays down the templates of the comments for you.


Obviously this is my $0.02 worth, and everyone is entitled to their opinion. My final point is this...if you plan to be a hard nosed developer, you should start with another language anyway. Java is a great language, but lets be honest...it lets you cut way too many corners. Memory management is one of the WORST problems I see in flegling code, and Java sorta skips right over all of that...at least until the point in which you see your very first OutOfMemoryException, that is.