Chapter0 PDF
Chapter0 PDF
Computer Programs:
A computer program is a set of instructions that "tell" the computer to do a certain task, such as
play a game of Diablo II; compose, format, and print a letter; or predict the survival of cockroaches
over several generations. People who used the earliest computers had to know how to write their
own programs. There were no stores where they could buy ready-to-use software packages.
Today, most people who use computers are not programmers. Instead, they use application
software such as a word processor, a spreadsheet, an Internet browsers, games, and graphics
programs. You can become a very sophisticated computer user and know nothing about writing
programs.
Yet even if you have no intention of becoming a software developer or writing complex software
applications, you can still learn to program and enjoy solving your own problems in your own way.
Java-Jive
Chapter 0
kweiser 04
Page 0
There are several reasons to learn the foundations of computer science and how to program:
Secure Java permits the creation of programs that are virus-free and tamper-free.
Getting Started:
The software we will use to write Java programs is called JJ2.
1. Open JJ2, select Demo User and then select Open Selected JJ Project from Server.
2. Select: File New. The white window that opens is called the edit window.
3. Type HELLO into the edit window. Press the triangle button at the top right of the edit
window. This button compiles (translates Java code into a language the computer can
understand Java byte code see page 7) and runs the program. However, if the Java
code is incorrect, it cannot be translated. Instead, the compiler will report an error
message.
Questions:
1. Select Help About in JJ2 at the top right of the screen. Who is the third from the last
person listed who assisted in the development of this software?
2. What error message does the Java compiler report from #3 ("Getting Started") above?
Java-Jive
Chapter 0
kweiser 04
Page 1
System.out is an object that prints characters on the console window (black window
on the screen).
The characters enclosed in double quotation marks and are called a string. The string is
printed in the console window.
Press the triangle button to compile this Java code. If it doesnt compile but shows another
error message, fix the error and compile again. Eventually, when all errors are corrected, the
console window will show the run of your Java code.
> compiling code snippet ... ... Compilation successful.
> running code snippet
BEGIN: snippet
Hello
END: snippet
Lab # 00:
1.
Read over the Java code below. What do you guess it will do when you run it?
Discuss this with your desk partner or someone nearby.
System.out.print("A" + "B");
System.out.println("C" + "D");
System.out.println();
System.out.println("E");
2.
Java-Jive
Chapter 0
kweiser 04
Page 2
3.
Compile and run this program. Show the actual output below:
> compiling code snippet ... ... Compilation successful.
> running code snippet
BEGIN: snippet
_______________________________________________
_______________________________________________
_______________________________________________
_______________________________________________
END: snippet
Lab # 01:
This is the Java code for Lab # 01:
/*
@Author:
Date:
Teacher:
Course:
Period:
Lab #:
Kathy Weiser
11/3/04
Weiser
Computer Science
4
01
*****************
*
*
*
*
*
*
*
*
*
*
*****************
Do the following:
1.
Type the Java code above, modifying the documentation (the information between /* and
*/) to have your name, period, and the correct date.
2.
3.
Java-Jive
Chapter 0
kweiser 04
Page 3
4. Copy the run into documentation added below your program. Your program should now look
like this:
/*
@Author:
Date:
Teacher:
Course:
Period:
Lab #:
Kathy Weiser
11/3/04
Weiser
Computer Science
4
01
RUN
*****************
*
*
*
*
*
*
*
*
*
*
*****************
*/
Lab # 02:
1.
Write a program that prints your first and last name on the first line, your address on the
second line, skips the third line, and prints your phone number on the fourth line.
2.
After compiling and debugging (correcting the errors) the program, run it. Copy the run
into documentation below the program statements. (See lab # 01).
3.
Java-Jive
Chapter 0
kweiser 04
Page 4
4.
Berj Avenasyan
11/4/04
Weiser
Computer Science
4
02
This program prints
address, and phone
*/
and documentation at the bottom with a copy of your run
/*
RUN
Berj Avenasyan
12345 Something St.
(818) 558-4700
*/
so does this:
System.out.println("one" + "two");
System.out.println("three");
System.out.println();
System.out.print("four");
so does this:
System.out.println("onetwo");
System.out.println("three");
System.out.println();
System.out.print("four");
Java provides a facility for displaying special characters in a string. These special characters
are indicated by placing a backslash (\) in the string. For example, since double quotation
marks are used to indicate the start and end of a string, there is no obvious way to include
quotation marks within a string.
Java-Jive
Chapter 0
kweiser 04
Page 5
Effect
Go to next line
Double-quotation mark
Single-quotation mark
Single backslash
Tab (move over eight spaces)
Lab # 03:
1.
Write a program using escape sequences that produces the following run output:
*
|\
| \
------|--\-\
/
~~~~~~~\
/~~~~~~~
------~~~~~~~~~~~~~~~~~~~~~~~~
the BHS sailboat
2.
After compiling and debugging your program, run it. Copy the run into documentation
below the program. Make sure you have added documentation at the top of your program
giving me your information and the program description.
3.
4.
Print out a listing of the program that includes documentation at the top and the run at the
bottom. Turn in the program.
Java-Jive
Chapter 0
kweiser 04
Page 6
Lab # 04:
/*
@Author:
Date:
Teacher: Weiser
Course:
Period:
Lab #: 04
Lab Description: Write a program that draws a house using
characters inside quotation marks. The two output statements
in Java for console applications are:
System.out.print("stuff goes here");
System.out.println("stuff goes here");
-- and --
http://javaboutique.internet.com/AdvNewsScroll2/
http://javaboutique.internet.com/WebCalculator/
http://javaboutique.internet.com/PingPong/
Java-Jive
Chapter 0
kweiser 04
Page 7
Java Vocabulary:
1.
program
2.
Java
3.
4.
secure
5.
robust
6.
portable
7.
JJ2
8.
edit window
9.
compiles
10.
error message
11.
statement
12.
console window
13.
method
14.
string
15.
semicolon
16.
code
17.
snippet
18.
documentation
19.
debugging
20.
escape character
21.
compiler
22.
23.
24.
interpreter
Java-Jive
Chapter 0
kweiser 04
Page 8