CS 1063 Week
1: Introduction to Computer Programming
Objectives
- Administrative
- Use the web to obtain class notes, assignments, projects, and
calendar dates
- Type in a simple program in JBuilder and execute it
Reading Week 1
Administrative
- Syllabus
- Fill out survey
- Borland JBuilder software
- Course mechanics
- Labs (12)
- Quizzes (10)
- Projects (3)
- Tests (2 and a final)
- Course web page
Activity 1: Compiling a Simple Program
Complete instructions for JBuilder can be found at
http://www.cs.utsa.edu/~javalab/lab/gettingStartedJbuilder.html
Part 1:
Setup - Find JBuilder on your computer and execute it.
- Project/Package Name: helloworldpkg
- Add a new Main Class with name: HelloWorld.
Remember to check the box Generate main method.
- Save all
- You will need to type in the highlighted line below replacing the
one that is there.
- Java is case-sensitive. You must enter upper and
lowercase letters exactly as they appear in the program listing.
- Right click on the HelloWorld
tab and chose run using defaults. you should
see
Hello, World! in the output window.
public class HelloWorld {
public HelloWorld() {
}
public static void main(String[] args) {
System.out.println("Hello
World");
}
}
Part 2:
Construction
- Every Java application contains a class with a main method. When the
application starts, the
instructions in the main method are executed.
public static
void main(String[] args) {
.
. .
}
- Use comments to help human readers understand your program.
Add the following line to your program. run
public class
HelloWorld {
public HelloWorld() {
}
public static void main(String[] args) {
// display a greeting in the console window
System.out.println("Hello World");
}
}
- Any text enclosed between // and the end of the line is
completely ignored by the compiler.
- Comments are used to explain the program to other programmers
or to yourself.
- The compiler also ignores any text between a /* and */ If
you have a comment that is longer than one line then the /* . . . */
comment is simpler. For example
/* This is a simple
Java program
It will print a greeting to the console
*/
- Add the highlighted lines to your HelloWorld file and run
again. Was there any change?
- Instructions or statements in the body of the main method (statements
between {} ) are executed one at a time. Each statement ends in a
semicolon (;)
- Notice that our main
has only one statement - the System.out.println("Hello
World");
- The comment is ignored by the compiler
- Whenever you call a method in Java, you need to specify three
things
- The object that you want to use - System.out
- The name of the method you want to use - println
- A pair of parentheses, containing any other information the
method needs - ("Hello World")
Part 3: More on the System.out.println statement
and strings. Add the highlighted lines to your HelloWorld file and run.
- String - a sequence of characters enclosed in quotation marks.
- The println method
prints a string or a number and then starts a new line. The
following code prints out the two lines
Hello
World!
System.out.println("Hello");
System.out.println("World!");
Last
Modified: January 3,
2007 at 10:28am