Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

pixelbaker

macrumors member
Original poster
Aug 21, 2006
72
0
I'm in an application development class learning the very basics of java. I've been using TextMate for my coding purposes, but now my simple apps need to be able to request input in a command line form and then return results based on it.

I can compile and run, but it won't request that info and then keep running.

Somebody said that I need to just run it through the command line and I was hoping to do that, but I'm not really sure how. I also compile quite often and it would be nice to have a shortcut key to do it

Is there some other editor that has this functionality? I don't mind Eclipse/NetBeans/XCode but they seem like overkill for the stuff I'm doing.

Thanks in advance
 

Cromulent

macrumors 604
Oct 2, 2006
6,810
1,100
The Land of Hope and Glory
Just use the Terminal to execute your program. You will obviously need to write your program to take input from the standard input and the write and information you need back to the standard output. If you are having problems with the program not continuing to run then you need to rethink how you have written your program.

Not sure how to do it in Java but it should be similar to C.
 

pixelbaker

macrumors member
Original poster
Aug 21, 2006
72
0
:( my problem is that I don't know how to execute it it the Terminal. and I would like to be able to somehow compile and execute in the terminal with a keyboard shortcut from my text editor eventually.
 

toddburch

macrumors 6502a
Dec 4, 2006
748
0
Katy, Texas
To execute a java app in Terminal, just be sure you are in the folder where the .class file exists, for example, mytest.class, and then type

java mytest

That's pretty much all there is to it, from a basics standpoint.

Todd
 

toddburch

macrumors 6502a
Dec 4, 2006
748
0
Katy, Texas
And, after you type the javac command once, and the java mytest command once, you can use the command stack in Terminal (you can recall previously entered commands) by using the up and down arrow keys.

It's pretty fast.

Todd
 

Mernak

macrumors 6502
Apr 9, 2006
435
16
Kirkland, WA
if you can compile and run it, but don't get an input prompt, it sounds like your reader is messed up, here is my example code to do that
Code:
BufferedReader in = new BufferedReader( new InputStreamReader(System.in) );
System.out.printf("Enter some text: ");
String message = in.readLine();
and just use the normal javac and java to compile and run the program from the terminal.

P.S. JJEdit looks perfect for what you are doing.
P.P.S. it seems to have the same bug that netBeans has when requesting info, doesn't display the text of what you should input first, plus various other annoyances.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.