Download a development environment program called BlueJ from http://www.bluej.org/ Make sure JDK is installed Follow the installation instruction Download the BlueJ Tutorial Other instructions (prepared by Noriko) can be found here .
Download TextPad The TextPad java FAQ More Info on setting up TextPad
Source code: HelloWorld.java
Type in and save the source code in a file named HelloWorld.java.
Compile: javac HelloWorld.java
Compile the source code, assuming that the PATH is set correctely. If the compilation is successful, a file named HelloWorld.class will be generated. This is the Java byte-code file.
Run: java HelloWorld
Execute the app by invoking the Java byte-code interpreter (resides in c:\jdk1.3\bin\).
Notes:
- the argument of java is the class name not the file name (i.e. no extension).
- the output will be visible directly under the line at which you type this.
- If you need to capture the output for printing purposes, add > filename.out to the end of this command line, (where filename is a name that you choose for the output file).
Example:
java HelloWorld > hello.out
The output will now not appear on the screen, but will be placed into a file named hello.out in your working folder.
Type in the source code:
HelloWorldApplet.java
Compile the source code:
javac HelloWorldApplet.java
Type in and save the following HTML source in a file named HelloDemo.html. One way to view th eapplet is to use a Java-enable browser such as IE or Netscape Another way to view th eapplet is to use the applet viewer in JDK
appletviewer HelloDemo.htmlBasic Applet Structure
- In general an applet must extends the Applet class.
- It does not need a main() method, but should at least implement the paint() method (or other methods that will be discussed later on).
- It is embeded as follows:
<applet code=class_filename width=pixels height = pixels> < /applet>- Each applet is assigned a rectangular region on the web page. The dimensions are set in the applet tag in the HTML file.
- The paint() method is invoked when the applet is initially loaded in a browser
- The origin (0,0) is loacted at the upper left corner of the rectangular region
public static void main(String[] arg)The main method serves as the entry point for the Java Virtual Machine (JVM)(i.e, JVM is an abstraction of the CPU of a computer). Recall that the machine code of the JVM is the Java byte-code, to invoke the Java app. See Java Execution Model When the app starts, no instance of the class has been created, so only a static method can be invoked. Thus main() must be static.
{
........
}
Datatype | Meaning | Size in Bytes | Min Value | Max Value | Sig. Digits |
---|---|---|---|---|---|
byte | Integer | 1 | -128 | 127 | |
short | Integer | 2 | -32,768 | 32,767 | |
int | Integer | 4 | -2 billion | 2 billion | |
long | Integer | 8 | -9.2x1018 | 9.2x1018 | |
float | Floating Point | 4 | -3.2x1038 | 3.2x1038 | 7 |
double | Floating Point | 8 | -1.8x10308 | 1.8x10308 | 15 |
char | Character | 2 | Any Unicode character | ||
boolean | boolean | 1 | false | true |
\b | backspace |
\n | new line (line feed) |
\r | carriage return |
\t | tab |
\" | double quote |
\' | single quote |
\\ | backslash |
short timeInSeconds = 245;
char a = 'K', b = '$';
boolean flag = true;
double maxVal = 35.875;