
@anchor{J.T.W. tarball}
@cindex A tarball to get you started
@cindex TT(~/jtw-tutorials)

BO(Question 4.1.1: Some code to get you started.)  First, please visit
the following Website
WEBSITE(http://davin.50webs.com/J.T.W/download-links.html) for the
programs that you need to have installed before you can do any coding
in J.T.W.  You should then download a tarball (also known as a
EM(compressed archive file)):
WEBSITE(http://davinpearson.com/binaries/java-training-wheels-1.1.tar.gz)
containing the code you need to get started. Then unzip the tarball
and change directory to TT(java-training-wheels) and issue the
following command on GNU/Linux systems: TT(./configure) or on MS
Windows systems: TT(bash configure).  If you are using
EM(M.S. Windows) and your TT(HOME) variable is unset, then you will
need to set it to a sensible value.  Examples of sensible values for
your TT(HOME) variable include, TT(c:\) or TT(c:\home) or TT(d:\home)
if your TT(d) drive is a hard drive.  To set the TT(HOME) variable in
windows, press BO(Windows E) and right click on EM(My Computer)
(Windows XP) or EM(This Computer) (Windows 10) and click on
EM(Properties), then click on EM(Advanced system settings), then click
on EM(Advanced), then click on EM(New) environment variable to set the
TT(HOME) variable.

@cindex Installing Davin's version of Emacs TT(dlisp.tar.gz)
@cindex Davin's version of Emacs TT(dlisp.tar.gz)
@cindex TT(dlisp.tar.gz), Davin's version of GNU Emacs
@cindex Installing Davin's TT(jtw-mode)
@cindex Davin's TT(jtw-mode.el), a major mode for editing *.jtw files
@cindex TT(jtw-mode.el) Davin's major mode for editing *.jtw files

When you run the TT(configure) script you will be prompted for the
location of prefix directory and the location of the place to keep
your TT(*.jtw) files.  You will also be asked if you want to install
just Davin's TT(jtw-mode) or Davin's full version of Emacs.

RED(BO(NOTE:)) If are reading this file on your local filesystem then
you would have already completed this question.

@cindex My first program
@cindex Your first program
@cindex Your first J.T.W. program
@cindex ``Hello, World!''
@cindex Hello, World!

BO(Question 4.1.2: Your first J.T.W. program.) Traditionally in
computer science the first program that you write in any programming
language is a program that does nothing else but prints out "Hello,
World". The following code does just that. In the following code, note
the use of the CLASS construct. In Java and J.T.W., every piece of
program code that does some real computational work resides in a CLASS
of some description.

m4_define(PD,@tie{})

@example
CLASS MyFirstProgram
BEGIN
PD BEGINMAIN
PD PD System.out.println("Hello, World!");
PD ENDMAIN
END
@end example

@cindex TT(make build X.run) to build and run a CLASS file.
@cindex Building code that uses a CLASS

The code for any CLASS TT(X) in these tutorials should reside in a
file called TT(X.jtw). Therefore the above code should be put into a
file called TT(MyFirstProgram.jtw). If two classes TT(X) and TT(Y) use
each other and TT(X) contains the MAIN FUNCTION then it is convenient
to place them both in a file called TT(X.jtw). To build and run some
code, you first need to be in the TT(~/jtw-tutorials) folder and
secondly you need to issue the following shell command: TT(make X.run)
where TT(X) is the name of the CLASS that you want to run, so it is

@center TT(make GRN(MyFirstProgram.run))

in this case.  For all the questions that follow this one, it will be
assumed that you know how to do this. See @ref{How to build a
collection of class files or an entire package} for more information
about building classes that use other classes in different files or
building entire packages.

BO(Question 4.1.3: Multiple calls to TT(System.out.println())). Change
the above code from printing the string "Hello, World!" to printing
out the following messages. Please note that it will be easiest to use
multiple calls to TT(System.out.println()) which sends text to the
screen for the purpose of viewing.

@cindex TT(System.out.println(/* args */);)

@example[
Hello, Anne! How are you doing?
Hello, Brian! How are you doing?
Hello, Clare! How are you doing?]
@end example

BO(Question 4.1.4: Functions,parameters and arguments.)  A FUNCTION is
a piece of code that does some computational work and optionally
returns a value. Notice how the TT(hello) FUNCTION below takes a value
of whose name to say hello to. This value who is called a
parameter. The values passed to the parameter by the call to the
FUNCTION is called an argument. For the purposes of this question, add
two more calls to the hello FUNCTION in the MAIN FUNCTION to get the
same result as the code for the previous question. The keyword
TT(void) indicates that this FUNCTION does not return a value. See the
next question for a FUNCTION that does return a value.

@cindex Functions, parameters and arguments

@example
CLASS MySecondProgram
BEGIN
PD FUNCTION VOID hello(String who)
PD BEGIN
PD PD System.out.println("Hello " + who + ", how are you doing?");
PD END
PD BEGINMAIN
PD PD hello("Anne");
PD ENDMAIN
END
@end example

BO(Question 4.1.5: Return values.)  Notice how the following TT(hello)
FUNCTION returns a string rather than printing out the string. Add two
more calls to the TT(hello) FUNCTION below to get the same result as
for Question 4.1.4.

@cindex Return values

@example
CLASS MyThirdProgram
BEGIN
PD FUNCTION String hello(String who)
PD BEGIN
PD PD return "Hello " + who + ", how are you doing?";
PD END
PD BEGINMAIN
PD PD System.out.println(hello("Anne"));
PD ENDMAIN
END
@end example

BO(Question 4.1.6: Ignoring return values.)  In J.T.W. and Java, it is
not necessary to use a value that is returned by a FUNCTION. Sometimes
this wastes computational resources since the value that is computed
by the FUNCTION is not used but other times when the FUNCTION whose
value is to be ignored does some additional work by setting the
value(s) of some variable(s) to different values then the FUNCTION
call is not a waste of resources. To ignore the value returned by the
hello FUNCTION, simply call the FUNCTION without using the value like
so: TT(hello("Ignored");) For the purposes of this question, try
calling the hello FUNCTION without using the return value by adding a
line of code to the MAIN FUNCTION.

@cindex Ignoring the return values of functions and methods.

BO(Question 4.1.7: Comments.)  Study the following code. Note the use
of comments. Comments are used to disable code for debugging purposes
and also to help explain how a program works. The most useful comment
in J.T.W. and Java is COMM(/** until the first */). This type of
comment is harvested by Javadoc to produce documentation on how a
CLASS works. The second and third most useful comments are
(respectively) COMM(// until the end of the line) and COMM(/* until
the first */). The third type of comment is not very useful because in
Java you are not allowed to have one comment inside another, so if you
use this type of comment you will constantly need to search for and
remove COMM(*/) closing comments. In the tutorials that follow you will see
many comments, although mainly the first and second types of comments.

@cindex Comments harvested by Javadoc
@cindex Javadoc, harvesting of comments

@example
COMM(/** This comment is harvested by Javadoc
PD PD to document the MyFourthProgram class */)
CLASS MyFourthProgram
BEGIN COMM(// I am a single line comment)
PD COMM(/* I am)
PD PD PD COMM(a multi-line)
PD PD PD PD PD COMM(comment */)
PD COMM(/** This comment is harvested by Javadoc)
PD PD PD COMM(to document the hello function */)
PD FUNCTION String hello(String who)
PD BEGIN
PD PD return "Hello " + who + ", how are you doing?";
PD END )
PD COMM(/** This comment is harvested by Javadoc)
PD PD PD COMM(to document the main function */)
PD BEGINMAIN
PD PD System.out.println(hello("Anne"));
PD ENDMAIN
END
@end example

