Simple java test

Discussion in 'Java' started by Howard Brazee, Jan 31, 2007.

  1. What is the easiest way someone learning Java can run short little
    test programs?

    (I don't want to create JBuilder projects with libraries all over the
    place for someone who is just wanting to learn)
    Howard Brazee, Jan 31, 2007
    #1
    1. Advertising

  2. Howard Brazee

    Alex Hunsley Guest

    Howard Brazee wrote:
    > What is the easiest way someone learning Java can run short little
    > test programs?
    >
    > (I don't want to create JBuilder projects with libraries all over the
    > place for someone who is just wanting to learn)


    This is a good question to ask and for a reason: do it the simply and
    straightforwards way. Forget IDEs (as you are indicating you want to
    do). If you work with the command line to begin with, you get a feel for
    what goes on 'under the hood', what is really happening.

    Simplest possible way:
    Ensure you have Java installed on your system, and the bin/ directory
    for Java is on your path.
    open a command prompt. CD into a directory containing a java source file
    (e.g. HelloWorld.java).
    Compile like so:

    javac HelloWorld.java

    This creates a HelloWorld.class file.
    Run this like so:

    java -cp . HelloWorld

    (Note: there's no class at the end in above command!)
    NB: this assumes your HelloWorld class doesn't have a package statement
    in it - i.e. the class is in the 'default' package.
    lex
    Alex Hunsley, Jan 31, 2007
    #2
    1. Advertising

  3. Howard Brazee

    Oliver Wong Guest

    "Howard Brazee" <> wrote in message
    news:...
    > What is the easiest way someone learning Java can run short little
    > test programs?
    >
    > (I don't want to create JBuilder projects with libraries all over the
    > place for someone who is just wanting to learn)


    There's this web game called "Javala" which gives you Java problems for
    you to solve. You solve them by typing actual Java code which gets
    interpreted on the server side. Presumably, the server side then runs some
    unit tests on the provided code to test if you managed to solve the problem.

    Anyway, you can just ignore the problem and type whatever code you want,
    if you're in a situation where you have access to a web browser, but no JVM
    (the website uses JavaScript and the rest is serverside, so you don't even
    need the JRE to use it), but need to test some small snippet of Java code.

    http://javala.cs.tut.fi/en/top10.do

    - Oliver
    Oliver Wong, Jan 31, 2007
    #3
  4. Howard Brazee

    Hal Rosser Guest

    "Howard Brazee" <> wrote in message
    news:...
    > What is the easiest way someone learning Java can run short little
    > test programs?
    >
    > (I don't want to create JBuilder projects with libraries all over the
    > place for someone who is just wanting to learn)


    A Minimal IDE like "JGrasp" makes the learning experience go smoothly
    without getting all bogged down in learning something like Netbeans or
    Eclipse. It sort of a text editor that lets you step through your code to
    debug it.
    Some prefer to work from the command line, but JGrasp is a good compromise.
    Hal Rosser, Feb 1, 2007
    #4
  5. Howard Brazee

    Alex Hunsley Guest

    Hal Rosser wrote:
    > "Howard Brazee" <> wrote in message
    > news:...
    >> What is the easiest way someone learning Java can run short little
    >> test programs?
    >>
    >> (I don't want to create JBuilder projects with libraries all over the
    >> place for someone who is just wanting to learn)

    >
    > A Minimal IDE like "JGrasp" makes the learning experience go smoothly
    > without getting all bogged down in learning something like Netbeans or
    > Eclipse. It sort of a text editor that lets you step through your code to
    > debug it.
    > Some prefer to work from the command line, but JGrasp is a good compromise.


    I think a lot of people recommend trying the command line as a learning
    experience (me included) - but I don't really like working with it a
    lot, there are tools that are helpful, now that I know what goes on
    under the bonnet.
    Alex Hunsley, Feb 1, 2007
    #5
  6. On Wed, 31 Jan 2007 19:41:58 -0500, "Hal Rosser"
    <> wrote:

    >A Minimal IDE like "JGrasp" makes the learning experience go smoothly
    >without getting all bogged down in learning something like Netbeans or
    >Eclipse. It sort of a text editor that lets you step through your code to
    >debug it.
    >Some prefer to work from the command line, but JGrasp is a good compromise.


    That seems like a useful solution. I installed it on my computer and
    told it not to change any actions (so JBuilder would continue as it
    is).

    I tried the applet in chapter two of _Java and JavaScript Programming_
    by Peter Wayner, and was able to compile it into the same directory as
    the .java file. That chapter said to use a browser to run it. But
    it has a System.out.println(message); in it. Firefox says "Applet
    Kids started". I would rather not run Resin in this exercise and
    don't know if it would help. Is there a different setting that I
    need if we are to use this book's examples?

    Here's the code:
    kids.html:
    <HTML>
    <HEAD>
    <TITLE>Kids Title</TITLE>
    </HEAD>
    <BODY>
    <h1>Kids Header</h1>
    <hr>
    <applet code="Kids.class" width=200 height=200>
    </applet>
    </BODY>
    </HTML>
    =================================
    Kids.java:
    import java.applet.Applet;

    public class Kids extends Applet {
    int boredomFactor = 3;
    // how long until they quit.
    String message = "";
    // What they normally say
    String quitMessage = "";
    // What they say when they quit
    public void MyTurn(Kids WhozNext){
    if (boredomFactor-- <= 0){
    System.out.println(quitMessage);
    }
    else {
    System.out.println(message);
    WhozNext.MyTurn(this);
    }
    }

    public void init(){
    Kids Bobby, Kenny;
    Bobby = new Kids ();
    Bobby.message = "Kenny, you did it.";
    Bobby.boredomFactor = 4;
    Bobby.quitMessage="Fine.";
    Kenny = new Kids();
    Kenny.message="Bobby, you did it.";
    Kenny.quitMessage="Fine";
    Kenny.MyTurn(Bobby);
    }
    // public static void main(String[] args){
    // System.out.println("testing Kids");
    // }
    }
    Howard Brazee, Feb 1, 2007
    #6
  7. Howard Brazee

    Daniel Pitts Guest

    On Jan 31, 2:56 pm, "Oliver Wong" <> wrote:
    > "Howard Brazee" <> wrote in message
    >
    > news:...
    >
    > > What is the easiest way someone learning Java can run short little
    > > test programs?

    >
    > > (I don't want to create JBuilder projects with libraries all over the
    > > place for someone who is just wanting to learn)

    >
    > There's this web game called "Javala" which gives you Java problems for
    > you to solve. You solve them by typing actual Java code which gets
    > interpreted on the server side. Presumably, the server side then runs some
    > unit tests on the provided code to test if you managed to solve the problem.
    >
    > Anyway, you can just ignore the problem and type whatever code you want,
    > if you're in a situation where you have access to a web browser, but no JVM
    > (the website uses JavaScript and the rest is serverside, so you don't even
    > need the JRE to use it), but need to test some small snippet of Java code.
    >
    > http://javala.cs.tut.fi/en/top10.do
    >
    > - Oliver


    I had fun with javala.
    When I tried it, you couldn't solve the i.o. problems... Unless you
    were tricky (like I was)

    For a long time, I was the only one with a score above 94.
    Now a lot of people have 100. I guess they fixed Dewey,Huey,Louie
    (the string tokenizer problem)
    Daniel Pitts, Feb 1, 2007
    #7
  8. Howard Brazee

    Oliver Wong Guest

    "Howard Brazee" <> wrote in message
    news:...
    >
    > I tried the applet in chapter two of _Java and JavaScript Programming_
    > by Peter Wayner, and was able to compile it into the same directory as
    > the .java file. That chapter said to use a browser to run it. But
    > it has a System.out.println(message); in it. Firefox says "Applet
    > Kids started". I would rather not run Resin in this exercise and
    > don't know if it would help. Is there a different setting that I
    > need if we are to use this book's examples?
    >
    > Here's the code:
    > kids.html:
    > <HTML>
    > <HEAD>
    > <TITLE>Kids Title</TITLE>
    > </HEAD>
    > <BODY>
    > <h1>Kids Header</h1>
    > <hr>
    > <applet code="Kids.class" width=200 height=200>
    > </applet>
    > </BODY>
    > </HTML>
    > =================================
    > Kids.java:
    > import java.applet.Applet;
    >
    > public class Kids extends Applet {
    > int boredomFactor = 3;
    > // how long until they quit.
    > String message = "";
    > // What they normally say
    > String quitMessage = "";
    > // What they say when they quit
    > public void MyTurn(Kids WhozNext){
    > if (boredomFactor-- <= 0){
    > System.out.println(quitMessage);
    > }
    > else {
    > System.out.println(message);
    > WhozNext.MyTurn(this);
    > }
    > }
    >
    > public void init(){
    > Kids Bobby, Kenny;
    > Bobby = new Kids ();
    > Bobby.message = "Kenny, you did it.";
    > Bobby.boredomFactor = 4;
    > Bobby.quitMessage="Fine.";
    > Kenny = new Kids();
    > Kenny.message="Bobby, you did it.";
    > Kenny.quitMessage="Fine";
    > Kenny.MyTurn(Bobby);
    > }
    > // public static void main(String[] args){
    > // System.out.println("testing Kids");
    > // }
    > }


    I don't know why this program was coded as an applet instead of as an
    application. The messages sent via System.out.println() should show up in
    the Java console, though.

    - Oliver
    Oliver Wong, Feb 1, 2007
    #8
  9. I found the println output for that applet (without JBuilder nor Resin
    running)

    It is in C:\Documents and Settings\brazee\Application
    Data\Sun\Java\Deployment\log\plugin150_10.trace

    I wonder if that can be set to somewhere else.
    Howard Brazee, Feb 1, 2007
    #9
  10. On Thu, 1 Feb 2007 15:59:30 -0500, "Oliver Wong"
    <> wrote:

    >I don't know why this program was coded as an applet instead of as an
    >application.


    I guess the author was only concerned with web access.

    >The messages sent via System.out.println() should show up in
    >the Java console, though.


    What Java console? I was running it from a browser. If there's a
    setting to redirect it that output, I'd like to know how to do so.

    I figured they were in a log file somewhere - my past experience with
    log files was that they can be moved around - depending on whether I
    used Resin or just JBuilder. So I did a Windows search for files
    with my desired output and finally found the log file.

    When we do this, I'll have our work directory with a shortcut to that
    log directory. The book did not even indicate that the output
    wouldn't be immediately visible.
    Howard Brazee, Feb 1, 2007
    #10
  11. Howard Brazee

    Oliver Wong Guest

    "Howard Brazee" <> wrote in message
    news:...
    > On Thu, 1 Feb 2007 15:59:30 -0500, "Oliver Wong"
    > <> wrote:
    >
    >>I don't know why this program was coded as an applet instead of as an
    >>application.

    >
    > I guess the author was only concerned with web access.
    >
    >>The messages sent via System.out.println() should show up in
    >>the Java console, though.

    >
    > What Java console? I was running it from a browser. If there's a
    > setting to redirect it that output, I'd like to know how to do so.


    See http://mindprod.com/jgloss/console.html

    - Oliver
    Oliver Wong, Feb 1, 2007
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sting
    Replies:
    5
    Views:
    1,607
    Natty Gur
    Jun 8, 2004
  2. Robert Allan Schwartz
    Replies:
    7
    Views:
    364
    Marco Manfredini
    Aug 13, 2004
  3. Chris
    Replies:
    1
    Views:
    658
    Chris
    May 11, 2006
  4. Edvard Majakari
    Replies:
    4
    Views:
    673
    Edvard Majakari
    Feb 25, 2005
  5. Skybuck Flying

    Call oddities: &Test() vs &Test vs Test

    Skybuck Flying, Oct 4, 2009, in forum: C Programming
    Replies:
    1
    Views:
    681
    Skybuck Flying
    Oct 4, 2009
Loading...

Share This Page