Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
michael-
thomas.com
Email Michael Thomas: <myfirstname>@michael-
thomas.com
©JCrazy LLC; ©Michael Thomas
If you have trouble with any of the steps below see the table below called "Help Notes".
Steps
(Tested with Java SE 8u111)
Step: Using a Text Editor
• Windows NotePad
◦ Windows comes with NotePad. You can use it to complete this section.
• NotePad++ - https://notepad-plus-plus.org/download - free & GPL license, written in C++
◦ I really like this editor.
◦ Download and install the .exe.
Note: There is a .zip file which is nice if you don't have rights to install a program.
• My Notes on other Text Editors
• Create a new directory to place the files you will work with.
You can do this using Windows Explorer or using DOS (click here for Help with DOS)
• You can use the Windows program "Notepad" to create these files.
• MyFirst_java_test.bat - create and run this batch file (click on it in Win Explorer).
Reason: Test your JDK install: java.exe, javac.exe, javaw.exe, appletviewer.exe
rem Optional:
rem * This is not needed if you set the JAVA_HOME and PATH system environment variables as in the tutorial.
rem call MyFirst_jdk_setpath.bat
echo off
echo.
echo **** Test for: java.exe (Run Java Applications)****
echo.
java.exe -fullversion
echo.
echo **** Test for: javac.exe (Compliler) ****
echo.
javac.exe -help
echo.
echo **** Test for: javaw.exe (Run Java Applications)****
echo.
javaw.exe -help
echo.
echo **** Test for: appletviewer.exe (Compliler) ****
echo.
appletviewer -help
pause
• Do not proceed unless you can run the previous batch file without errors.
Example of an Error:
'javac.exe' is not recognized as an internal or external command,
operable program or batch file.
• Create, compile and Run your first Java Application. Java Applications are designed to on a local machine which has a
JVM (Java Virtual Machine) loaded. By the way, Java Servlets work the same way.
◦ Create: MyFirstApplication.java - the source code for the java application program.
/*
File.......: MyHello_Application.java
Description: Basic Application example.
Programmer.: Michael Thomas, 1/17/99
Compile....: javac MyHello_Application.java
Run........: java MyHello_Application
*/
public class MyFirstApplication {
public static void main( String [] args ) {
System.out.println("Hello World from an Application.");
}
}
◦ Create: MyFirstApplication_compile.bat - This will compile the .java source code and create a .class file.
rem call MyFirst_jdk_setpath.bat
javac MyFirstApplication.java -classpath .
pause
*/
import java.applet.Applet;
import java.awt.Graphics;
◦ Create: MyFirstApplet_compile.bat - This will compile the .java source code and create a .class file.
rem call MyFirst_jdk_setpath.bat
javac MyFirstApplet.java
pause
◦ For now we will create a batch file to use Java's appletviewer.exe to display the applet.
We are doing this because of additional browser security issues when running applets.
◦ Create: MyFirstApplet_view.bat - this will run a Java Applet using JDK's appletviewer.exe
rem call MyFirst_jdk_setpath.bat
appletviewer MyFirstApplet.html
pause
Topic Notes
Environment DOS Environments:
Variables:
View the DOS Environment Variables.
• Path
• Classpath • c:\> set | more - This DOS command will show you all of the DOS environment variables and
page break if neccessary.
• set CLASSPATH=. - This sets the class path to the current directory. Make sure you don't
add extra spaces to this command!
• set CLASSPATH= - This will remove the CLASSPATH variable.
• path - shows the director order in which DOS will look for DOS Commands. I like to have the
JDK be the first in the list if your OS allows it. (ex: c:\jdk1.3\bin; c:\winnt; etc...)
• CLASSPATH - a variable that tells java which directories to look for classes. You should have
".;" be the first in the list. If you need to customize the CLASSPATH for a program use the -
classpath compile option when compiling (ex: javac HelloWorld.java -classpath . ).
Win XP
Win 95/98
• Steps
◦ Press Start, Run
◦ type: msconfig
◦ Then hit the "Enter" key.
◦ Click on the Autoexec.bat tab
◦ Click on "set Path" line. Then click "Edit"
◦ Right now you are viewing the Autoexec.bat file. Be careful while you are in this file.
◦ See if you have a command that begins with
"SET PATH =". If you do, add the correct path as the first entry after the "SET PATH
=". Choose from the following:
◾ For JDK 1.2 add: c:\jdk1.2\bin;
◾ For SDK 1.3 add: c:\jdk1.3\bin;
Note: If you don't have a "SET PATH" statement, add the following:
◾ set path = c:\jdk1.3\bin;
◦ Next, you must reboot.
◦ After you reboot go to a DOS prompt and type:
path
◦ If c:\jdk1.3\bin appears first your are completed. If c:\windows and/or
c:\windows\command is first, you maybe calling java.exe from those directories.
Win ME
• Steps
◦ Press Start, Run
◦ type: msconfig
◦ Then hit the "Enter" key.
◦ Click on the Environment tab
◦ Click on "Path" line. Then click "Edit"
◦ Be careful and add the correct path. Note - add the path as the first entry.
For JDK 1.2 add: c:\jdk1.2\bin;
For SDK 1.3 add: c:\jdk1.3\bin;
Ex: c:\jdk1.3\bin; c:\windows; c:\windows\command;
◦ Click on "Apply"
◦ Now click on the "General" tab. Make sure that the Normal option is selected. If not you
may get a message about "selective startup" after you reboot.
◦ Click on "OK"
◦ Next, you must reboot.
◦ After you reboot go to a DOS prompt and type:
path
◦ If c:\jdk1.3\bin appears first your are completed. If c:\windows and/or
c:\windows\command is first, you maybe calling java.exe from those directories.
DOS Commands
Common DOS Commands
• dir /x - shows 8char short file names. Some versions of DOS require short filenames when you
CD or give pathnames. This command is handy in those cases. May not work for all OS's.
• Error opening registry key 'Software\JavaSoft\Java Runtime Environment' when calling: java
<program name>
◦ Quick fix - give the full path for java: ex: c:\jdk1.3\bin\java
◦ Reinstall the Java Runtime Environment (JRE)