Upload
juniper-james
View
212
Download
0
Embed Size (px)
Citation preview
Getting Started
Our Java Programming Environment: DrJava
Home Page: http://drjava.org
DrJava requires Java 2, version 1.4 or later.
It is recommended to download and use Sun's JDK 1.5.0, currently in beta releases, (from http://java.sun.com)
Starting to Program in Java
/*NameAssignment NumberDateDescription in your own words of what the assignment does*/
/* & */ surround a >commented= area- this part of the program is NOT run, but is for some else to understand what you did
import java.awt.*;
LIBRARY / PACKAGE attachment ... this allows the use of commands found in within the >attached= packages- java.awt.* for standard Java commands
Your First Java Program // The "HelloWorld" class.
public class HelloWorld
{
public static void main (String[] args)
{ System.out.println("Hello World!");
} // main method
} // HelloWorld class
Comment line. Any line that starts with // is a comment line.
Defines the class name. The class name must agree with the file name, this class must be saved as HelloWorld.java. It must match exactly as Java is case sensitive
Defines the start of the class.
Defines the end of the class.
main -> is the method name, this is the name used for the method that starts the program.
public -> means that other classes can call this method.
static -> loads the method into memory and keeps it there.
void -> means the method does not return a value.
String [] args - allows for use of words / Strings
-{ } surrounds all parts of the main block- Instructs the program to print "Hello World!"
... all programming code in the main block
Printing TechniquesTo print a blank line, we can simply write:
To print a VERY LONG LINE, we write the following:
System.out.println(“This will print a Verrrrrrrrry long”
+ “on one line by joining”
+ “these strings into one line”);
System.out.println();
The process of joining strings is called (+ Sign)
Concatenation
If we don’t wish to jump to a new line after printing a string, we can use the method instead of Printlnprint
This will produce:
A double quote: ”
A backslash: \
If we Want to print a string that contains escape sequences such as double quotes, backslash, java ‘s solution is to use Immediately infront of the escape sequence.
System.out.print(“Hello”);System.out.print(“There!”);
System.out.println(“A double quote: \””);System.out.println(“A backslash: \\”);
This will produce:
HelloThere!
\
Assignment #1
P. 12 # 5, 6, 7
Due Friday 7th, 2008
Assignment # 1 Rubric