Download Basic Help Document

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Basic Help Document
The Java Platform, Standard Edition 6.0 (Java SE 6):
We recommend you use the Java Platform, Standard Edition 6.0 (Java SE) to
compile and test your programs.
The Java Platform, Standard Edition 6.0 is available as follows:


Java SE 6 is free (for Windows, Linux, Suns)
from http://java.sun.com/javase/downloads/
For J2SE 5.0 on the Mac, go to http://developer.apple.com/java/
and download: J2SE 5.0 Release 4
The Java SE Development Kit (JDK) includes the Java Runtime Environment (JRE) and
command-line development tools that are useful for developing applets and applications.
Platform Installation Notes
http://java.sun.com/javase/6/webnotes/install/index.html
Setting the PATH variable when installing Java on Windows XP:
http://java.sun.com/javase/6/webnotes/install/jdk/install-windows.html
Documentation
All the standard Java SE API classes, such as String and Vector, have complete
online documentation.
Information on the CURRENT Java SE 6 version (as well as previous versions):


Java Documentation
Java API Specifications
URL for the online Sun Java tutorial:
http://java.sun.com/docs/books/tutorial/
Difference between Java application programs and Applets
An applet is a Java bytecode program that runs on a Web browser. Most up-to-date Web
browsers include a Java interpreter. A Web page on a host computer on the Internet can
contain instructions that send Java bytecodes to a client computer (like yours) that has asked
to view the page. The Web browser on the client runs the Java applet with its built-in
interpreter.
Applets are used for user interaction, graphics, and animation. We will concentrate on Java
programs that get input from the keyboard and write output to the DOS window of the
monitor. These are called Java application programs.
General Steps to Creating, Compiling and Running Java Programs
1. Start a MS-DOS command window.
2. Now, change to the directory of your choice from within the command window.
For example:
>cd \Temp
3. Create some Java source code with Notepad from within the command window.
For example, suppose we want a class named "Test", then we would start Notepad
with the name of the Java file:
>notepad Test.java
4. The source code, Test.java, might look like this:
public class Test
{
public static void main(String args[])
{
System.out.println("We work!");
}
}
Don't forget to save the file!
5. Double check the name of the Java program file you just saved
by listing out the files in the current directory:
>dir
/p
If the name of the Java program file listed does not end in .java, you need to rename
it so that it does For instance, if the file appears as A.java.txt, you should rename it
as A.java
6. Assuming we saved the Java source code (as in step 4) from within Notepad, we can
now go back to the command prompt and compile it. This is done with the javac
compiler command:
>javac Test.java
7. If it doesn't compile, fix the errors with Notepad. Otherwise if it compiles fine
(we know this by the fact we had no error messages and the "Test.class" file exists),
we can run the application (found in Test.class) using the java command followed
by the name of the class (without the extension):
>java Test
8. At this point you should see:
We work!
A Possible Java J2SE Problem -- No Path to Java J2SE
If the system can't find javac, java or appletviewer, you should check your path by typing
"PATH" at the command prompt:
>PATH
It should return something like this:
PATH=C:\WINNT\system32;C:\WINNT;C:\JDK1.3.1\BIN
If there is no JDK or J2SE in the path, you won't have direct access to the Java commands.
Setting the PATH variable when installing Java on Windows XP:
http://java.sun.com/javase/6/webnotes/install/jdk/install-windows.html
Opening (or Browsing for) an Existing File in Notepad
Whenever you are trying to open (or browsing for) a file that already exists in your
directories,
be sure that you highlight the All Files option
on the Files of type: form at the bottom of the Open/Browse window
This should permit you to see all the .java, .html, and .txt files in your directory
Don't limit your search to just Text Documents (*.txt) or HTML Files,
or you'll never find files with names ending in .java or .class
Common Error Messages from the Compiler
Few error messages that you might encounter early in the process and some solutions:
Undefined variable
You've referenced a variable that is not defined within the scope that it is used. Check
whether it is a typo or simply defined elsewhere.
Wrong number of arguments in constructor
In trying to create a new object, you've misused the constructor.
Can't make a static reference to nonstatic variable whatever in class yourclass
You probably used a class name where you meant to use an object name.
Variable whatever in class yourclass1 not accessible from class yourclass2
Don't try to directly reference private instance variables.
Undefined variable, class, or package name
Check spelling and capitalization on the name being used. Probably a typo.
Common Run-Time Errors
Can't find class yourclass
You've given java the wrong name for the class file; you're in the wrong directory, or
ou haven't imported the classes needed by yourclass to run.