Java Student Project         

Hello World
Ability Level: Beginner  
Estimated Time: 40 minutes
Objectives:
  • To learn how to use the compiler and print to the screen.
Materials & Resources:
  • Java Software
  • Textbook
Overview:
Write a program that prints out "Hello World!"

Instructions:


1. Create a program to print out "Starting Java ..." and "Hello World!" on the next line. It should look like the output shown above.

2. Read in the hints section why the following code is used.

3. If you are using J++, follow the instructions for the compiler in the extras section below.

//program hello.java by your name

import java.io.*;

public class hello //hello is the fileName
{
   public static void main(String[] args)
   {
        System.out.println("Starting Java ...");
        System.out.println("Hello World!");
   }
}

Hints: Some important points to keep in mind in doing this project:

The file name and the project name need to be the same.

Writing a Java program

A. All Java statements must end with a semi-colon (;)

B. Programs may contain literal strings (a series of characters in double quotes)

C. Programs contain user-defined variables and methods

D. The statement System.out.println( "Hello") is an example of a call to a method of the out object which is contained in the static class System. This method accepts a string as an argument, in this case, "Hello" which is a string literal. The argument is passed to the method which displays it on the monitor

E. All programming statements in Java must be part of a class. A class name must conform to specific syntax rules.

1. The class name should be the same as the file name under which the program is saved

2. Class names are case sensitive, for style purposes should be capitalized, must start with a letter, and may contain only letters, digits, underscores or dollar signs. Letters in this case may include international characters

3. There are 48 keywords defined in Java 1.1 created by the Sun Corporation. Keywords may not be used as identifiers or class names

4. The contents of a class are contained within curly braces ( ie. { } )

5. A class may have an access modifier, such as Public, to describe when it may be accessed

6. A class may contain any number of variables and methods

F. Java programs may have comments which provide explanations of the program and its details to help programmers understand the code, and to make program modification and maintenance simpler.

1. There are three types of comments

a. Line comments begin a line in the program with two forward slashes, //. This causes the compiler to ignore the remaining characters on that line only

b. Block comments begin with /* and end with */. These comments may span more than one line, and the compiler ignores everything between them

c. Javadoc comments, unique to the Java language, which begin with /** and End with */. These comments are used by the javadoc utility to generate documentation.

Extras: If you are using Visual J++, follow these instructions:
  1. To open J++,
    • Click on programming folder
    • Click on Microsoft Visual J++
    • Microsoft Development Studio
  2. To begin a program,
    • Click on File, New, Project
    • Under location, type in the location of your network drive folder and directory
    • Highlight Java Project, and key in the project name [fileName]
    • Click on open, yes, ok
  3. To begin the java source file,
    • Click on File, New, File
    • Click the folder "Visual J++" and highlight the icon "Java file"
    • Click on open
    • Click on file, save as 
    • Type in the name of the source code [fileName] dot java, being sure you are in the correct folder and the name matches the project name (example: hello.java)
    • Click save
  4. Delete these files before beginning your project:
    • Highlight the Form1.java and press delete and yes
    • Highlight miscellaneous files and press delete and yes
  5. Double click the fileName.java and start typing in the blank editing box to the left
  6. If you are on a network, 
    • make sure the file name is high lighted 
    • click on "project" in the menu
    • click on [fileName] properties
    • click on compile and under "additional compiler options" and "output directory" type in C:\Debug.  
  7. Save by clicking on file and save all.
  8. Either press F5 or click on the play button to start the program