Example:
Purpose:To define a new variable of a particular type and optionally supply an initial value |
Greeting1
g
void
101dalmatians
Hello, World
<greeting>



Example:
Purpose:To assign a new value to a previously defined variable. |

String greeting = "Hello, World!";
int n = greeting.length(); // sets n to 13
String river = "Mississippi"; // Sets bigRiver to "MISSISSIPPI": String bigRiver = river.toUpperCase();
System.out.length(); // This method call is an error

// Construct a new string ("Missouri"):
river.replace("issipp", "our")
public int length()
// return type: int
// no explicit parameter
public String replace(String target, String replacement)
// return type: String;
// two explicit parameters of type String
// In class PrintStream: public void println(String output)
public void println(String output)
public void println(int output)

Rectangle box = new Rectangle(5, 10, 20, 30);
new Rectangle()
// constructs a rectangle with its top-left corner
// at the origin (0, 0), width 0, and height 0
Example:
Purpose:To construct a new object, initialize it with the construction parameters, and return a reference to the constructed object |

Example:
Purpose:To import a class from a package for use in a program. |
01: import java.awt.Rectangle;
02:
03: public class MoveTester
04: {
05: public static void main(String[] args)
06: {
07: Rectangle box = new Rectangle(5, 10, 20, 30);
08:
09: // Move the rectangle
10: box.translate(15, 25);
11:
12: // Print information about the moved rectangle
13: System.out.println("After moving, the top-left corner is:");
14: System.out.println(box.getX());
15: System.out.println(box.getY());
16: }
17: }
After moving, the top-left corner is:
20
35
This page is found at
http://java.sun.com/j2se/1.5.0/docs/api/.
" Hello, Space ! "
Rectangle box = new Rectangle(5, 10, 20, 30);
Rectangle box2 = box;
box2.translate(15, 25);
