![]() |
Up to 87% savings on Geeks.com!
SECRET CAMCORDER
Prices too low to show! Expires 8/31 Take 10% Off All MCM Electronics Purcases!
|
![]()
![]()
![]()
By Sergey Skudaev
Here you will learn how to install Java Development Kit, edit AUTOEXEC.BAT file, set PATH and CLASSPATH environment variables create java application, compile java source code and run java application.
1. Download Java Developer Kit J2SE 5.0 from http://java.sun.com/j2se/1.5.0/download.jsp
2. Download J2SE 5.0 Documentation from http://java.sun.com/j2se/1.5.0/download.jsp#docs
3. Set PATH, CLASSPATH and JAVA_HOME environment variables Environment Variables
On Windows 98, Me, edit AUTOEXEC.BAT file. Open it in notepad and add the following lines of text in bold
PATH=C:\WINDOWS;C:\WINDOWS\COMMAND;C:\j2sdk1.4.2_08\bin;
SET JAVA_HOME=C:\j2sdk1.4.2_08\bin;
SET CLASSPATH=.;C:\j2sdk1.4.2_08\classes;
The dot in class path indicates that Java class file generated after you compile java source code will be located in the same directory as *.java source files. The "classes" directory is not created during Java SDK installation. I created it later. You can create any directory for java classes wherever you like.
The "C:\j2sdk1.4.2_08\bin" path in my AUTOEXEC.BAT file points to J2SDK location on my PC. On your PC path to J2SDK and its version may be different. So use your path, not mine.
JAVA_HOME is not required to run java application, but it may be useful later if you decide to install Tomcat server to develop and run java application for web.
Windows 2000 or Windows XP do not use AUTOEXEC.BAT file. You have to create environment variables. Please read how to create environment variables tutorial.

In Windows XP on my PC I set the path environment variable for user and for system. Only then I could start javac.exe in command prompt from any directory
To test configuration on your PC, create a test directory on you C drive. Open Notepad or TextPad and copy the following Java code.
import java.lang.*;
public class greeting
{
public static void main(String[] args)
{
System.out.println("Hello Wolrd!");
}
}
Save file as greeting.java in the test directory. In Java language the source file name always must be the same as a public class name declared in the file.
Open command prompt. Usually, it is located in accessories menu. Command prompt displays a path to "Windows" directory (in windows 98, Me) or "C:\Documents and Settings\user>" directory, or some other directory.
Type cd and two dots cd.. and press enter.
Repeat the procedure until you get to root directory C:> Then type cd test and press enter.
You will get in C:\test> directory where your greeting.java file is located.
You can check it by typing C:\test>dir command. All files of test directory will be displayed.
Type C:\test>javac greeting.java and press enter. The source file will be compiled and greeting.class file appears in the test directory. If you mistype the code, errors will be displayed. Check if you spelling is correct.
If no error display, type C:\test>java greeting
You should not type file extension to run java class. Press enter to start java application.
The message "Hello World!" displays in command prompt.

Congratulation! You configure your PC correctly and can start to develop more sophisticated Java Application.
The ASCII Art Java application prints flowers in wase composed from ASCII characters.
Ther is a source code:ASCIIart.java
//Java Art. Copyright by Sergey Skudaev 2007
public class ASCIIart
{
public ASCIIart()
{
}
public void print()
{
System.out.println(" ");
System.out.println(" ");
System.out.println(" ");
System.out.println(" ");
System.out.println(" @ @ @ ");
System.out.println(" @ @ @ @ ");
System.out.println(" @ @ @ ");
System.out.println(" \\|/ ");
System.out.println(" | | | ");
System.out.println(" | | | ");
System.out.println(" | | | ");
System.out.println(" | | | ");
System.out.println(" ( ) ");
System.out.println(" ^^^^^ ");
System.out.println(" ");
System.out.println(" ASCII Vase ");
System.out.println(" ");
System.out.println(" ");
}
public static void main(String[] args)
{
ASCIIart art = new ASCIIart();
art.print();
}
}

Application output.
Please rate the tutorial