View Full Version : Java I\O
Xterria
11-10-2001, 02:40 PM
ok, all this talk about C# is making me hungry for Java. Does any body know how to do a Hello World progam in Java? It's a console Application. So far I have this:
public class Class1
{
public static void main (String[] args)
{
//Whats the code for output?
}
}
thanks.
Troll_King
11-10-2001, 03:31 PM
.
Xterria
11-10-2001, 03:48 PM
thanks, but what about input?
Xterria
11-10-2001, 11:51 PM
input? anybody?
class Class1
{
int input; //for the input
public static void main(String args[])
{
//System.in.WHAT?
}
}
Unregistered
11-11-2001, 08:08 PM
The answer to your question is not simple.
Unlike C++ where you can go:
cout << "Hello World" << endl;
Java I/O is not simple. Why? Many reason.
I suggest you pick up a college level text and look at examples.
Xterria
11-11-2001, 08:34 PM
with
cout << "Hello World!" << endl;
you can go
System.out.println("Hello World!\n");
looks simple to me.
CuriousJay
11-12-2001, 06:01 PM
Haven't done java for a couple years.. but I believe it's
var = System.in.read();
If I'm wrong.. I wouldn't be surprised, as that's off the top of my head..
Xterria
11-12-2001, 06:59 PM
thanks, but it still isn't working :(
Try this -
import java.io.*;
class test {
public static void main( String[] args ) {
try{
BufferedReader stdin =new BufferedReader(new
InputStreamReader(System.in));
String a = new String();
a=stdin.readLine();
System.out.print(a);
}
catch(IOException e) {
System.out.println("IO Exception");
}
}
}
steven_g
11-13-2001, 05:09 PM
class ReadChar
{
public static void main(String[] args)
throws java.io.IOException
{
char c;
System.out.println("Hit a Key and press enter"):
c = (char)System.in.read();
System.out.println("You typed " + c);
}
}
Xterria
11-13-2001, 07:17 PM
yes! thank you!!!
quzah
11-14-2001, 05:59 PM
How here wants a Java board? (I do.) Face it, C# is just as much C as Java is. They both share similar "C" syntax, but aside from that, they aren't C.
That being the case, a Java board would do nicely. :)
Quzah.
Xterria
11-14-2001, 09:15 PM
I'm with you.
Fordy
11-21-2001, 06:55 PM
He he...
I've had my fingers burned here before for promoting Java......No one took much notice......
If you want a good resourse try JavaRanch (http://www.javaranch.com/cgi-bin/ubb/Ultimate.cgi). They have a board bigger than us and you will find whatever you may need there.........
Just be carefull....they can be touchy about stuff like names.....If you go on as a one word alias they get snooty.......
Excellent info though....
If you wanted to do this in an applet, the simplest form, no color, no nada, just text, here is the source code:
/** - documented comments, if you haven't heard of these, you can just use /* and */
AppHW.java - Main source code.
AppHW - Hello World! for a Java applet
Programmer: Sean Mackrory
*/
import java.applet.Applet
class AppHW
{
public void init()
{
Label HW = new Label("Hello World!");
add(HW);
};
}
vBulletin® v3.7.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.